Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Introduction to C++ 2024/25

Total questions: 10

Worksheet time: 8mins

Name
Class
Date
1.

What is the correct syntax for an if statement in C++?

a)

if x > 5 {}

b)

if (x > 5) {}

c)

if x > 5 then {}

d)

if {x > 5}

2.

Which of the following is a valid declaration of an integer variable in C++?

a)

int 1 number;

b)

number int;

c)

int number;

d)

number : int;

3.

Which of the following is the correct way to read an integer from user input using cin?

a)

cin >> int userInput;

b)

int userInput;

cin << userInput;

c)

int userInput;

cin >> userInput;

d)

userInput = cin;

4.

What data type would you use to store a single character in C++?

a)

string

b)

char

c)

int

d)

double

5.

What will the following code display?

a)

"x is greater than 5"

b)

"x is not greater than 5"

c)

"x is greater than 10"

d)

None of the above

6.

Which C++ logical operator is used for logical AND?

a)

&&

b)

||

c)

!

d)

&

7.

What is the purpose of the "else if" statement in C++?

a)

To declare variables

b)

To create a nested if

c)

To specify an alternative condition to be tested

d)

To end a program

8.

What is the correct way of checking if something is less than or equal to:

a)

if(x>=10)

b)

if(x=<10)

c)

if(x<&&=10)

d)

if(x<=10)

9.

Which of the following correctly represents a floating-point variable?

a)

float pi = 3.14;

b)

float pi = "3.14";

c)

int pi = 3.14;

d)

float 3.14 = pi;

10.

What will the following code print if y is set to 0?

if(y) { cout << "True"; }

else { cout << "False"; }

a)

True

b)

False

c)

0

d)

Nothing