Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz 2 Progdas

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What is the purpose of the #include directive in a C++ program?

a)

To define a macro for constants

b)

To start the execution of the program

c)

To declare the main function

d)

To include standard input/output stream functionalities

2.

Which of the following correctly represents the syntax for declaring a constant macro in C++?

a)

#define PI = 3.14159

b)

const double PI = 3.14159

c)

constant double PI = 3.14159

d)

#define PI 3.14159

3.

In the context of C++ programming, what is the primary function of the main() function?

a)

It performs memory management

b)

It contains all preprocessor directives

c)

It handles exceptions

d)

It starts the program execution

4.

Which of the following data types is used to represent whole numbers in C++?

a)

float

b)

double

c)

char

d)

int

5.

What does the following C++ statement do? cout << "Hello, World!";

a)

It reads input from the user.

b)

It outputs the string "Hello, World!" to the console.

c)

It compares two strings.

d)

It initializes a variable.

6.

Which of the following is a correct example of a single-line comment in C++?

a)

# This is a comment

b)

// This is a comment

c)

/* This is a comment */

d)

<!—This is a comment—>

7.

What is the output of the following C++ code snippet?
int x = 10;
int y = 20;
cout << x + y;

a)

1020

b)

10 + 20

c)

10 20

d)

30

8.

Which of the following statements about variable declaration in C++ is true?

a)

Variables can be used without being declared

b)

Variables are automatically initialized to zero

c)

Variables cannot store data types other than integers

d)

Variables must be declared before they are used in a program

9.

Which data type in C++ is best suited for representing a single character?

a)

string

b)

int

c)

float

d)

char

10.

What is the role of the return statement in the main() function of a C++ program?

a)

It declares variables

b)

It initializes the program

c)

It starts the execution of the main() function

d)

It ends the program execution and returns a value to the operating system

11.

Which statement about program control in C++ is TRUE?

a)

Program control only manages the sequence of function calls

b)

Program control can alter the order in which statements are executed

c)

Program control is used solely for looping structures

d)

Program control only affects the flow of main() function

12.

What does a selection statement allow a program to do?

a)

To repeat a set of instructions a specific number of times

b)

To decide which of several actions to take based on a condition

c)

To terminate the execution of a loop or function

d)

To store values that will be used in later operations

13.

Which characteristic distinguishes a switch statement from an if statement in C++?

a)

An if statement is less versatile than a switch statement for multiple options

b)

An if statement can only evaluate simple conditions

c)

A switch statement can evaluate complex boolean expressions

d)

A switch statement is restricted to comparing integral values

14.

Which of the following operators is used to check for equality in a C++ conditional statement?

a)

=

b)

==

c)

&&

d)

||

15.

Which selection structure allows you to evaluate multiple conditions, where each condition can lead to a different block of code being executed?

a)

if

b)

switch

c)

for

d)

while

16.

Which of the following is NOT a valid condition to be used in a switch statement in C++?

a)

An integer constant

b)

A char literal

c)

A floating-point value

d)

An integral expression

17.

Which operator combination is correctly used to check if two conditions are both true in a C++ if statement?

a)

&&

b)

||

c)

==

d)

><

18.

Why might nested if statements be preferred over a switch statement in certain C++ scenarios?

a)

Because nested if statements are simpler to write and understand

b)

Because nested if statements are inherently faster

c)

Because nested if statements consume less memory

d)

Because nested if statements can handle more complex conditions

19.

Which of the following conditions would you use to check if a variable age is between 12 and 17 inclusive?

a)

age > 12 && age < 17

b)

age < 12 || age > 17

c)

age >= 12 && age <= 17

d)

age == 12 || age == 17

20.

What is the primary purpose of an if-else statement?

a)

To repeat a set of statements until a condition is met

b)

To choose between two alternative blocks of code based on a condition

c)

To decide the number of times a block of code is executed

d)

To exit a loop