Font size
WorksheetsC++ Programming Foundations Quiz
Total questions: 57
Worksheet time: 49mins
Which of the following is a feature introduced in C++ to support object-oriented programming?
Pointer arithmetic
Polymorphism
Preprocessor directives
Static typing
True or False: A variable declared as const int x = 5; can be modified after initialization.
True
False
What is the output of the following code? int x = 10; if (x > 5) cout << "High"; else cout << "Low";
High
Low
Compile error
No output
Which of the following function declarations demonstrates valid function overloading?
void print(int x); and int print(int x);
void print(int x); and void print(float x);
void print(int x); and void print(int y);
void print(int x); and void print(int x, int y = 0);
What is the output of this recursive function for n = 4! int sum(int n) { if (n <= 0) return 0; return n + sum(n - 1); }
10
6
4
Stack overflow
True or False: A C++ class can have multiple constructors with different parameter lists.
True
False
What is the value of x after executing: int x = 5; x += x++ * 2;?
15
11
12
Undefined
What is the purpose of a constructor in a C++ class?
To deallocate memory
To initialize object data members
To define class methods
To handle exceptions
Which operator is used to access members of a class through a pointer?
.
->
::
&
Write a C++ recursive function to compute the nth Fibonacci number. Explain one advantage and one disadvantage of using recursion for this problem.
Define a C++ class Rectangle with private data members for length and width, and public methods to calculate area and perimeter. Show how to create an object and use these methods.
Write a C++ function using a loop to check if a number is prime. Explain how you would debug it if it incorrectly identifies 1 as prime.
What is the only function that all C++ programs must contain?
start()
system()
main()
program()
Which command in C++ moves the text to the next line?
\t
\n
\r
\s
C++ was developed by?
Dennis Ritchie
Bjarne Stroustrup
James Gosling
Guido van Rossum
What is the extension of C++ programs?
.c
.css
.cpp
.jsp
Which syntax is correct in printing an output in a C++ program?
print<<"Good Day!";
cout<<"Good Day!";
printf<<"Good Day!";
cout<<"Good"<<"Day!";
Insertion operator (<<) is used with?
cin
cout
both of the above
main
break() is used along which statements?
while
switch
for-while
if-then-else
This is a code that has not yet been linked into a complete program.
Source Code
Assembly Code
Object Code
Machine Code
The object code is produced in what program development phase?
Preprocessing
Compilation
Linking
Loading
Executing
What happens first when a C++ executable is run?
The preprocessor converts the source code into an object code.
The compiler converts the object code into an executable code.
The linker links the object code with the missing functions needed to produce the executable code.
The loader places the program in the memory
The CPU executes the program
By default, how are instructions executed by the CPU?
One instruction at a time
Several Instructions at a time
All instructions in one time
None of the above
Single line comments are denoted by what symbol?
//
\
/*
*/
Which of the following are ignored by the C++ compiler and the computer? (Check all that apply)
Comments
Blank lines
Spaces
Tab Spaces
Preprocessing directives
A preprocessing directive starts with what symbol?
//
#
(
{
The library defined in the preprocessor directive must be enclosed by what symbols?
{ }
[ ]
< >
( )
Blanks lines, spaces, and tab characters are called?
Keywords
White spaces
Symbols
Escape Sequences
A code that is reserved by C++ for a specific use.
Keyword
White space
Symbol
Escape Sequence
Which symbol starts a block of code?
<
(
{
[
The words enclosed in double quotation marks are known as the following EXCEPT what?
String
Character String
String Literal
Stream
The semicolon (;) is used to?
Start a block of code
Terminate a function
Start a statement
End a statement
Which of the following is the scope resolution operator?
<<
>>
::
\
Which of the following is the escape character operator?
<<
>>
::
\
Which of the following is the input stream object?
>>
<<
cin
cout
Which of the following is NOT a VALID identifier?
X1
_X1
x1
_1x
1x
NOT a VALID identifier? Which of the following are VALID identifiers?
X1
_X1
x1
_1x
1x
The process of creating a new variable without value
declaration
naming
instantiation
assigning
What does <= mean?
less than
greater than
less than or equal to
greater than or equal to
What punctuation is used to signal the beginning and end of code blocks?
{ }
-> and <-
BEGIN and END
( and )
Which of the following is a correct comment?
*/ Comments /
** Comment **
/ Comment */
{ Comment }
After running the following code, what will be the value of x? y = 3; x = 5 * y;
3
5
15
0
A programmer is:
person who writes code and communicates instructions to a computer
person who types
person who studies computers
error or mistake in your code
What is the output of this program? int main() { cout << "Hi everybody"; return 0; }
"Hi everybody"
Hi everybody"
Hi everybody
"Hi everybody
Which of the following is NOT a logical operator in C++ language?
&
&&
||
!
Which of the following is NOT a comparison operator in C++ language?
>
<=
=
==
If originally x=2, y=0, and z=1, what is the value of x, y, and z after executing the following code? if (x > y) y = x; else z = x;
x=2 y=2 z=1
x=0 y=2 z=0
x=2 y=1 z=1
x=2 y=0 z=1
All variables must be declared before they are used.
True
False
I liked the quiz?
Any suggestions?
True or False: A Boolean variable is declared with the bool keyword.
True
False
True or False: The break statement can be used with while, for, and switch statements but not with if-then-else.
True
False
True or False: A function in C++ can have default arguments only for the last parameters in the parameter list.
True
False
Which of the following operators are used in C++? (Select all that apply)
==
+=
**
++
Write a C++ program using a switch statement to classify a user-entered character as a vowel or consonant. Explain how you would debug it if it incorrectly classifies 'y' as a vowel.
Write a C++ function to overload the max function for integers and doubles. Explain the role of function overloading in this context.
Define a C++ class Student with private data members for name and roll number, and public methods to set and display them. Show how to create and use an object. Explain one benefit of encapsulation.
