Question: 11 -
What happens to a function defined inside a class without any complex operations (like looping, a large number of lines, etc)?
-
It becomes a virtual function of the class
-
It becomes an inline function of the class
-
It becomes a default calling function of the class
-
The program gives an error
Answer:
It becomes an inline function of the class
Solution:
Any function which is defined inside a class and has no complex operations like loops, a large number of lines then it is made inline.
Any function which is defined inside a class and has no complex operations like loops, a large number of lines then it is made inline.
Question: 12 -
How many minimum number of functions should be present in a C++ program for its execution?
-
1
-
0
-
3
-
2
Answer:
1
Solution:
The execution of a C++ program starts from main function hence we require atleast 1 function to be present in a C++ program to execute and i.e. the main function.
The execution of a C++ program starts from main function hence we require atleast 1 function to be present in a C++ program to execute and i.e. the main function.
Question: 13 -
What is the scope of the variable declared in the user defined function?
-
the main function
-
whole program
-
only inside the {} block
-
header section
Answer:
only inside the {} block
Solution:
The variable is valid only in the function block as in other.
The variable is valid only in the function block as in other.
Question: 14 -
Which of the following is the default return value of functions in C++?
-
int
-
void
-
char
-
float
Answer:
int
Solution:
C++ uses int as the default return values for functions. It also restricts that the return type of the main function must be int.
C++ uses int as the default return values for functions. It also restricts that the return type of the main function must be int.
Question: 15 -
What will be the output of the following C++ code?#include <iostream>
using namespace std;
void fun(int x, int y){
x = 20;
y = 10;
}
int main() {
int x = 10;
fun (x, x);
cout << x;
return 0;
}
-
Error
-
20
-
30
-
10
Answer:
10
Solution:
In this program, we called by value so the value will not be changed, So the output is 10
In this program, we called by value so the value will not be changed, So the output is 10