9/13/2019 C++ Programming MCQs Test 3 | Online C++ Programming Test - Studytonight
(/)
C++ Programming MCQs Test 3
This Test will cover complete C++ with very important questions, starting off from basics to advanced level.
Q. Which of the following parameter passing mechanism(s) is/are supported by
C++, but not by C?
A. Pass by value
B. Pass by reference
C. Pass by value-result
D. All of the above
Correct Answer : OPTION B, Pass by reference. As such C does not support pass by reference. But
it can be simulated by using pointers.
Q. cout stands for __________.
A. class output
B. character output
C. common output
D. call output
Correct Answer : OPTION C, common output
Q. The following program __________.
https://www.studytonight.com/cpp/tests/10# 1/8
9/13/2019 C++ Programming MCQs Test 3 | Online C++ Programming Test - Studytonight
#include <iostream>
using namespace std;
void abc(int &p)
{
cout << p;
}
void main(void)
{
float m = 1.23;
abc(m);
cout << m;
}
A. results in a compila on error
B. results in a run me error
C. prints 1.23
D. prints 1
Correct Answer : OPTION A, results in a compilation error
Q. reference is not same as a pointer because __________.
A. a reference can never be null
B. a reference once established cannot be changed.
C. reference doesn't need an explicit dereferencing mechanism.
D. they are one and same
Correct Answer : OPTION A, a reference can never be null
Q. If a piece of code can be implemented as a macro or as an inline function,
which of the following factors favour implementation as an inline function?
A. Speed of execu on
https://www.studytonight.com/cpp/tests/10# 2/8
9/13/2019 C++ Programming MCQs Test 3 | Online C++ Programming Test - Studytonight
B. Flexibility to manipulate as a pointer
C. Source code size
D. Interac ng with other components(like variables in an expression), in the correct way.
Correct Answer : OPTION B, Flexibility to manipulate as a pointer
Q. The fields in a structure of a C program are by default __________.
A. protected
B. public
C. private
D. none of the above
Correct Answer : OPTION B, public
Q. The fields in a class, of a C++ program are by default __________.
A. protected
B. public
C. private
D. none of the above
Correct Answer : OPTION C, private
Q. For the below declarations, Which of the following statements is/are illegal?
https://www.studytonight.com/cpp/tests/10# 3/8
9/13/2019 C++ Programming MCQs Test 3 | Online C++ Programming Test - Studytonight
Declaration 1: char a;
Declaration 2: const char aa ='h';
Declaration 3: char *na;
Declaration 4: const char *naa;
Statement 1: aa = a;
Statement 2: na = &a;
Statement 3: na = &aa;
A. Only 1 and 2
B. Only 2 and 3
C. Only 1 and 3
D. All the three statements are illegal
Correct Answer : OPTION C, Only 1 and 3
Q. Forgetting to include a file(like cmath or math.h ) that is necessary will result
in __________.
A. Compila on error
B. Warning when the program is run
C. Error at link me
D. Warning when the program is compiled
Correct Answer : OPTION C, error at link time
Q. Assume that the random number generating function, rand() , returns an
integer between 0 and 10000 (both inclusive). If you want to simulate the
throwing of a die using this random function, you will use the expression
__________.
https://www.studytonight.com/cpp/tests/10# 4/8
9/13/2019 C++ Programming MCQs Test 3 | Online C++ Programming Test - Studytonight
A. rand()%6
B. rand()%6+1
C. rand()%5+1
D. none of the above
Correct Answer : OPTION B, rand()%6+1. It should randomly generate any integer between 1 and 6.
rand()%6 returns an integer from 0 to 5. To make it 1 to 6, we need to add 1.
Q. Assume that the random number generating function, rand() , returns an
integer between 0 and 10000 (both inclusive). To randomly generate a number
between a and b (both inclusive), you will use the expression __________.
A. rand()%(b-a)
B. (rand()%a) + b
C. (rand()%(b-a)) + a
D. (rand()%(b-a+1)) + a
Correct Answer : OPTION D, (rand()%(b-a+1)) + a
Q. Which of the following comments about inline comments are true?
A. A func on is declared inline by typing the keyword inline before the return value of the func on.
B. A func on is declared inline by typing the keyword inline a er the return value of the func on.
C. A func on that is declared inline may not be treated inline.
D. Inline func ons are essen ally same as implemen ng a func on as macro.
Correct Answer : OPTION A, A function is declared inline by typing the keyword inline before the
return value of the function.
https://www.studytonight.com/cpp/tests/10# 5/8
9/13/2019 C++ Programming MCQs Test 3 | Online C++ Programming Test - Studytonight
Q. Which of the following decides if a function that is declared inline , is
indeed going to be treated inline in the executable code?
A. Compiler
B. Linker
C. Loader
D. Preprocessor
Correct Answer : OPTION A, Compiler
Q. Which of the following type of functions is an ideal candidate for being
declared inline ?
A. A func on that is small and is not called frequently.
B. A func on that is small and is called frequently.
C. A func on that is not small and is not called frequently.
D. A func on that is not small and is called frequently.
Correct Answer : OPTION B, A function that is small and is called frequently.
Q. One disadvantage of pass-by-reference is that the called function may
inadvertently corrupt the caller's data. This can be avoided by :
A. passing pointers
B. declared the formal parameters constant
C. declared the actual parameters constant
D. all of the above
Correct Answer : OPTION B, declared the formal parameters constant
https://www.studytonight.com/cpp/tests/10# 6/8
9/13/2019 C++ Programming MCQs Test 3 | Online C++ Programming Test - Studytonight
SUBMIT TEST ()
What is Studytonight?
About Us (/about)
Authors (/authors)
Collaborate (/collaborate)
Testimonials (/testimonials)
Privacy Policy (/privacy)
Terms (/terms)
Contact Us (/contact)
Suggest (/suggest)
Tutorials
Android (/android)
Core Java (/java)
C++ (/cpp)
Data Structures (/data-structures)
Python (/python)
Network Programming (/network-programming-in-python)
DBMS & SQL (/dbms)
Servlet (/servlet)
More... (/library)
Tests
Core Java (/tests)
Android (/tests/?subject=android)
C++ (/tests?/?subject=cpp)
DBMS (/tests?/?subject=dbms)
C Language (/tests?/?subject=c)
More... (/tests)
Learn to Code
https://www.studytonight.com/cpp/tests/10# 7/8
9/13/2019 C++ Programming MCQs Test 3 | Online C++ Programming Test - Studytonight
HTML (/code/html)
CSS (/cascading-style-sheet/)
Website Development (/code/playground)
Java Interview Question (/ ashcards/Java)
C++ Interview Question (/ ashcards/Cpp)
OS Interview Question (/ ashcards/OS)
DBMS Interview Question (/ ashcards/Sql)
More... (/ ashcards)
https://www.studytonight.com/cpp/tests/10# 8/8