C# - Functions and Subroutines
C# - Functions and Subroutines
1. Which of the following statements are correct?
An argument passed to a ref parameter need not be initialized first.
Variables passed as out arguments need to be initialized prior to being passed.
Argument that uses params keyword must be the last argument of variable argument list of a method.
Pass by reference eliminates the overhead of copying large data items.
To use a ref parameter only the calling method must explicitly use the ref keyword.
An argument passed to a ref parameter need not be initialized first.
Variables passed as out arguments need to be initialized prior to being passed.
Argument that uses params keyword must be the last argument of variable argument list of a method.
Pass by reference eliminates the overhead of copying large data items.
To use a ref parameter only the calling method must explicitly use the ref keyword.
- 1, 2
- 2, 3
- 3, 4
- 4, 5
3. Which of the following statements are correct about functions and subroutines used in C#.NET?
A function cannot be called from a subroutine.
The ref keyword causes arguments to be passed by reference.
While using ref keyword any changes made to the parameter in the method will be reflected in that variable when control passes back to the calling method.
A subroutine cannot be called from a function.
Functions and subroutines can be called recursively.
A function cannot be called from a subroutine.
The ref keyword causes arguments to be passed by reference.
While using ref keyword any changes made to the parameter in the method will be reflected in that variable when control passes back to the calling method.
A subroutine cannot be called from a function.
Functions and subroutines can be called recursively.
- 1, 2, 4
- 2, 3, 5
- 3, 5
- 4, 5
4. Which of the following statements are correct?
C# allows a function to have arguments with default values.
C# allows a function to have variable number of arguments.
Omitting the return value type in method definition results into an exception.
Redefining a method parameter in the method's body causes an exception.
params is used to specify the syntax for a function with variable number of arguments.
C# allows a function to have arguments with default values.
C# allows a function to have variable number of arguments.
Omitting the return value type in method definition results into an exception.
Redefining a method parameter in the method's body causes an exception.
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
5. Which of the following statements are correct about functions used in C#.NET?
Function definitions cannot be nested.
Functions can be called recursively.
If we do not return a value from a function then a value -1 gets returned.
To return the control from middle of a function exit function should be used.
Function calls can be nested.
Function definitions cannot be nested.
Functions can be called recursively.
If we do not return a value from a function then a value -1 gets returned.
To return the control from middle of a function exit function should be used.
Function calls can be nested.
- 1, 2, 5
- 2, 3, 5
- 2, 3
- 4, 5
6. How many values is a function capable of returning?
- 1
- 0
- Depends upon how many params arguments does it use.
- Any number of values.
7. How many values is a subroutine capable of returning?
- Depends upon how many params arguments does it use.
- Any number of values.
- Depends upon how many ref arguments does it use.
- 0
8. Which of the following CANNOT occur multiple number of times in a program?
- namespace
- Entrypoint
- Class
- Function
9. 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?
- static void fun(object i) { ... }
- static void fun(int i) { ... }
- static void fun(double i, int j) { ... }
- static void fun(int i, double j) { ... }
10. Which of the following statements are correct about subroutines used in C#.NET?
If we do not return a value from a subroutine then a value -1 gets returned.
Subroutine definitions cannot be nested.
Subroutine can be called recursively.
To return the control from middle of a subroutine exit subroutine should be used.
Subroutine calls can be nested.
If we do not return a value from a subroutine then a value -1 gets returned.
Subroutine definitions cannot be nested.
Subroutine can be called recursively.
To return the control from middle of a subroutine exit subroutine should be used.
Subroutine calls can be nested.
- 1, 2, 3
- 2, 3, 5
- 3, 5
- 3, 4