wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C++ Programming Quiz (first)

Total questions: 52

Worksheet time: 26mins

Name
Class
Date
1.

What is the main difference between // and / */ comments?

a)

// is for single-line comments, while /* */ is for multi-line comments

b)

// is for multi-line comments, while /* */ is for single-line comments

c)

Both can be used interchangeably

d)

Neither is a valid comment syntax in C++

2.

Which of the following is used to output text in C++?

a)

cout <<

b)

print()

c)

console.log()

d)

output()

3.

What does the ++ operator do in C++?

a)

Increases a variable's value by 1

b)

Decreases a variable's value by 1

c)

Multiplies a variable by 2

d)

Divides a variable by 2

4.

What is an algorithm?

a)

A sequence of simple instructions that solve a problem

b)

A random set of commands without structure

c)

A method of compressing programming language syntax

d)

A type of computer hardware

5.

What is the purpose of the assignment operator (=) in C++?

a)

It assigns a value to a variable

b)

It compares two values

c)

It swaps two variables

d)

It multiplies two numbers

6.

Which operator is used to check if one value is less than or equal to another in C++?

a)

<=

b)

<

c)

>=

d)

==

7.

Which data type is used to store whole numbers without decimals in C++?

a)

int

b)

double

c)

char

d)

string

8.

What is the purpose of a flowchart in algorithm design?

a)

To visually represent the steps of an algorithm

b)

To execute an algorithm

c)

To write pseudocode

d)

To debug a program

9.

What is the correct syntax to declare an integer variable in C++?

a)

int x;

b)

variable x;

c)

declare int x;

d)

int = x;

10.

Use ____________ to specify a block of code to be executed, if the same condition is false.

a)
else
b)

switch

c)

break

d)

continue

11.

What was the main reason for the intentionally limited syntax of BASIC (1964)?

a)

To make the language easy to learn

b)

To improve execution speed

c)

To support complex algorithms

d)

To make it compatible with all operating systems

12.

Use ____________ to specify many alternative blocks of code to be executed.

a)
switch
b)

else

c)

break

d)

return

13.

Which of the following is a multi-line comment in C++?

a)

/* This is a comment */

b)

// This is a comment

c)

# This is a comment

d)

-- This is a comment

14.

Which operator is used to assign a value to a variable in C++?

a)

=

b)

==

c)

!=

d)

=>

15.

How are syntax rules typically defined?

a)

Using the Backus-Naur form

b)

Through random trial and error

c)

By copying rules from natural languages

d)

Without any predefined structure

16.

Which characteristic does a good algorithm have?

a)

It is clear and unambiguous

b)

It must be written in a programming language

c)

It must be long and complex

d)

It should have infinite steps

17.

Which operator is used to check if two values are not equal in C++?

a)

!=

b)

==

c)

<

d)

>

18.

What type of value does the condition inside an if statement evaluate to?

a)

Boolean (true or false)

b)

Integer only

c)

String

d)

Character

19.

What is a programming language?

a)

A set of keywords, symbols, identifiers, and rules for communication with a computer

b)

A tool used only for web development

c)

A type of hardware that runs computer programs

d)

A collection of pre-written software applications

20.

Which of the following is not a valid comment in C++?

a)

! This is a comment !!

b)

// This is a comment

c)

/* This is a comment */

d)

// Another comment

21.

Which data type is used to store text in C++?

a)

string

b)

char

c)

text

d)

word

22.

Which operator is used to check if two values are equal in C++?

a)

==

b)

=

c)

!=

d)

<=

23.

How do you correctly start the main function in C++?

a)

int main()

b)

main++

c)

main()

d)

start main()

24.

Which statement about the assignment operator is true?

a)

It updates the value stored in a variable

b)

It checks for equality between two variables

c)

It swaps the values of two variables

d)

It declares a variable without assigning a value

25.

Which data type should be used to store a single character in C++?

a)

char

b)

string

c)

character

d)

text

26.

What is the difference between = and == in C++?

a)

= assigns a value, while == compares two values

b)

= compares two values, while == assigns a value

c)

Both perform assignment

d)

Both perform comparison

