Following are the multiple choice questions from C++. Please scroll down to check the answers.
The void specifier is used if a function does not have return type.
You must specify void in parameters if a function does not have any arguments.
Type specifier is optional when declaring a function
Study the following piece of code and choose the best answer
int x=5, y=3, z;
a. The function addition is called by passing the values
b. The function addition is called by passing reference
In case of arguments passed by values when calling a function such as z=addidion(x,y),
a. Any modifications to the variables x & y from inside the function will not have any effect outside the function.
b. The variables x and y will be updated when any modification is done in the function
c. The variables x and y are passed to the function addition
d. None of above are valid.
If the type specifier of parameters of a function is followed by an ampersand (&, that function call is
a. pass by value
b. pass by reference
In case of pass by reference
a. The values of those variables are passed to the function so that it can manipulate them
b. The location of variable in memory is passed to the function so that it can use the same memory area for its processing
c. The function declaration should contain ampersand (& in its type declaration
d. All of above
Overloaded functions are
a. Very long functions that can hardly run
b. One function containing another one or more functions inside it.
c. Two or more functions with the same name but different number of parameters or type.
d. None of above
Functions can be declared with default values in parameters. We use default keyword to specify the value of such parameters.
Examine the following program and determine the output
using namespace std;
int operate (int a, int b)
return (a * b);
float operate (float a, float b)
int x=5, y=2;
float n=5.0, m=2.0;
cout << operate(x,y) <<"\t";
cout << operate (n,m);
a. 10.0 5.0
b. 5.0 2.5
c. 10.0 5
d. 10 2.5
1. a. True
2. b. False [ parameters can be empty without void too!]
3. b. False
4. a. The function addition is called by passing the values
5. a. Any modifications to the variables x & y from inside the function will not have any effect outside the function
6. b. pass by reference
7. b. The location of variable in memory is passed to the function so that it can use the same memory area for its processing
8. d. None of above
9. b. False
10. d. 10 2.5
|< Prev||Next >|