wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

OODP_Batch 1_Quiz

Total questions: 30

Worksheet time: 15mins

Name
Class
Date
1.

Guess the output of the following code:

a)

2.500000

b)

2.000000

c)

2

d)

Compilation Error

2.

How many times will the loop execute?

a)

4

b)

5

c)

6

d)

Infinite times

3.

What is the correct way to declare an integer pointer is

a)

int ptr;

b)

int *ptr;

c)

ptr *int;

d)

int &ptr;

4.

Find the value of x in this code:

a)

10

b)

15

c)

20

d)

40

5.

This function returns ---------

a)

Fibonacci sequence

b)

Factorial of n

c)

Sum of first n numbers

d)

Power of n

6.

Output of the following code is:

a)

True

b)

False

c)

Error

d)

Undefined behaviour

7.

What will be the output?

a)

3.14

b)

3.140000

c)

3.1

d)

Error

8.

Guess the output of the following code:

a)

1

b)

2

c)

3

d)

0

9.

Which of the following is a potential issue with using gets()?

a)

It's slow

b)

It can cause a buffer overflow.

c)

It can only read strings of a fixed length

d)

It's deprecated but still safe to use if you're careful.

10.

What is the purpose of a function pointer?

a)

To store the return value of a function

b)

To pass a function as an argument to another function.

c)

To create a new function dynamically.

d)

To call a function from a different file.

11.

Output of the below code is:

a)

5  6

b)

6  6

c)

5  7

d)

6  7

12.

Purpose of typedef keyword is---------

a)

To define a constant.

b)

To create an alias for an existing data type.

c)

To declare a function.

d)

To include a header file.

13.

What is the output of the following code:

a)

Hello

b)

Jello

c)

H

d)

Error

14.

What is the difference between const int p and int const p?

a)

They are the same.

b)

const int p makes the pointer constant, int const p makes the integer constant.

c)

const int p makes the integer constant, int const p makes the pointer constant.

d)

const int *p is invalid syntax.

15.

What is the output of the following code:

a)

5

b)

10

c)

15

d)

Error

16.

What is a dangling pointer?

a)

A pointer that points to a valid memory location.

b)

A pointer that points to a memory location that has been freed.

c)

A pointer that has not been initialized.

d)

A pointer that points to a constant value.

17.

Identify the correct statement for a switch in C:

a)

Multiple cases can have identical constant expressions

b)

The default statement is optional

c)

switch expressions accept floating-point types

d)

The break is mandatory after every case

18.

Identify the wrong statement:

a)

A for loop can have multiple initialization expressions

b)

The while condition is evaluated before each iteration

c)

A loop variable must be declared globally

d)

Infinite loops are possible in all types of loops

19.

Which of the following causes an infinite loop?

a)

for (i = 0; i < 10; i++)

b)

while (1);

c)

do { } while (i > 10);

d)

for (i = 0; i < 5; i--);

20.

Which statement is valid for the switch construct?

a)

break is required for the default block

b)

Cases must be in ascending order

c)

All cases must end with a semicolon

d)

case values must be constant

21.

Pointer arithmetic is not possible on ___.

a)

Integer pointers

b)

Float pointers

c)

Character pointers

d)

Void pointers

22.

To round off x (float), to an int value, the correct way to do is

a)

y = (int)(x + 0.5)

b)

y = int(x + 0.5)

c)

y = (int)x + 0.5

d)

y = (int)((int)x + 0.5)

23.

Fill in the missing statement to copy a string in C:

a)

strcat

b)

strncpy

c)

strcpy

d)

strcmp

24.

What is the missing statement to declare a pointer to a function that takes two integers and returns a float?

a)

float *func(int, int);

b)

float (*func)(int, int);

c)

float (func)(int, int);

d)

float (*func())(int, int);

25.

----------------- keyword is used to declare a function that cannot be modified in other source files.

a)

static

b)

volatile

c)

const

d)

extern

26.

Which of the following is not a valid printf format specifier?

a)

%zu

b)

%lld

c)

%p

d)

%n

27.

Which of the following function declarations is valid in C?

a)

int func(int a, float b = 3.14);

b)

int func(int, float);

c)

int func(void int);

d)

void func(void) int;

28.

What does the following code print?

a)

10

b)

20

c)

Compile-time Error

d)

Run-time Error

29.

Given int arr[3][3], which of the following is an incorrect way to access an element?

a)

arr[1][2]

b)

*(arr[1]+2)

c)

*(*(arr+1)+2)

d)

arr[3][3]

30.

What will be the result of the following expression in C?

                     int a = 5, b = 10, c = 15;

                     a = b++ + --c * a;

a)

a = 5, b = 11, c = 14

b)

a = 15, b = 11, c = 14

c)

a = 5, b = 11, c = 14

d)

a = 20, b = 11, c = 14