wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

D-Bug (C++)

Total questions: 15

Worksheet time: 45mins

Name
Class
Date
1.

What will be the output of the following C++ code?

a)

50

b)

0

c)

Division by zero condition

d)

 Error

2.

What will be the output of the following C++ code?

a)

20

b)

An exception occurred

c)

Error

d)

An exception occurred 20

3.

What will be the result of the following code snippet?

a)

1 2 3 4 5 6 . . . . .100

b)

1 1 1 1 . . . . . infinite times

c)

1 0 -1 -2 -3 . . . . .  till negative infinity

d)

None of these

4.

For which  values of variable tnum will the following code become an infinite loop?

a)

Only 0

b)

Only 1

c)

Only 1 or 2

d)

Any number other than 1 or 2

5.

What is wrong with the code?

a)

No error

b)

Compilation Error

c)

Logical error

d)

Runtime Error

6.

Which concept is missing or not used in the below C++ script?

a)

Polymorphism

b)

Encapsulation

c)

Inheritance

d)

Abstraction

7.

Find out the error.

a)

`func` should contain data members

b)

Function print(); should be predefined

c)

Both are correct

d)

None of these

8.

What happens when we try to compile the class definition in following code snippet?

a)

It will not compile because a class cannot be protectedly inherited from other class

b)

It will not compile because class body of Eagle is not defined

c)

It will not compile because class body of Birds is not defined

d)

It will compile successfully

9.

Which of the following function declarations is/are incorrect?

a)

int Sum(int a = 0, int b, int c = 3);

b)

int Sum(int a = 5, int b);

c)

Both are correct

d)

Both are incorrect

10.

What happens if the following program is executed in C and C++?

a)

Runs successfully  in C, error in C++

b)

Error in C, runs successfully in C++

c)

Error in both C and C++

d)

Runs successfully in both C and C++

11.

What will be the output of the following C++ function?

a)

1

b)

0

c)

Runtime error

d)

Compilation error

12.

The following program fragment:

int *a;

*a=7;

a)

Assigns 7 to a

b)

Results in compilation error

c)

Logical error

d)

Segmentation fault

13.

What will be the output/error of the following code?

a)

5

b)

Run-time error

c)

Compilation error

d)

Segmentation Fault

14.

What is wrong in the following line?

for(int k=0,k<=10,k++)

a)

The increment should always be ++k

b)

The commas should be semicolons

c)

There should be a semicolon at the end of the statement

d)

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

15.

What is wrong in the following line?

(x=4 && y=5) ? (a=5) : (b=6);

a)

The question mark should be an equal sign

b)

There are too many variables in the statement

c)

Relational operator must be used instead of assignment operator

d)

No error