wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Programming Quiz

Total questions: 19

Worksheet time: 10mins

Name
Class
Date
1.

What will be the output of the program?

a)

Numbers read from file: 12345

b)

Numbers read from file: 0

c)

Unable to open file

d)

Numbers read from file: 1 2 3 4 5

2.

What is the difference between array and structure?

a)

No difference

b)

Structure can include members of different data types

c)

Arrays can include only integers

3.

Observe function declaration and choose the best answer: int divide(int a, int b = 2)

a)

Variable b is international scope and will have value 2

b)

Variable b is of integer type and will always have value 2

c)

Variable a and b are of int type and initial value of both is 2

d)

Variable b will have value 2 if not specified when calling function

4.

Which of the following accesses a variable in structure b?

a)

b=var;

b)

b->var;

c)

b.var;

5.

Which of the following properly declares a variable var of structure foo?

a)

var foo struct;

b)

foo var;

c)

instruct foo;

d)

Struct foo;

6.

How do you create an object of a structure?

a)

Person person1 = {“Alice”, 30};

b)

Person person1 = new Person();

c)

Person* person1;

d)

Person person1;

7.

In an assignment statement a = b; which statement is true?

a)

Changes in b affect a

b)

Value of a is assigned to b

c)

Value of b is assigned to a, later changes in b do not affect a

d)

Variables are always equal

8.

Which stream class is used to both read and write on files?

a)

ifstream

b)

iostream

c)

ofstream

d)

fstream

9.

How many elements does this array have: int arraytwo[2][2];

a)

2

b)

1

c)

4

d)

8

10.

The data elements in structure are also known as what?

a)

Members

b)

Data

c)

None of the above

d)

Objects

11.

Which operator is used to compare two variables?

a)

+=

b)

&&

c)

==

d)

||

12.

Write correct function prototype: Function takes integer argument number and returns double.

a)

int intToDouble(number);

b)

double intToDouble(int number);

c)

float intToDouble(int number);

d)

double intToDouble(double number);

13.

Body of factorial function:

a)

n! = n*(n+1)!

b)

n! = n-(n-1)!

c)

n! = n/(n-1)!

d)

if(n>1) return n*factorial(n-1); else return 1;

14.

What will be the output of the code (recursive array sum)?

a)

15

b)

10

c)

5

d)

20

15.

This statement breaks one iteration in the loop:

a)

break

b)

continue

c)

&&

16.

Why do we need fstream class?

a)

Mathematical functions

b)

To work with files

c)

To work with strings

17.

We declare a function with _____ if it does not have return type.

a)

void

b)

float

c)

int

d)

bool

e)

double

18.

What is a recursive function?

a)

Runs indefinitely

b)

Cannot return value

c)

Calls itself

d)

Calls other functions

19.

A function that calls itself for processing is known as:

a)

Recursive function

b)

Inline function

c)

Overloaded function

d)

Nested function