Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C Programming Quiz

Total questions: 33

Worksheet time: 19mins

Name
Class
Date
1.

What is the return type of the function with prototype float func(char x, float v, double t);

a)

double

b)

char

c)

string

d)

int

e)

float

2.

Which of the following accesses a variable in structure b?

a)

b.var;

b)

b=var;

c)

b->var;

3.

How many times the current loop will execute? for (int i = 0; i <= 5; i += 3);

a)

1 time

b)

5 times

c)

2 times

d)

3 times

e)

4 times

4.

What is the correct value to return to the operating system upon successful completion of a program?

a)

10

b)

-1

c)

20

d)

0

e)

1

5.

Which of the following gives the value stored at the address pointed to by the pointer gala?

a)

*gala

b)

gala[0]

c)

&gala

d)

gala

6.

When following code is executed, what value will be in variable b? b = 5; a = b++;

a)

5

b)

4

c)

0

d)

6

e)

3

7.

Write correct function prototype for the function intToDouble that takes an integer argument number and returns a double.

a)

int intToDouble(number);

b)

double intToDouble(double number);

c)

float intToDouble(int number);

d)

double intToDouble(int number);

8.

Pointers may be compared by using relational operators.

a)

False

b)

True

9.

By default, all the files are opened in _____ mode.

a)

binary

b)

text

10.

When following code is executed, what value will be in variable a? b = 5; a = b++;

a)

5

b)

1

c)

0

d)

7

e)

6

11.

What will be used when terminating a structure?

a)

Semicolon

b)

Dot

c)

Colon

d)

Brackets

12.

How many times the current loop will execute? for (int i = 0; i <= 5; i += 3);

a)

5 times

b)

1 time

c)

2 times

d)

4 times

e)

3 times

13.

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

14.

Write correct function prototype for the function intToDouble that takes an integer argument number and returns a double.

a)

double intToDouble(double number);

b)

float intToDouble(int number);

c)

int intToDouble(number);

d)

double intToDouble(int number);

15.

What is the correct value to return to the operating system upon successful completion of a program?

a)

20

b)

1

c)

0

d)

10

e)

-1

16.

Which of the following is a complete function?

a)

funct(int x)

b)

funct;

c)

funct();

d)

int funct(int x) { return x = x + 1; }

17.

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

a)

int

b)

char

c)

float

d)

void

18.

Which of the following is the proper declaration of a pointer x?

a)

int &x;

b)

int x;

c)

int *x;

d)

ptr x;

19.

Choose the right option: string* x; string y;

a)

both x and y are pointer to string types

b)

x is a pointer to a string, y is a string

c)

y is a pointer to a string, x is a string

20.

Write a statement to initialize an array with values 1,2,3,4,5

a)

int myArray[]={1,2,3,4,5};

b)

int myArray[5]=1,2,3,4,5;

c)

int myArray(1,2,3,4,5);

d)

int myArray[]={1,2,3,4,5}

21.

This loop executes the code block once before checking condition.

a)

for

b)

while

c)

do while

22.

Difference between while and do-while loop:

a)

while checks condition before loop, do-while after

b)

do checks condition before first iteration

23.

In C++, this statement terminates the loop when encountered.

a)

&&

b)

continue

c)

break

24.

(3<5) || (7>8)

a)

true

b)

false

25.

How do you open a file for writing in C++?

a)

ifstream file("filename.txt");

b)

file.open("filename.txt");

c)

fstream file("filename.txt");

d)

ofstream file("filename.txt");

26.

What happens if you write to a file opened in read mode?

a)

creates new file

b)

overwrites file

c)

throws an error

d)

writes without issues

27.

What is an array?

a)

same type, non-contiguous

b)

series of elements

c)

none

d)

same type, contiguous memory

28.

Evaluate !(1 && !(0 || 1))

a)

true

b)

false

29.

How many times loop executes? for(int i=1;i<=4;i+=3);

a)

1

b)

2

c)

4

d)

0

e)

3

30.

The set of instructions a computer follows is called:

a)

program

b)

memory

c)

type

d)

line

e)

variable

31.

Correct operator to compare two variables:

a)

==

b)

+=

c)

&&

d)

||

e)

Equal

32.

Evaluate !(1 && !(0 || 1))

a)

false

b)

true

33.

Difference between while and do-while:

4 lines