wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

The Ultimate C++ Quiz

Total questions: 7

Worksheet time: 4mins

Name
Class
Date
1.

What will print out?

int x, y;

x = y;

x = 1;

if (x>y)

{

y = x;

y = 1;

} else

{

x = 2;

}

cout<<x<<endl<<y;

a)

1

2

b)

0

2

c)

1

0

d)

2

1

2.

What will print out?

int x, y;

x = 1;

if (x == 0)

{

x = 0;

y = 1;

} else

{

y = x*x;

}

cout<<y;

a)

1

b)

2

c)

3

d)

4

3.

What will print out?

int x, y, z;

x = 1;

y = 5;

z = x+y-1;

while (true)

{

if (x<z)

{

x = z;

z = x;

y = x;

x = y;

break;

} else

{

x = 1;

y = x;

z = y;

}

}

cout<<x<<endl<<y<<endl<<z;

a)

1

5

5

b)

5

5

5

c)

1

6

6

d)

1

1

1

4.

What will print out?

for(int x=-3;x<=0;x++)

{

cout<<x-1<<endl;

}

a)

-3

-2

-1

0

b)

-4

-3

-2

-1

0

c)

-4

-3

-2

-1

d)

-2

-1

0

5.

What will print out?

bool a = true;

while (a == true)

{

cout<<"Hello World!";

a = false;

}

a)

Hello World!

b)

Nothing will be printed out on the screen

6.

What will print out?

bool a = true;

while (a == true)

{

a = false;

cout<<"Hello World!";

}

a)

Hello World!

b)

Nothing will be printed out on the screen

7.

What will print out?

while (true)

{

break;

cout<<"Hello World!";

}

a)

Hello World!

b)

Nothing will be printed out on the screen