wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Introduction to C++

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What is the correct file extension for a C++ source file?

a)

.cpp

b)

.exe

c)

.java

d)

.txt

2.

What is the purpose of the #include directive?

a)

To allow input and output operations

b)

To define a new programming language

c)

To import all available functions in C++

d)

To format text output

3.

What does the int main() function do?

a)

Starts the execution of a C++ program

b)

Declares global variables

c)

Runs system-level commands

d)

Automatically prints output

4.

Which of the following is NOT a valid C++ variable name?

a)

myVariable

b)

2cool4school

c)

_underscore_variable

d)

camelCaseExample

5.

What will cout << "Hello" << " World!" << endl; output?

a)

A) Hello World!

b)

B) HelloWorld!

c)

C) "Hello" "World!"

d)

D) Compilation error

6.

What is the correct way to declare a constant variable in C++?

a)

const double PI = 3.14159;

b)

let PI = 3.14159;

c)

define PI 3.14159;

d)

permanent double PI = 3.14159;

7.

Which of the following is NOT a valid C++ data type?

a)

int

b)

double

c)

string

d)

decimal

8.

What happens if you divide an integer by zero in C++?

a)

A) A runtime error occurs

b)

B) The program returns infinity

c)

C) The result is 0

d)

D) The compiler automatically handles the exception

9.

What does the modulus operator (%) do?

a)

Returns the remainder of a division

b)

Divides two numbers

c)

Converts values to percentages

d)

Returns the absolute value

10.

Which statement correctly initializes a char variable in C++?

a)

char letter = 'A';

b)

char letter = "A";

c)

char letter = A;

d)

character letter = 'A';

11.

What will cout << (4 > 3) << endl; output? {Tricky one! I will explain after}

a)

true

b)

1

c)

Yes

d)

4 > 3

12.

Which C++ control structure is used to make decisions?

a)

if statements

b)

cout statements

c)

while loops

d)

for loops

13.

What does the switch statement do in C++?

a)

Evaluates an expression and jumps to a case label

b)

Controls program execution speed

c)

Replaces if statements in all cases

d)

Declares multiple variables

14.

What is the difference between while and do-while loops?

a)

while loops check the condition before running, do-while runs at least once

b)

do-while loops execute more efficiently

c)

while loops only work with integers

d)

There is no difference

15.

Which of the following statements is true about cin?

a)

It is used for input in C++

b)

It prints output to the console

c)

It is used for file handling

d)

It only works with integer values

16.

The (a)   statement is used to exit a function and return a value to the calling function.

17.

In C++, a ________ is a sequence of characters enclosed in double quotes.

a)

string

b)

integer

c)

character

d)

boolean

18.

The ________ operator is used to access the address of a variable in memory.

a)

& (address-of operator)

b)

* (dereference operator)

c)

% (modulus operator)

d)

+ (addition operator)

19.

A ________ loop executes a block of code at least once before checking its condition.

a)

do-while

b)

while

c)

for

d)

foreach

20.

The (a)   library must be included to use mathematical functions like pow() and sqrt().