General
Basicss
1. The constants are also called as
A. Const
B. Preprocessor
C. Literals
D. None of these
Answer: C
Explanation:
2. What are the parts of the literal constants?
A. integer numerals
B. floating-point numerals
C. strings and boolean values
D. all of the above
Answer: D
Explanation: Because these are the types used to declare variables and so these can be declared
as constants.
3. Which one of the following is different from the other?
A. array type
B. character type
C. boolean type
D. integer type
Answer: A
Explanation: Array type is not the basic type and it is constructed using the basic type.
4. Which data type is used to represent the absence of parameters?
A. Int
B. Short
C. Void
D. float
Answer: C
Explanation: Because void specifies an empty set of values/parameters.
5. How the constants are declared?
A. const keyword
B. #define preprocessor
C. both a and b
D. None of these
Answer: C
Explanation: The const will declare with a specific type values and #define is used to declare
user definied constants.
6. Which type is best suited to represent the logical values?
A. Integer
B. Boolean
C. Character
D. float
Answer: B
Explanation: Logical values can be either true or false, so the boolean type is suited for it.
7. Identify the user-defined types from the following?
A. Enumeration
B. Classes
C. both enumeration and classes
D. int
Answer: C
Explanation: They must be defined by the users before use, unlike the other types which are
readily available.
8. Pick the odd one out.
A. integer, character, boolean, floating
B. enumeration, classes
C. integer, enum, void
D. arrays, pointer, classes
Answer: C
Explanation: integer, character, boolean & floating consists of all fundamental types,
enumeration & classes consists of user-defined types and arrays, pointer & classes consists of
derived types but integer, enum & void is a mixture.
9. How many characters are specified in the ASCII scheme?
A. 64
B. 128
C. 256
D. 24
Answer: B
Explanation: There are 128 characters defined in the C++ ASCII list.
10. Given the variables p, q are of char type and r, s, t are of int type. Select the right
statement?
1. t = (r * s) / (r + s);
2. t = (p * q) / (r + s);
A. 1 is true but 2 is false
B. 1 is false and 2 is true
C. both 1 and 2 are true
D. both 1 and 2 are false
Answer: C
Explanation: Every character constant has an integer value. Also char belongs to the integral type
hence arithmetic and logical operations can be performed on them.
11. Which of the following belongs to the set of character types?
A. Char
B. wchar_t
C. Enum
D. both wchar_t and char
Answer: D
Explanation: wchar_t and char are used to represent wide character and character respectively.
The wchar_t is used to store large number of characters that we have in Unicode while char used
to represent only 128 characters.
12. How do we represent a wide character of the form wchar_t?
A. L’a’
B. l’a’
C. L[a]
D. La
Answer: A
Explanation: A wide character is always indicated by immediately preceding the character literal
by an L.
Flow control
Function
1. Which of the following statements are true if we have int f(float) ?
A. f is a function taking an argument of type int and returning a floating point
number
B. f is a function taking an argument of type float and returning an integer
C. f is a function of type float
D. f is a function of type int
Answer: B
Explanation: The argument that is passed to a function f is of float type and the function finally
returns a value that is of integer type.
Array, pointer and Structure
2. What are mandatory parts in the function declaration?
A. return type, function name
B. return type, function name, parameters
C. parameters, function name
D. parameters, variables
Answer: A
Explanation: In a function, return type and function name are mandatory all else are just
used as a choice.
3. Which is more effective while calling the functions?
A. call by value
B. call by reference
C. call by pointer
D. call by object
Answer: B
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.
4. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
void car{
cout << "BWD";
}
int main( ) {
car();
return 0;
}
A. BWD
B. BWD BWD
C. compile time error
D. runtime error
Answer: C
Explanation: We have to use the semicolon to declare the function in line 3. This is called a
function declaration and a function declaration ends with a semicolon.
5. 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;
}
A. 10
B. 20
C. Compile time error
D. 30
Answer: A
Explanation: In this program, we called by value so the value will not be changed, So the output
is 10.
6. How many minimum number of functions should be present in a C++ program for its
execution?
A. 0 C. 2
B. 1 D. 3
Answer: B
Explanation: The execution of a C++ program starts from main function hence we require at
least 1 function to be present in a C++ program to execute and i.e. the main function.
7. Which of the following is the default return value of functions in C++?
A. Int
B. Char
C. Float
D. void
Answer: A
Explanation: C++ uses int as the default return values for functions. It also restricts that the
return type of the main function must be int.
8. What is an inline function?
A. A function that is expanded at each call during execution
B. A function that is called during compile time
C. A function that is not checked for syntax errors
D. A function that is not checked for semantic analysis
Answer: A
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.
9. An inline function is expanded during ______________
A. compile-time
B. run-time
C. never expanded
D. end of the program
Answer: A
Explanation: An inline function is expanded during the compile-time of a program. A
function is not inline if it has static variables, loops or the function is having any
recursive calls.
10. When we define the default values for a function?
A. When a function is defined
B. When a function is declared
C. When the scope of the function is over
D. When a function is called
Answer: B
Explanation: Default values for a function is defined when the function is declared inside
a program.
11. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int fun(int x = 0, int y = 0, int z){
return (x + y + z);
}
int main() {
cout << fun(10);
return 0;
}
A. 10
B. 0
C. Error
D. Segmentation fault
Answer: C
Explanation: Default arguments should always be declared at the rightmost side of the
parameter list but the above function has a normal variable at the rightmost side which is a
syntax error, therefore the function gives an error.
12. 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. 0
C. 10
D. 5
Answer: D
Explanation: 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.
File