wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C++ Programming

Total questions: 20

Worksheet time: 15mins

Name
Class
Date
1.

Directives are translated by the

a)

Pre-processor

b)

Compiler

c)

Linker

d)

Editor

2.

What will the result of 'num' variable after execution of the following statements?

int num = 58;

num % = 11;

a)

3

b)

5

c)

8

d)

11

3.

What will the result of num1 variable after execution of the following statements?

int j = 1, num1 = 4;

while (++j <= 10)

{

num1++;

}

a)

11

b)

12

c)

13

d)

14

4.

Give the following declarations and an assignment statement. Which one is equivalent to the expression str [4]?

char str[80];

char * p;

p = str;

a)

p + 4

b)

*p + 4

c)

*(p + 4)

d)

p[3]

5.

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

6.

True/False: For Loops can never be an infinite loop.

a)

True

b)

False

7.

How many times will the shown for loop execute?

a)

0

b)

9

c)

10

d)

11

8.

What does <= mean?

a)

less than

b)

greater than

c)

less than or equal to

d)

greater than or equal to

9.

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

a)

cout()

b)

system()

c)

main()

d)

program()

10.

What punctuation is used to signal the beginning and end of code blocks?

a)

{ }

b)

//

c)

BEGIN and END

d)

/* */

11.

Which of the following is a correct comment?

a)

*/ Comments */

b)

** Comment **

c)

/* Comment */

d)

{ Comment }

12.

Which command moves the shown text to the next line?

a)

\t

b)

\n

c)

\r

d)

/n

13.

After running the following code, what will be the value of x?

y = 3;

x = 5 * (++y);

a)

15

b)

5

c)

15

d)

20

14.

Do while loops

a)

Runs a statement once

b)

Runs a statement twice

c)

Runs a statement multiple times or not within a boolean condition

d)

Doesn't run at all

15.

Switch Statement

a)

Is a statement with a set of conditions called cases

b)

Is a case

c)

Is a condition with no cases

d)

Is a boolean statement

16.

Voids

a)

A statement that returns a value

b)

A statement that doesn't return a value

c)

A function that return a value

d)

A function that doesn't return a value

17.

iostream

a)

Displays output from the screen and input from the keyboard

b)

Has all the math equations

c)

Counts the time

d)

Checks if the code has a function

18.

Cpp Compiler converts source code in

a)

.cpp file

b)

.obj file

c)

.exe file

d)

.lnk file

19.

In a class the access specifiers are _______ by default:

a)

Private

b)

Protected

c)

Public

20.

What is the difference when allocating the following memory?

int array1[15];

int array2[3][5];

a)

array1 is larger

b)

array2 is larger

c)

The size allocated is the same