27.

Which operator is used to check if one value is greater than or equal to another in C++?

a)

>=

b)

>

c)

<

d)

==

28.

What is the purpose of a compiler?

a)

To translate source code into machine instructions

b)

To directly execute source code without tr

29.

Which operator is used to check if one value is greater than another in C++?

a)

>

b)

<

c)

<=

d)

!=

30.

What is the purpose of a compiler?

a)

To translate source code into machine instructions

b)

To directly execute source code without translation

c)

To convert machine instructions back to source code

d)

To store software documentation

31.

What happens to comments when a C++ program is compiled?

a)

They are ignored by the compiler

b)

They cause an error if too many are used

c)

They slow down the execution of the program

d)

They are included in the final executable file

32.

What is the correct syntax for declaring a variable in C++?

a)

type variableName = value;

b)

variableName = value;

c)

declare variableName = value;

d)

type = variableName value;

33.

What is the purpose of an if statement in C++?

a)

To execute a block of code only if a specified condition is true

b)

To execute a block of code in all cases

c)

To declare a variable

d)

To define a function

34.

Why does source code need another program to execute?

a)

Because computers can only execute their native machine instructions

b)

Because source code is already in machine language

c)

Because source code cannot be written by humans

d)

Because source code does not contain executable instructions

35.

Which keyword is used to display output in C++?

a)

cout

b)

cin

c)

print

d)

display

36.

Use ____________ to specify a new condition to test, if the first condition is false.

a)

else if

b)

switch

c)

break

d)

while

37.

Which of the following is NOT a component of programming language syntax?

a)

Data compression methods

b)

Keywords

c)

Symbols

d)

Identifiers

38.

Use ____________ to specify a block of code to be executed, if a specified condition is true.

a)

if

b)

else

c)

switch

d)

loop

39.

Which data type is used to store floating-point numbers with decimals in C++?

a)

double

b)

int

c)

char

d)

bool

40.

Which of the following is a correct use of the assignment operator?

a)

int x = 10;

b)

int x == 10;

c)

10 = x;

d)

int x < 10;

41.

Which of the following is a correct syntax for an if statement in C++?

a)

if (x > 5) { cout << "x is greater than 5"; }

b)

if x > 5 { cout << "x is greater than 5"; }

c)

if (x > 5) cout << "x is greater than 5";

d)

if x > 5 then { cout << "x is greater than 5"; }

42.

What is the output of the following code snippet? if (10 < 5) { cout << "x is less than 5"; } cout << "End of program";

a)

End of program

b)

x is less than 5 End of program

c)

x is less than 5

d)

Compilation error

43.

What is pseudocode?

a)

A high-level representation of an algorithm

b)

A type of programming language

c)

A low-level machine code

d)

A compiled version of an algorithm

44.

What is the correct way to declare multiple variables of the same type in C++?

a)

int a, b, c;

b)

variable a, b, c;

c)

variable int a, b, c;

d)

declare int a, b, c;

45.

What will happen if the condition inside an if statement is false?

a)

The block of code inside {} will be skipped

b)

The program will terminate

c)

The condition will be ignored, and the block will execute

d)

The compiler will throw an error

46.

Which data type is used to store values with two states (true or false) in C++?

a)

bool

b)

int

c)

char

d)

string

47.

What will be the value of x after the following statement? int x = 5; x = 10;

a)

10

b)

5

c)

15

d)

Undefined

48.

What is the purpose of syntax in a programming language?

a)

To define rules for structuring code

b)

To improve execution speed

c)

To make programming languages harder to learn

d)

To store large amounts of data

49.

What is a computer program?

a)

A sequence or set of instructions in a programming language for a computer to execute

b)

A hardware component of a computer

c)

A physical storage device for programs

d)

A mathematical formula used in software

50.

What is the main goal of debugging in programming?

a)

To find and fix errors in a program

b)

To make the code run faster

c)

To add more features to the program

d)

To compile the program

51.

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

a)

.cpp

b)

.t

c)

.k++

d)

.kp

52.

Which keyword is used to take user input in C++?

a)

cin

b)

cout

c)

input

d)

scanf