Exercise: Functions And Subroutines

Questions for: Functions And Subroutines

What will be the output of the C#.NET code snippet given below?
namespace ExamAdept
{
    class SampleProgram
    {
        static void Main(string[ ] args)
        {
            int i = 5;
            int j;
            fun1(ref i);
            fun2(out j);
            Console.WriteLine(i + ", " + j);
        }
        static void funl(ref int x)
        {
            x = x * x;
        }
        static void fun2(out int x)
        {
            x = 6; 
            x = x * x; 
        }
    }
}
A:
5, 6
B:
5, 36
C:
25, 36
D:
25, 0
Answer: C
No answer description is available. Let's discuss.
Which of the following statements are correct about the C#.NET program given below?
namespace ExamAdept
{ 
    class SampleProgram
    { 
        static void Main(string[ ] args)
        { 
            int a = 5;
            int s = 0, c = 0; 
            s, c = fun(a); 
            Console.WriteLine(s +" " + c) ;
        }
        static int fun(int x)
        {
            int ss, cc;
            ss = x * x; cc = x * x * x; 
            return ss, cc;
        } 
    } 
}
  1. An error will be reported in the statement s, c = fun(a); since multiple values returned from a function cannot be collected in this manner.
  2. It will output 25 125.
  3. It will output 25 0.
  4. It will output 0 125.
  5. An error will be reported in the statement return ss, cc; since a function cannot return multiple values.
A:
1, 3
B:
2, 4
C:
4, 5
D:
1, 5
Answer: D
No answer description is available. Let's discuss.
A function can be used in an expression, whereas a subroutine cannot be.
A:
True
B:
False
C:
D:
Answer: A
No answer description is available. Let's discuss.
Which of the following statements are correct about subroutines used in C#.NET?
  1. If we do not return a value from a subroutine then a value -1 gets returned.
  2. Subroutine definitions cannot be nested.
  3. Subroutine can be called recursively.
  4. To return the control from middle of a subroutine exit subroutine should be used.
  5. Subroutine calls can be nested.
A:
1, 2, 3
B:
2, 3, 5
C:
3, 5
D:
3, 4
Answer: B
No answer description is available. Let's discuss.
If a function fun() is to sometimes receive an int and sometimes a double then which of the following is the correct way of defining this function?
A:
static void fun(object i)
{ ... }
B:
static void fun(int i)
{ ... }
C:
static void fun(double i, int j)
{ ... }
D:
static void fun(int i, double j)
{ ... }
Answer: A
No answer description is available. Let's discuss.
Ad Slot (Above Pagination)
Quiz