wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

IT112 Midterm

Total questions: 100

Worksheet time: 2hrs 34mins

Name
Class
Date
1.

This is a code that has not yet been linked into a complete program.

a)

Source Code

b)

Assembly Code

c)

Object Code

d)

Machine Code

2.

The object code is produced in what program development phase?

a)

Preprocessing

b)

Compilation

c)

Linking

d)

Loading

e)

Executing

3.

In what phase the c++'s executable program is produced?

a)

Preprocessing

b)

Compilation

c)

Linking

d)

Loading

e)

Executing

4.

By default, how are instructions executed by the CPU?

a)

One instruction a a time

b)

Several Instructions at a time

c)

All instructions in one time

d)

None of the above

5.

Single line comments are denoted by what symbol?

a)

//

b)

\\

c)

/*

d)

*/

6.

Which of the following are ignored by the C++ compiler and the computer? Check all that applies.

a)

Comments

b)

Blank lines

c)

Spaces

d)

Tab Spaces

e)

Preprocessing directives

7.

A preprocessing directive starts with what symbol?

a)

//

b)

#

c)

(

d)

{

8.

The library defined in the preprocessor directive must be enclosed by what symbols?

a)

{ }

b)

[ ]

c)

< >

d)

( )

9.

Blanks lines, spaces, and tab characters are called?

a)

Keywords

b)

White spaces

c)

Symbols

d)

Escape Sequences

10.

A code that is reserved by C++ for a specific use.

a)

Keyword

b)

White space

c)

Symbol

d)

Escape Sequence

11.

Which symbol starts a block of code?

a)

<

b)

(

c)

{

d)

[

12.

Which symbol is used to determine that a code/keyword is a function?

a)

<

b)

(

c)

{

d)

[

13.

The words enclosed in double quotation marks are known as the following EXCEPT what?

a)

String

b)

Character String

c)

String Literal

d)

Stream

14.

The semicolon (;) is used to?

a)

Start a block of code

b)

Terminate a function

c)

Start a statement

d)

End a statement

15.

Which of the following is the escape character operator?

a)

<<

b)

>>

c)

::

d)

\

16.

Which of the following is the stream insertion operator?

a)

<<

b)

>>

c)

::

d)

\

17.

Which of the following is the stream extraction operator?

a)

<<

b)

>>

c)

::

d)

\

18.

A location in the computer's memory where a value can be stored for use by a program. Note: Answer must be in UPPERCASE letters.

(a)  

19.

Which of the following is the input stream object?

a)

>>

b)

<<

c)

cin

d)

cout

20.

Which of the following is NOT a VALID identifier?

a)

X1

b)

_X1

c)

x1

d)

_1x

e)

1x

21.

Which of the following are VALID identifiers?

a)

int

b)

include

c)

return

d)

zero

22.

All variables must be declared before they are used.

a)

True

b)

False

23.
The process of creating a new variable without value
a)
declaration
b)
naming
c)
instantiation
d)
assigning
24.

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

a)

start()

b)

system()

c)

main()

d)

program()

25.

Which of the following is a correct comment?

a)

*/ Comments */

b)

** Comment **

c)

/* Comment */

d)

{ Comment }

26.
Which command moves the shown text to the next line?
a)
\t
b)
\n
c)
\r
d)
\s
27.
A programmer is:
a)
person who writes code and communicates instructions to a computer
b)
person who types
c)
person who studies computers
d)
error or mistake in your code
28.
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
29.
... variables store whole numbers (-4, 3, 51, etc). 
a)
Float
b)
Logical
c)
Character
d)
Integer
30.
... point variables store decimal numbers (3.5, -5,123, 4.0, etc). 
a)
Float
b)
Integer
c)
Logical
d)
Character
31.

Which of the following is NOT a logical operator in C++ language?

a)

&

b)

&&

c)

||

d)

!

32.

Which of the following is NOT a comparison operator in C++ language?

a)

>

b)

<=

c)

=

d)

==

33.

Evaluate the following expressions to true or false


3!=4-1

a)

true

b)

False

34.

Evaluate the following expressions to true or false


5 >= (1+6)-4

a)

True

b)

False

35.

Evaluate the following expressions to true or false

5+1==6 || 8-1>4

a)

True

b)

False

36.

If originally x=2,y=0, and z=1, what is the value of x, y, and z after executing the following code?


if (x>y)


y=x;

else

z=x;

a)

x=2 y=2 z=1

b)

x=0 y=2 z=0

c)

x=2 y=1 z=1

d)

x=2 y=0 z=1

37.

Which of these operators increments an integer variable by one?

a)

" * "

b)

" - - "

c)

" + + "

d)

>

38.

Which of these operators gets the remainder of dividing two numbers?

a)

#

b)

&

c)

%

d)

==

39.

