Font size
WorksheetsIntroduction to C++
Total questions: 20
Worksheet time: 10mins
What is the correct file extension for a C++ source file?
.cpp
.exe
.java
.txt
What is the purpose of the #include
To allow input and output operations
To define a new programming language
To import all available functions in C++
To format text output
What does the int main() function do?
Starts the execution of a C++ program
Declares global variables
Runs system-level commands
Automatically prints output
Which of the following is NOT a valid C++ variable name?
myVariable
2cool4school
_underscore_variable
camelCaseExample
What will cout << "Hello" << " World!" << endl; output?
A) Hello World!
B) HelloWorld!
C) "Hello" "World!"
D) Compilation error
What is the correct way to declare a constant variable in C++?
const double PI = 3.14159;
let PI = 3.14159;
define PI 3.14159;
permanent double PI = 3.14159;
Which of the following is NOT a valid C++ data type?
int
double
string
decimal
What happens if you divide an integer by zero in C++?
A) A runtime error occurs
B) The program returns infinity
C) The result is 0
D) The compiler automatically handles the exception
What does the modulus operator (%) do?
Returns the remainder of a division
Divides two numbers
Converts values to percentages
Returns the absolute value
Which statement correctly initializes a char variable in C++?
char letter = 'A';
char letter = "A";
char letter = A;
character letter = 'A';
What will cout << (4 > 3) << endl; output? {Tricky one! I will explain after}
true
1
Yes
4 > 3
Which C++ control structure is used to make decisions?
if statements
cout statements
while loops
for loops
What does the switch statement do in C++?
Evaluates an expression and jumps to a case label
Controls program execution speed
Replaces if statements in all cases
Declares multiple variables
What is the difference between while and do-while loops?
while loops check the condition before running, do-while runs at least once
do-while loops execute more efficiently
while loops only work with integers
There is no difference
Which of the following statements is true about cin?
It is used for input in C++
It prints output to the console
It is used for file handling
It only works with integer values
The (a) statement is used to exit a function and return a value to the calling function.
In C++, a ________ is a sequence of characters enclosed in double quotes.
string
integer
character
boolean
The ________ operator is used to access the address of a variable in memory.
& (address-of operator)
* (dereference operator)
% (modulus operator)
+ (addition operator)
A ________ loop executes a block of code at least once before checking its condition.
do-while
while
for
foreach
The (a) library must be included to use mathematical functions like pow() and sqrt().
