c++ mcq
c++ mcq
9. s
10. s
11. s
12. s
13.
Question 1:
Find out the error in following block of code.
If (x = 100)
Cout << “x is 100”;
a. 100 should be enclosed in quotations
b. There is no semicolon at the end of first line
c. Equals to operator mistake
d. Variable x should not be inside quotation
Question 2:
Looping in a program means
a. Jumping to the specified branch of program
b. Repeat the specified lines of code
c. Both of above
d. None of above
Question 3:
The difference between while structure and do structure for looping is
a. In while statement the condition is tested at the end of first iteration
b. In do structure the condition is tested at the beginning of first iteration
c. The do structure decides whether to start the loop code or not whereas while statement decides whether to
repeat the code or not
d. In while structure condition is tested before executing statements inside loop whereas in do structure condition
is tested before repeating the statements inside loop
Question 4:
Which of the following is not a looping statement in C?
a. while
b. until
c. do
d. for
Question 5:
Which of the following is not a jump statement in C++?
a. break
b. goto
c. exit
d. switch
Question 6:
Which of the following is selection statement in C++?
a. break
b. goto
c. exit
d. switch
Question 7:
The continue statement
a. resumes the program if it is hanged
b. resumes the program if it was break was applied
c. skips the rest of the loop in current iteration
d. all of above
Question 8:
Consider the following two pieces of codes and choose the best answer
CODE 1:
switch (x) {
case 1:
cout <<”x is 1”;
break;
case 2:
cout <<”x is 2”;
break;
default:
cout <<”value of x unknown”;
}
CODE 2
If (x==1){
Cout <<”x is 1”;
}
Else if (x==2){
Cout << “x is 2”;
}
Else{
Cout <<”value of x unknown”;
}
Question 9:
Observe the following block of code and determine what happens when x=2?
switch (x){
case 1:
case 2:
case 3:
cout<< "x is 3, so jumping to third branch";
goto thirdBranch;
default:
cout<<"x is not within the range, so need to say Thank You!";
}
a. Program jumps to the end of switch statement since there is nothing to do for x=2
b. The code inside default will run since there is no task for x=2, so, default task is run
c. Will display x is 3, so jumping to third branch and jumps to thirdBranch.
d. None of above
Question 10
Which of the following is false for switch statement in C++?
a. It uses labels instead of blocks
b. we need to put break statement at the end of the group of statement of a condition
c. we can put range for case such as case 1..3
d. None of above
Answers
Question 1:
cin extraction stops execution as soon as it finds any blank space character
a. true
b. false
Question 2:
string mystring;
getline(cin, mystring);
Question 3:
Question 4:
a. <iostream>
b. <string>
c. <sstring>
d. <sstream>
Question 5:
a. <iostream>
b. <string>
c. <sstring>
d. <sstream>
Question 6:
Question 7:
Question 8:
Question 9:
a. int
b. long int
c. short int
d. float
Question 10:
a. Global variables are declared in a separate file and accessible from any program.
b. Local variables are declared inside a function and accessible within the function only.
c. Global variables are declared inside a function and accessible from anywhere in program.
d. Local variables are declared in the main body of the program and accessible only from functions.
Answers
1. a. True
2. a. Reads a line of string from cin into mystring
3. d. None of above
4. d. <sstream>
5. c. <sstring>
6. b. The second input overwrites the first one
7. b. The program worked as expected without any errors during its execution
8. c. readable
9. c. short int
10 b. Local variables are declared inside a function and accessible within the function on
Question 1
Streams are
a. Abstraction to perform input and output operations in sequential media
b. Abstraction to perform input and output operations in direct access media
c. Objects where a program can either insert or extract characters to and from it
d. Both a and c
Question 2
Which of the following is known as insertion operator?
a. ^
b. v
c. <<
d. >>
Question 3:
Regarding the use of new line character (/n) and endl manipulator with cout statement
a. Both ways are exactly same
b. Both are similar but endl additionally performs flushing of buffer
c. endl can’t be used with cout
d. \n can’t be used with cout
Question 4:
Which of the following is output statement in C++?
a. print
b. write
c. cout
d. cin
Question 5:
Which of the following is input statement in C++?
a. cin
b. input
c. get
d. none of above
Question 6:
By default, the standard output device for C++ programs is
a. Printer
b. Monitor
c. Modem
d. Disk
Question 7:
By default, the standard input device for C++ program is
a. Keyboard
b. Mouse
c. Scanner
d. None of these
Question 8:
Which of the following statement is true regarding cin statement?
a. cin statement must contain a variable preceded by >> operator
b. cin does not process the input until user presses RETURN key
c. you can use more than one datum input from user by using cin
d. all of above
Question 9:
Which of the following is extraction operator in C++?
a. ^
b. v
c. <<
d. >>
Question 10:
When requesting multiple datum, user must separate each by using
a. a space
b. a tab character
c. a new line character
d. all of above
Answers
1. d. Both a and c
2. c. <<
3. b. Both are similar but endl additionally performs flushing of buffer
4. c. Cout
5. a. Cin
6. b. Monitor
7. a. Keyboard
8. d. All of above
9. d. >>
10. d. all of above
Question 1
In an assignment statement
a=b;
b. The value of b is assigned to variable a but the later changes on variable b will not effect the
value of variablea
c. The value of b is assigned to variable a and the later changes on variable b will effect the
value of variable a
d. The value of variable a is assigned to variable b and the value of variable b is assigned
to variable a.
Question 2
All of the following are valid expressions in C++
a = 2 + (b = 5);
a = b = c = 5;
a = 11 % 3
a. True
b. False
Question 3:
To increase the value of c by one which of the following statement is wrong?
a. c++;
b. c = c + 1;
c. c + 1 => c;
d. c += 1
Question 4:
When following piece of code is executed, what happens?
b = 3;
a = b++;
Question 5:
The result of a Relational operation is always
d. All of these
Question 6:
Which of the following is not a valid relational operator?
a. ==
b. =>
c. >=
d. >=
Question 7:
What is the final value of x when the code int x; for(x=0; x<10; x++) {} is run?
A. 10
B. 9
C. 0
D. 1
Question 8:
When does the code block following while(x<100) execute?
D. While it wishes
Question 9:
Which is not a loop structure?
A. for
B. do while
C. while
D. repeat until
Question 10:
How many times is a do while loop guaranteed to loop?
A. 0
B. Infinitely
C. 1
D. Variable
Answers
1. b. The value of b is assigned to variable a but the later changes on variable b will not effect the
value of variable a
2. a. True
3. c. c + 1 => c;
6. b. =>
7. A. 10
9. D. Repeat Until
10. C. 1
Question 1
A variable is/are
d. None of these
Question 2
a. Letters
b. Digits
c. Underscores
d. Spaces
Question 3
a. papername
b. writername
c. typename
d. printname
Question 4
a. bitand
b. bittand
c. biand
d. band
Question 5
a. The first one refers to a variable whose identifier is x and the second one refers to the
character constant x
b. The first one is a character constant x and second one is the string literal x
d. None of above
Question 6
a. \t
b. \v
c. \f
d. \w
Question 7
b. You can also concatenate several string constants separating them by one or several
blank spaces, tabulators, newline or any other valid blank character
c. If we want the string literal to explicitly made of wide characters, we can precede the
constant with the L prefix
d. All of above
Question 8
Question 9
d. Constructs an integer type variable with pathwidth as identifier and 100 as value
Question 10
In an assignment statement
c. The assignment always takes place from right to left and never the other way
d. All of above
Answers
2. d. Spaces
3. c. Typename
4. a. Bitand
5. a. The first one refers to a variable whose identifier is x and the second one refers to the
character constant x
6. d. \w
7. d. All of above
Question 1
Identify the correct statement
a. Programmer can use comments to include short explanations within the source code itself.
b. All lines beginning with two slash signs are considered comments.
d. both
Question 2
The directives for the preprocessors begin with
a. Ampersand symbol (&
Question 3
The file iostream includes
c. Both of these
d. None of these
Question 4
There is a unique function in C++ program by where all C++ programs start their execution
a. Start()
b. Begin()
c. Main()
d. Output()
Question 5
Every function in C++ are followed by
a. Parameters
b. Parenthesis
c. Curly braces
d. None of these
Question 6
Which of the following is false?
d. None of above
Question 7
Every statement in C++ program should end with
b. A Comma (,)
c. A Semicolon (
d. A colon (
Question 8
Which of the following statement is true about preprocessor directives?
Question 9
A block comment can be written by
Question 10
When writing comments you can
1. b. All lines beginning with two slash signs are considered comments.
4. c. Main()
5. b. Parenthesis
6. d. None of above
7. c. A semicolon
Question 1:
A function can not be overloaded only by its return type.
a. True
b. False
Question 2:
A function can be overloaded with a different return type if it has all the parameters same.
a. True
b. False
Question 3:
Inline functions involves some additional overhead in running time.
a. True
b. False
Question 4:
A function that calls itself for its processing is known as
a. Inline Function
b. Nested Function
c. Overloaded Function
d. Recursive Function
Question 5:
We declare a function with ______ if it does not have any return type
a. long
b. double
c. void
d. int
Question 6:
Arguments of a functions are separated with
a. comma (,)
b. semicolon (
c. colon (
d. None of these
Question 7:
Variables inside parenthesis of functions declarations have _____ level access.
a. Local
b. Global
c. Module
d. Universal
Question 8:
Observe following function declaration and choose the best answer:
int divide ( int a, int b = 2 )
b. Variable a and b are of int type and the initial value of both variables is 2
Question 9:
The keyword endl
Question 10:
Strings are character arrays. The last index of it contains the null-terminated character
a. \n
b. \t
c. \0
d. \1
Answers:
1. a. True
2. b. False
3. a. True
4. d. Recursive Function
5. c. Void
6. a. Comma (,)
7. a. Local
10. c. \0
http://interviewquestionstutorials.com/tag/100-top-c-c-
mcq-questions-answers-pdf/
Question 1:
The void specifier is used if a function does not have return type.
a. True
b. False
Question 2:
You must specify void in parameters if a function does not have any arguments.
a. True
b. False
Question 3:
Type specifier is optional when declaring a function
a. True
b. False
Question 4:
Study the following piece of code and choose the best answer
a=addition(x,y)
Question 5:
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
Question 6:
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
Question 7:
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
Question 8:
Overloaded functions are
c. Two or more functions with the same name but different number of parameters or type.
d. None of above
Question 9:
Functions can be declared with default values in parameters. We use default keyword to specify the
value of such parameters.
a. True
b. False
Question 10:
Examine the following program and determine the output
#include <iostream>
return (a * b);
{
return (a/b);
int main()
return 0;
a. 10.0 5.0
b. 5.0 2.5
c. 10.0 5
d. 10 2.5
Answers
1. a. True
3. b. False
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
Question 1.
What is the correct value to return to the operating system upon the successful completion of a
program?
A. -1
B. 1
C. 0
D. Programs do not return a value.
Question 2.
What is the only function all C++ programs must contain?
A. start()
B. system()
C. main()
D. program()
Question 3.
What punctuation is used to signal the beginning and end of code blocks?
A. { }
B. -> and <-
C. BEGIN and END
D. ( and )
Question 4.
What punctuation ends most lines of C++ code?
A. . (dot)
B. ; (semi-colon)
C. : (colon)
D. ' (single quote)
Question 5.
Which of the following is a correct comment?
A. */ Comments */
B. ** Comment **
C. /* Comment */
D. { Comment }
Question 6.
Which of the following is not a correct variable type?
A. float
B. real
C. int
D. double
Question 7.
Which of the following is the correct operator to compare two variables?
A. :=
B. =
C. equal
D. ==
Question 8.
Which of the following is true?
A. 1
B. 66
C. .1
D. -1
E. All of the above
Question 9.
Which of the following is the boolean operator for logical-and?
A. &
B. &&
C. |
D. |&
Question 10.
Evaluate !(1 && !(0 || 1)).
A. True
B. False
C. Unevaluatable
Answers
1. C. 0
2. C. main()
3. A. { }
4. B. ;
5. C. /* Comment */
6. B. real
7. D. ==
8. E. All of the above
9. B. &&
10. A. True
14. s
15. s
16. s
17. s
18.
s
ss
19. s
20. s
21. s
22. s
23. s
24. s
25. s
26. s
27. s
28. s
29. s
30. s
31. s
32. s
s
s
s
s
s