Google News
logo
CPP - Quiz(MCQ)
A)
r distinguishes between comments and inner data
B)
r distinguishes between comments and outer data
C)
distinguishes between comments and outer data
D)
distinguishes between comments and code

Correct Answer : Option (D) :   distinguishes between comments and code


Explanation : To distinguish between different parts of the program like comments, codes, etc.

A)
It will return value
B)
It will not return value to its caller
C)
It will return value to its caller
D)
May or may not depend on the declared return type of the function, the passed arguments are different than the function return type

Correct Answer : Option (B) :   It will not return value to its caller


Explanation : As void is not having any return value, it will not return the value to the caller.

A)
parameters, function name
B)
parameters, variables
C)
return type, function name
D)
return type, function name, parameters

Correct Answer : Option (C) :   return type, function name


Explanation : In a function, return type and function name are mandatory all else are just used as a choice.

A)
127
B)
102
C)
99
D)
90

Correct Answer : Option (A) :   127


Explanation : C99 allows to pass a maximum of 127 arguments in a function.

A)
call by reference
B)
call by pointer
C)
call by object
D)
call by value

Correct Answer : Option (A) :   call by reference


Explanation : In the call by reference, it will just passes the reference of the memory addresses of passed values rather than copying the value to new memories which reduces the overall time and memory use.

A)
whole program
B)
the main function
C)
header section
D)
only inside the {} block

Correct Answer : Option (D) :   only inside the {} block


Explanation : The variable is valid only in the function block as in other.

A)
It becomes a virtual function of the class
B)
It becomes an inline function of the class
C)
It becomes a default calling function of the class
D)
The program gives an error

Correct Answer : Option (B) :   It becomes an inline function of the class


Explanation : 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.

A)
A function that is called during compile time
B)
A function that is not checked for semantic analysis
C)
A function that is expanded at each call during execution
D)
A function that is not checked for syntax errors

Correct Answer : Option (C) :   A function that is expanded at each call during execution


Explanation : Inline function is those which are expanded at each call during the execution of the program to reduce the cost of jumping during execution.

A)
Middle of the parameter list
B)
Anywhere inside the parameter list
C)
To the rightmost side of the parameter list
D)
To the leftmost side of the parameter list

Correct Answer : Option (C) :   To the rightmost side of the parameter list


Explanation : Default parameters are defined to the rightmost side of parameter list in a function to differentiate between the normal and default parameters for example if a function is defined as fun(int x = 5, int y) then if we call fun(10) then 10 should be given to x or y because one can apply both logics like x = 10 already defined and 10 passed is for y but if compiler reads it from left to right it will think it is for x and no parameter is given for y, therefore, the compiler will give error.

10 .
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
 
int fun(int=0, int = 0);
 
int main()
{
  cout << fun(5);
  return 0;
}
int fun(int x, int y) { return (x+y); }
A)
5
B)
10
C)
-5
D)
-10

Correct Answer : Option (A) :   5


Explaination : C++ allows to define such prototype of the function in which you are not required to give variable names only the default values. While in function definition you can provide the variable names corresponding to each parameter.