Fill in the blank to get 1 outputted from this code:


int main() {


int a = 2;

int b = 13;


cout<< b _ a <<endl;


}

(a)  

40.

True or False. This code will output 0


cout<< 23 % 2 <<endl;

a)

True

b)

False

41.

True or False. This code will output 1


cout<< 55 % 2 <<endl;

a)

True

b)

False

42.

Fill in the blank to get 0 outputted from this code:


int main() {


cout<< 12 ___ 12 <<endl;


}

a)

-

b)

+

c)

==

d)

%

43.

Fill in the blank to get 0 outputted from this code:


int main() {


cout<< 12 ___ 3 <<endl;


}

a)

-

b)

+

c)

==

d)

%

44.

Fill in the blank to get 0 outputted from this code:


int main() {


cout<< 0 ___ 3 <<endl;


}

a)

-

b)

/

c)

==

d)

+

45.

Fill in the blank to get 1 outputted from this code:


int main() {


cout<< 9 % (a)   <<endl;


}

46.

Fill in the blank to get 2 outputted from this code:


int main() {


cout<< 5 % (a)   <<endl;


}

47.

Fill in the blank to get 3 outputted from this code:


int main() {


cout<< 15 % (a)   <<endl;


}

48.

Fill in the blank to get 3 outputted from this code:


int main() {


cout<< 19 ____ 4 <<endl;


}

a)

%

b)

==

c)

+

d)

&&

49.

What does this unary operator mean? : ++

a)

It is the increment operator, usage: x++ , output if x=10: 11

b)

It is the decrement operator, usage x--, output if x=10: 9

c)

It is the logical 'Not' operator, usage !(x), output if x=10: True

50.

What does this unary operator mean? --

a)

It is the decrement operator, usage: X--, output if x=10 : 9

b)

It is the increment operator, usage: x++, output if x=10 : 11

c)

It is the logical 'Not' operator, usage: !(X), output if x=10: True

51.

How many loops are there in C++

a)

2

b)

3

c)

4

d)

1

52.

What is currect syntax of for loop?

a)

for(initialization;condition; increment/decrement)

b)

for(increment/decrement; initialization; condition)

c)

for(initialization, condition, increment/decrement

d)

None of These

53.

Can a for loop contain another for loop?

a)

No

b)

Yes

c)

Compilation Error

d)

Runtime Error

54.

Each pass through a loop is called a/an

a)

pass through

b)

enumeration

c)

iteration

d)

culmination

55.

Which looping process checks the test condition at the end of the loop?

a)

for

b)

while

c)

do-while

d)

no looping process checks the test condition at the end

56.

In a group of nested loops, which loop is executed the most number of times?

a)

the outermost loop

b)

the innermost loop

c)

all loops are executed the same number of times

d)

cannot be determined without knowing the size of the loops

57.

The statement i++; is equivalent to

a)

i = i + i;

b)

i = i + 1;

c)

i = i - 1;

d)

i --;

58.

Which looping process is best used when the number of iterations is known?

a)

for

b)

while

c)

do-while

d)

all looping processes require that the iterations be known

59.

What's wrong? for (int k = 2, k <=12, k++)

a)

the increment should always be ++k

b)

the variable must always be the letter i when using a for loop

c)

there should be a semicolon at the end of the statement

d)

the commas should be semicolons

60.

If there is more than one statement in the block of a for loop, which of the following must be placed at the beginning and the ending of the loop block?

a)

parentheses ( )

b)

braces { }

c)

brackets [ ]

d)

arrows < >

61.

What output is produced by the following segment of code:


for(int fun = 20; fun > 1; fun -=3)

cout << fun << " ";

a)

20 17 14 11 8 5 2 -1

b)

20 17 14 11 8 5 2

c)

17 14 11 8 5 2 -1

d)

20 17 14 11 8 5

e)

Infinite Loop

62.

What output is produced by the following segment of code:


for(int i = 1; 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

63.

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

64.

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

65.

What output is produced by the following segment of code:


int start = 5;

int end = 20;

for(; start <= end; start +=2)

cout << start << " ";

a)

5 7 9 11 13 15 17 19 21

b)

7 9 11 13 15 17 19 20

c)

7 9 11 13 15 17 19 21

d)

5 7 9 11 13 15 17 19

e)

Infinite Loop

66.

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

67.

What output is produced by the following segment of code:


for (int dmc = 8; dmc >= 10; dmc-=4)

cout << * << " ";

a)

* * *

b)

* *

c)

*

d)

No Output

e)

Infinite Loop

68.

What output is produced by the following segment of code:


for (int dmc = 8; dmc >= 8; dmc-=4)

cout << dmc << " ";

a)

8 4 0

b)

8 4

c)

8

d)

No Output

e)

Infinite Loop

69.

