wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

QUiZ

Total questions: 10

Worksheet time: 15mins

Name
Class
Date
1.

What is essential in every recursive function?

a)

A global variable

b)

A base condition

c)

At least two parameters

d)

A loop

2.

What does the following function return for fun(3)?
int fun(int n) {

if (n == 0) return 1;

return n * fun(n - 1);

}

a)

6

b)

3

c)

0

d)

1

3.

In indirect recursion:

a)

A function calls itself directly

b)

A function never calls any other function

c)

A function A calls B, and B calls A

d)

Functions cannot have base cases

4.

Which of the following is a disadvantage of recursion?

a)

Less readability

b)

More lines of code

c)

Higher memory usage due to stack frames

d)

Slower compilation

5.

What will the following print for test(3)?
void test(int n) {

if(n == 0) return;

printf("%d ", n);

test(n - 1);

printf("%d ", n);

}

a)

3 2 1

b)

1 2 3

c)

3 2 1 2 3

d)

1 2 3 2 1

6.

What is a main difference between malloc and calloc?

a)

malloc initializes memory to zero

b)

calloc initializes memory to zero

c)

Both initialize memory to zero

d)

Neither allocate memory

7.

Which of the following correctly allocates memory for an array of 5 integers?

a)

int *p = malloc(5);

b)

int p = malloc(5 sizeof(int));

c)

int *p = calloc(sizeof(int));

d)

int p = malloc(5);

8.

What happens if you call free() on a pointer allocated with malloc?

a)

The memory is released back to the system

b)

The pointer becomes NULL

c)

The program terminates

d)

Memory doubles automatically

9.

Which is TRUE about calloc?

a)

Allocates memory but does NOT set it to zero

b)

Allocates contiguous memory blocks

c)

Cannot allocate memory for arrays

d)

Is faster than malloc

10.

What is a dangling pointer?

a)

A pointer that stores a negative address

b)

A pointer that points to freed memory

c)

A pointer that points to global memory

d)

A pointer that has never been declared