C# Programming - Functions and Subroutines

Exercise : Functions and Subroutines - General Questions
  • Functions and Subroutines - General Questions
6.
Which of the following will be the correct output for the C#.NET program given below?
namespace IndiabixConsoleApplication
{ 
    class SampleProgram
    { 
        static void Main(string[] args)
        {
            int a = 5; 
            int s = 0, c = 0;
            Proc(a, ref s, ref c);
            Console.WriteLine(s + " " + c);
        }
        static void Proc(int x, ref int ss, ref int cc)
        {
            ss = x * x;
            cc = x * x * x;
        } 
    } 
}
0 0
25 25
125 125
25 125
None of the above
Answer: Option
Explanation:
No answer description is available. Let's discuss.

7.
What will be the output of the C#.NET code snippet given below?
namespace IndiabixConsoleApplication
{
    class SampleProgram
    {
        static void Main(string[ ] args)
        {
            int i = 10;
            double d = 34.340;
            fun(i);
            fun(d);
        }
        static void fun(double d)
        {
            Console.WriteLine(d + " ");
        }
    }
}
10.000000 34.340000
10 34
10 34.340
10 34.34
Answer: Option
Explanation:
No answer description is available. Let's discuss.

8.
Which of the following statements are correct?
  1. C# allows a function to have arguments with default values.
  2. C# allows a function to have variable number of arguments.
  3. Omitting the return value type in method definition results into an exception.
  4. Redefining a method parameter in the method's body causes an exception.
  5. params is used to specify the syntax for a function with variable number of arguments.
1, 3, 5
3, 4, 5
2, 5
4, 5
None of these
Answer: Option
Explanation:
No answer description is available. Let's discuss.

9.
If a procedure fun() is to receive an int, a Single & a double and it is to return a decimal then which of the following is the correct way of defining this procedure?
fun(int i, Single j, double k) decimal 
{ ... }
static decimal fun(int i, Single j, double k) 
{ ... }
fun(int i, Single j, double k) 
{
    ...
    return decimal; 
}
static decimal fun(int i, Single j, double k) decimal 
{ ... }
A procedure can never return a value.
Answer: Option
Explanation:
No answer description is available. Let's discuss.

10.
If a function fun() is to receive an int, a Single & a double and it is to return a decimal then which of the following is the correct way of defining this function?
decimal static fun(int i, Single j, double k)
{ ... }
decimal fun(int i, Single j, double k)
{ ... }
static decimal fun(int i, Single j, double k)
{ ... }
static decimal fun(int i, Single j, double k) decimal
{ ... }
static fun(int i, Single j, double k)
{ 
    ... 
    return decimal;
}
Answer: Option
Explanation:
No answer description is available. Let's discuss.