What output is produced by the following segment of code:


for (int dmc = 8; dmc >= 0; dmc-=4)

cout << dmc << " ";

a)

8 4 0

b)

8 4

c)

8

d)

No Output

e)

Infinite Loop

70.

What output is produced by the following segment of code:


for (int x = 5; x > 0; x--);

cout << * << " ";

a)

* * * * *

b)

* * * * * *

c)

*

d)

No Output

e)

Infinite Loop

71.

The statements in the body of a while loop may never be executed while the statements in the body of a do-while loop will be executed

a)

at least once

b)

at least twice

c)

never

d)

as many times as the user wishes

72.

A for statement contains three expressions: initialization, condition, and

a)

reversal

b)

update

c)

null

d)

validation

73.

If you want a user to enter exactly 20 values, which loop would be the best to use?

a)

while

b)

switch

c)

do-while

d)

for

74.

How many times will the above loop display "Hello world!"?

a)

19

b)

20

c)

21

d)

an infinite number of times

75.

A file must be __________ before data can be written to or read from it.

a)

opened

b)

closed

c)

named

d)

buffered

76.

To allow file access in a program, you must use __________ in the header file.

a)

#include <file>

b)

#include <fileaccess>

c)

#include <fstream>

d)

#include <cfile>

77.

Assuming outFile is a file stream object and number is a variable, which statement writes the contents of number to the file associated with outFile?

a)

write(outFile, number);

b)

outFile >> number;

c)

number >> outFile;

d)

outFile << number;

78.

What is the output of the above program?

a)

0 1 2 3 4

b)

0 1 2 3

c)

0 1 2

d)

0 1

79.

What is the output of the above program?

a)

0 1 2 3 4

b)

0 1 2 3

c)

0 1 2 4

d)

0 1 2

80.

These are operators that add and subtract one from their operands.

a)

plus and minus

b)

++ and --

c)

binary and unary

d)

conditional and relational

81.

Which of the following is not a fundamental type is not present in C but present in C++?

a)

int

b)

void

c)

bool

d)

char

82.

What is the size of a boolean variable in C++?

a)

1 bit

b)

2bit

c)

1byte

d)

2byte

83.

Which of the following is an entry-controlled loop?

a)

for

b)

none

c)

do-while

d)

all of above

84.

Which of the following is an exit-controlled loop?

a)

for

b)

while

c)

do-while

d)

all of above

85.

What is the final value of x in the following code segment?


int x = 7;

x += 2*x;

a)

63

b)

21

c)

81

d)

This code segment will not compile.

86.

What is the final value of y in the following code segment?


int y = 3 * 7 % 8 + 1 * 4;

a)

9

b)

24

c)

25

d)

6

e)

This code segment will not compile.

87.

What is the final value of x in the following code segment?

int x = 7/2;

a)

3 1/2

b)

3.5

c)

3.0

d)

This code segment will not compile.

88.

What is the final value of w in the following code segment?


int w = int(3 / 2) + 5 % 10 - 3.5;

a)

-2

b)

3

c)

-3

d)

2

e)

This code segment will not compile.

89.

What is the final value of x in the following code segment?

(Assume the header file <cmath> has been included.)


double x = pow(2, 3) + 1 / 2;

a)

9.5

b)

8.5

c)

8.0

d)

9.0

e)

This code segment will not compile.

90.

What is the final value of x in the following code segment?

(Assume the header file <cmath> has been included.)


double x = 15 / sqrt(4.0) - 10 % 3;

a)

6.5

b)

6.0

c)

0.0

d)

-0.5

e)

This code segment will not compile.

91.

Which of these variables can only contain a single letter?

a)

char symbol;

b)

string word;

c)

int num;

d)

double num;

92.

Which of these variables can contain decimal numbers?

a)

int apples;

b)

double apples;

c)

char apples;

d)

void apples;

93.

How can we store a user input to the variable

int apples; ?

a)

cin << int apples;

b)

cin >> apples;

c)

cin;

94.

What kind of data type is this value?


9.45

a)

float

b)

integer

c)

character

d)

string

95.

What data type is this value?


'R'

a)

integer

b)

float

c)

character

d)

string

96.

For the following code, what is the name of the variable?


int game = 2;

a)

int

b)

integer

c)

game

d)

2

97.

For the following code, what is the data type?


float boat = 3.4;

a)

float

b)

boat

c)

decimal

d)

3.4

98.

What is the output for this code?


int x = 3;

int y = 6;

cout << x + y;

a)

9

b)

18

c)

6

d)

3

99.

What is the output of this code?


int x = 4;

x = 5;

cout << x;

a)

4

b)

5

c)

20

d)

9

100.

What is the output of this code?


int y = 4;

y = y / 2;

cout << y + 1;

a)

3

b)

2

c)

9

d)

8