Basic C++
Basic C++
Basic C++
Questions
Question 1
a.
b.
c.
d.
Streams are
Abstraction to perform input and output operations in sequential media
Abstraction to perform input and output operations in direct access media
Objects where a program can either insert or extract characters to and from it
Both a and c
Question 2
a.
b.
c.
d.
Question 3:
a.
b.
c.
d.
Regarding the use of new line character (/n) and endl manipulator with cout statement
Both ways are exactly same
Both are similar but endl additionally performs flushing of buffer
endl cant be used with cout
\n cant be used with cout
Question 4:
a.
b.
c.
d.
Question 5:
a.
b.
c.
d.
Question 6:
a.
b.
c.
d.
Question 7:
a.
b.
c.
d.
Question 8:
a.
b.
c.
d.
Question 9:
a.
b.
c.
d.
Question 10:
a.
b.
c.
d.
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
Basics of C++ - Objective Questions (MCQs)
Question 1:
cin extraction stops execution as soon as it finds any blank space character
a.
b.
true
false
Question 2:
Observe the following statements and decide what do they do.
string mystring;
getline(cin, mystring);
a.
b.
c.
d.
Question 3:
Regarding stringstream identify the invalid statement
a.
b.
c.
d.
Question 4:
Which of the header file must be included to use stringstream?
a.
b.
c.
d.
<iostream>
<string>
<sstring>
<sstream>
Question 5:
Which of the following header file does not exist?
a.
b.
c.
d.
<iostream>
<string>
<sstring>
<sstream>
Question 6:
If you use same variable for two getline statements
a.
b.
c.
d.
Question 7:
The return 0; statement in main function indicates
a.
b.
c.
d.
Question 8:
Which of the following is not a reserve keyword in C++?
a.
b.
c.
d.
mutable
default
readable
volatile
Question 9:
The size of following variable is not 4 bytes in 32 bit systems
a.
b.
c.
d.
int
long int
short int
float
Question 10:
Identify the correct statement regarding scope of variables
a.
b.
c.
d.
Global variables are declared in a separate file and accessible from any program.
Local variables are declared inside a function and accessible within the function only.
Global variables are declared inside a function and accessible from anywhere in program.
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 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
int x=5, y=3, z;
a=addition(x,y)
a.
The function addition is called by passing the values
b.
The function addition is called by passing reference
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
c.
The variables x and y are passed to the function addition
d.
None of above are valid.
Question 6:
If the type specifier of parameters of a function is followed by an ampersand (&
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
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
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>
using namespace std;
int operate (int a, int b)
{
return (a * b);
}
float operate (float a, float b)
{
return (a/b);
}
int main()
{
int x=5, y=2;
10.0
5.0
10.0
10
5.0
2.5
5
2.5
Answers
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
Basics of C++ - Objective Questions (MCQs) Set - 1
Questions
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
Basics of C++ - Objective Questions (MCQs)
Question 1:
b.
c.
d.
Question 2:
Looping in a program means
a.
b.
c.
Both of above
d.
None of above
Question 3:
The difference between while structure and do structure for looping is
a.
b.
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.
b.
c.
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;
}
a.
b.
c.
d.
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.
d.
None of above
Question 10
Which of the following is false for switch statement in C++?
a.
b.
we need to put break statement at the end of the group of statement of a condition
c.
d.
None of above
Answers
1.
2.
3.
4.
b. Until
5.
d. Switch
6.
d. Switch
7.
8.
9.