Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C++ Quiz

Total questions: 50

Worksheet time: 37mins

Name
Class
Date
1.

Suppose x is 5 and y is 7. Choose the value of the following expression:


(x != 7) && (x <= y)

a)

false

b)

1

c)

0

d)

null

2.

Suppose that x is an int variable. Which of the following expressions always evaluates to true?

a)

(x > 0) || ( x <= 0)

b)

(x >= 0) || (x == 0)

c)

(x > 0) && ( x <= 0)

d)

(x > 0) && (x == 0)

3.

Which of the following expressions correctly determines that x is greater than 10 and less than 20?

a)

10 < x < 20

b)

(10 < x < 20)

c)

10 < x && x < 20

d)

10 < x || x < 20

4.

The expression in an if statement is sometimes called a(n) ____.

a)

selection statement

b)

action statement

c)

decision maker

d)

action maker

5.

What is the output of the following C++ code?

int x = 35;

int y = 45;

int z;


if (x > y)

z = x + y;

else

z = y – x;


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

a)

35 45 80

b)

35 45 10

c)

35 45 –10

d)

35 45 0

6.

When one control statement is located within another, it is said to be ____.

a)

blocked

b)

compound

c)

nested

d)

closed

7.

Which of the following will cause a logical error if you are attempting to compare x to 5?

a)

if (x == 5)

b)

if (x = 5)

c)

if (x <= 5)

d)

if (x >= 5)

8.

Assume you have three int variables: x = 2, y = 6, and z.

Choose the value of z in the following expression: z = (y / x > 0) ? x : y;.

a)

2

b)

3

c)

4

d)

6

9.

What is the value of x after the following statements execute?

int x;

x = (5 <= 3 && 'A' < 'F') ? 3 : 4

a)

2

b)

3

c)

4

d)

5

10.

Which of the following refers to a temporary storage that can be assigned a value within a program?

a)

value

b)

data type

c)

function

d)

variable

11.

In C++ programming, which type of controlling position performs new line command?

a)

elnd

b)

end

c)

endl

d)

end()

12.

What is the output of the given value expression?

float n = 4.6, x=11.33,y;

y=n+x;

cout << y;

a)

15.93

b)

15.10

c)

15.0

d)

15

13.

Which of the following reads the entire program and converts it into object code?

a)

editor

b)

compiler

c)

interpreter

d)

debugger

14.

In C++, which of the following defines the routines for standard input and output, such as cout and cin?

a)

#include<conio.h>

b)

#include<math.h>

c)

#include<stdio.h>

d)

#include<iostream>

15.

Which symbol is used when storing a character in a variable?

a)

" "

b)

' '

c)

;

d)

:

16.

what does this shape represent in a flowchart?

a)

input/output

b)

process

c)

decision

d)

flowlines

17.

What is the name of this symbol in a flowchart?

a)

flowlines

b)

input/output

c)

decision

d)

process

18.

what flowcharting symbol should the equation below be placed?

a = num%2

a)
b)
c)
d)
19.

He is the developer of c programming

a)

bjarne stroustrup

b)

dennis ritchie

c)

ken thompson

d)

brian kernighan

20.

He is the developer of C++ programming language

a)

bjarne stroustrup

b)

ken thompson

c)

dennis ritchie

d)

brian kernighan

21.

which of the following is the format specifier for char items [100] when you want to display/output it?

a)

%c

b)

%s

c)

%i

d)

%f

22.

which of the following data types that specifies no value is returned/available?

a)

integer

b)

void

c)

boolean

d)

float

23.

what is the function used in c programming that displays the output on the terminal window.

a)

printf

b)

cout

c)

cin

d)

scanf

24.

It is a function in c++ programming used to display the output on the terminal window.

a)

cin

b)

cout

c)

printf

d)

scanf

25.

It is a data type that can contain data with decimal numbers.

a)

integer

b)

char

c)

float

d)

boolean

26.

