wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C++ Quiz

Total questions: 40

Worksheet time: 17mins

Name
Class
Date
1.

What is a correct syntax to output "Hello World" in C++?

a)

System.out.println("Hello World");

b)

Console.Writeline("Hello World");

c)

cout<<"Hello World";

d)

print("Hello World");

2.

Which data type is used to create a variable that should store text?

a)

Txt

b)

String

c)

string

d)

myString

3.

How do you create a variable with the numeric value 5?

a)

int x=5;

b)

num x=5

c)

double x=5;

d)

x=5;

4.

How do you create a variable with the floating number 2.8?

a)

int x = 2.8;

b)

byte x = 2.8

c)

double x = 2.8;

d)

x = 2.8;

5.

Which method can be used to find the length of a string?

a)

getSize()

b)

getLength()

c)

length()

d)

len()

6.

Which operator is used to add together two values?

a)

The + sign

b)

The & sign

c)

The * sign

7.

Are the identifiers "firstname" and "FirstName" the same?

a)

Yes

b)

No

8.

A C++ identifier can start with a digit.

a)

True

b)

False

9.

What is the definition of an array?

a)

An array is a mathematical equation used to calculate averages.

b)

An array is a data structure that stores a collection of elements, each identified by at least one array index or key.

c)

An array is a type of fish found in the ocean.

d)

An array is a type of loop in programming languages.

10.

How are arrays declared in C++?

a)

By using parentheses instead of square brackets

b)

By specifying the size first followed by the data type

c)

By omitting the data type and size

d)

By specifying the data type of the elements followed by square brackets containing the size of the array.

11.

How are array indexes calculated in C++?

a)

Array indexes in C++ start from 0.

b)

Array indexes in C++ start from 1.

c)

Array indexes in C++ start from -1.

d)

Array indexes in C++ start from 100.

12.

The semicolon (;) is used to?

a)

Start a block of code

b)

Terminate a function

c)

Start a statement

d)

End a statement

13.

Which of the following is the input stream object?

a)

>>

b)

<<

c)

cin

d)

cout

14.

Which of the following is NOT a VALID identifier?

a)

X1

b)

_X1

c)

x1

d)

_1x

e)

1x

15.

All variables must be declared before they are used.

a)

True

b)

False

16.

What is the type of the temp variable?

var temp = 14.55;

a)

Double

b)

Boolean

c)

Integer

d)

String

17.

What is the output of this program? Program int main() { cout<<"Hi everybody"; return 0; }

a)

"Hi everybody"

b)

Hi everybody"

c)

Hi everybody

d)

"Hi everybody

18.

What is the only function all C++ programs must contain?

a)

start()

b)

system()

c)

main()

d)

program()

19.

Which of the following is a valid relational operator in C++?

a)

=<

b)

=>

c)

<=

d)

=<>

20.

Which of the following relational operators evaluates to true if the two compared expressions are not equal?

a)

==

b)

<=

c)

!=

d)

>

21.

Which statement about the if-else structure is true?

a)

The else block can exist without an if block.

b)

An if block can execute multiple else blocks for a single condition.

c)

The else block is executed only if the if condition evaluates to false.

d)

The if condition can only test for equality.

22.

Which of the following is the correct format of a "for" loop?

a)

for(int i = 0; i < 10; i++);

b)

for[int i = 0; i < 10; i++];

c)

for(int i = 0; i < 10; i++)

d)

for[int i = 0; i < 10; i++]

23.

Which for loop will not work?

a)

for (i=0; i<5; i++)

b)

for (i=5; i<=10; i++)

c)

for (i=5; i=10; i++)

d)

for (i=5; i<100; i++)

24.

The statement i++; is equivalent to ______.

a)

i = i + i;

b)

i = i + 1;

c)

i = i - 1;

d)

i--;

25.

What output is produced by the following segment of code:


for(int i = 0; i < 10; i++)

cout << i << " ";

a)

0 1 2 3 4 5 6 7 8 9 10

b)

0 1 2 3 4 5 6 7 8 9

c)

1 2 3 4 5 6 7 8 9 10

d)

1 2 3 4 5 6 7 8 9

e)

Infinite Loop

26.

What output is produced by the following segment of code:


for (int x = 10; x > 0; x++)

cout << x << " ";

a)

10 9 8 7 6 5 4 3 2 1

b)

10 9 8 7 6 5 4 3 2 1 0

c)

9 8 7 6 5 4 3 2 1

d)

No Output

e)

Infinite Loop

27.

Make this code loop three times:


in tries= 0;


while(_________ ) {

cin>> “Looping!”;

tries++;


}

a)

tries < 3

b)

answer == 3

c)

tries > 0

d)

tries < 0

28.

5<=5 evaluates to

a)

true

b)

false

29.

Select the assignment operator

a)

==

b)

===

c)

=

d)

!=

30.

The shape used to indicate a decision is to be made.

a)

Circle

b)

Diamond

c)

Oval

31.

Is it important for a programmer to plan the logic of his program?

a)

Yes

b)

No

32.

It is used to compare two expressions and return true or false. The most common are > (greater than), < (less than), >= (greater than or equal to), <= (less than or equal to), == (equal to), != (not equal to).

a)

Arithmetic Operator

b)

Assignment Operator

c)

Relational Operator

d)

Logical Operator

33.

results in "true" if the value is false, and vice versa. It effectively inverts the value. True becomes false and false becomes true. Overlaps with || but not with &&

a)

Or (||)

b)

Not (!)

c)

And (&&)

d)

Boolean

34.

results in "true" only if two statements are both true; otherwise, the operator results in false. In coding, the two statements are called "operands"

a)

And (&&)

b)

Nor (!)

c)

Or (||)

d)

is Equal to (==)

35.

int x=3, y=5;

bool result;

result = x > y;

The condition is?

a)

TRUE

b)

FALSE

36.

int x=3, y=5;

bool result;

result = (x != y);

The condition is?

a)

TRUE

b)

FALSE

37.

Suppose,

n = 5 m = 8

Then,

(n > 3) && (m > 5) evaluates to

a)

TRUE

b)

FALSE

38.

Suppose,

n = 5 m = 8

Then,

!(n < 3) evaluates to

a)

TRUE

b)

FALSE

39.

Which of the following is a correct way to write an if statement in C++?

a)

if (x = 5) { ... }

b)

if x = 5 { ... }

c)

if (x == 5) { ... }

d)

if x == 5 { ... }

40.

What is the purpose of the else clause in an if statement?

a)

To execute a block of code if the condition in the if statement is true

b)

To execute a block of code if the condition in the if statement is false

c)

To repeat a block of code a specific number of times

d)

To exit a loop based on a certain condition