It is also called a procedure or a function that is used to perform a certain task

a)

flowchart

b)

algorithm

c)

pseudocode

d)

data flow diagram

27.

what is the output of this equation,10 + 23/2%2+100 -25

a)

86

b)

15

c)

75

d)

81

28.

give the output of 6 * (2 / 15% 3) + 354 -125

a)

-125

b)

175

c)

-176

d)

229

29.

What is the value of X in the sample code given below?

X = ( 2 + 3) * 2 + 3;

a)

10

b)

13

c)

25

d)

28

30.

What value will be stored in z if the following code is executed?

x = 5 , y = -10, a = 4, b = 2;

z = x+++++y * b/a;

a)

-2

b)

2

c)

1

d)

0

31.

Evaluate the following expressions to true or false


5 >= (1+6)-4

a)

true

b)

false

32.

Which operators are used to compare the values of operands to produce logical value in C language

a)

mathematical

b)

logical

c)

relational

d)

assignment

33.

Determine if the statement below is correct:

double x, y;

cout <<"Enter a number: ";

cin>>y;

x=y+1;

cout<<"\nDisplay Input plus 1....";

a)

true

b)

false

34.

Determine if the statement below is correct:

char let1 = 't';

char let2 = 'i';

char let3 = 'p';

cout<<let1, let2, let3;

a)

true

b)

false

35.

Determine if the statement below is correct:

int x;

cout<<“Enter a number: ”; cin>>x;

a)

true

b)

false

36.

Determine the variable below whether it is valid or not:

NAME

a)

valid

b)

invalid

37.

Determine the variable below whether it is valid or not:

sumof3Numbers

a)

valid

b)

invalid

38.

Determine the variable below whether it is valid or not:

aver@ge

a)

valid

b)

invalid

39.

Determine the variable below whether it is valid or not:

first name

a)

valid

b)

invalid

40.

Determine the variable below whether it is valid or not:

Char34

a)

valid

b)

invalid

41.

Determine the variable below whether it is valid or not:

int

a)

valid

b)

invalid

42.

What is the output of the following program segment if the entered value for num = 1234?

main(){ int num, w,x,y,z;

scanf(“%d”,&num);

w = num % 10;

x = (num / 10) % 10;

y = (num/100) % 10;

z = num / 1000;

printf(“%d %d %d %d”, w,x,y,z); }

a)

1234

b)

1243

c)

4321

d)

4312

43.

What part of your c program structure we prepare variables before using them inside the program?

a)

main

b)

declaration

c)

output

d)

conditional expression

44.

Which type of controlling position that performs new line command?

a)

//n

b)

/n

c)

\n

d)

\*n

45.

Which of the following literal may be in the form of a series of characters?

a)

character

b)

string

c)

boolean

d)

integer

46.

What is the output of the code below:

mickey = mouse;

if (mickey == mouse)

cout << ("Mickey is a mouse");

else

cout << ("Minnie rules");

a)

Mickey is a mouse

b)

Nothing prints.

c)

Minnie rules

d)

Mickey is a mouse" & "Minnie rules

47.

What is the output of the code below:

john = 5;

if (john > 6)

cout << ("John is getting ice cream");

else

cout << ("John is getting apple juice");

cout << "John is getting grapes")

a)

John is getting ice cream

b)

John is getting apple juice

John is getting grapes

c)

John is getting apple juice

d)

John is getting ice cream

48.

Equivalent of switch statement

a)

if

b)

else if ladder

c)

if else

d)

while

49.

What is the output of the code below:

number_of_coins = 10 .

if (number_of_coins == 6)

cout << "You can buy some gum";

else

if (number_of_coins == 10)

cout << "You are rich";

else

cout << "Get a job!";

a)

You can buy some gum

b)

You are rich

c)

Get a job!

d)

You are rich

Get a job!

50.

Which of the following is a correct comment?

a)

*/ Comments */

b)

/* Comment */

c)

** Comment **

d)

{ Comment }