wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C Programming Quiz

Total questions: 50

Worksheet time: 25mins

Name
Class
Date
1.

What will be the output of printf("%d", sizeof('A'));?

a)

1

b)

2

c)

4

d)

8

2.

Which keyword is used to prevent modification of a variable?

a)

static

b)

const

c)

volatile

d)

register

3.

What is the output of the code int a = 5; printf("%d", a++ + ++a);?

a)

11

b)

12

c)

10

d)

Undefined behavior

4.

Which operator has the highest precedence in C?

a)

*

b)

++

c)

()

d)

[]

5.

Which of the following is used to dynamically allocate memory in C?

a)

alloc()

b)

calloc()

c)

malloc()

d)

Both B and C

6.

What does this code output? int a = 10; int b = a++ + ++a; printf("%d", b);

a)

21

b)

22

c)

23

d)

24

7.

Which of the following is not a storage class in C?

a)

auto

b)

extern

c)

volatile

d)

static

8.

What is the return type of malloc()?

a)

int

b)

void

c)

void *

d)

float

9.

Which function is used to read a string with spaces?

a)

scanf()

b)

gets()

c)

fgets()

d)

getch()

10.

Which is correct syntax for a function pointer?

a)

int *func();

b)

int (*func)();

c)

*int func();

d)

func int*();

11.

Which header file is required for strlen()?

a)

stdlib.h

b)

string.h

c)

stdio.h

d)

ctype.h

12.

Which format specifier is used to print an address?

a)

%p

b)

%x

c)

%d

d)

%u

13.

Which of these is a correct 2D array declaration?

a)

int arr[ ][3];

b)

int arr[3][3];

c)

int arr(3)(3);

d)

int arr[];

14.

Which loop is guaranteed to run at least once?

a)

for

b)

while

c)

do-while

d)

switch

15.

How to access structure member with a pointer?

a)

*ptr.member

b)

ptr->member

c)

ptr.member

d)

&ptr.member

16.

Size of integer pointer on 64-bit system?

a)

2 bytes

b)

4 bytes

c)

8 bytes

d)

Depends

17.

Which is not a loop control structure?

a)

break

b)

continue

c)

goto

d)

switch

18.

Correct way to declare function pointer?

a)

int *fptr();

b)

int (*fptr)();

c)

(*fptr)int();

d)

fptr() *int;

19.

What does char str[] = "Hello"; printf("%c", *str); print?

a)

H

b)

e

c)

o

d)

l

20.

Correct file opening mode to append?

a)

"w"

b)

"a"

c)

"r"

d)

"ra"

21.

Which is not a valid pointer type?

a)

void*

b)

int*

c)

function*

d)

char*

22.

Which function frees memory allocated by malloc()?

a)

delete

b)

remove

c)

free

d)

clear

23.

Which of the following creates infinite loop?

a)

for(;;)

b)

while(1)

c)

do {} while(1);

d)

All of the above

24.

How to pass an array to a function?

a)

Size only

b)

Each element

c)

Base address

d)

Last index

25.

Default return type of a function in C if not specified?

a)

int

b)

void

c)

float

d)

undefined

26.

Which data structure uses LIFO?

a)

Queue

b)

Stack

c)

Array

d)

Tree

27.

Which operation is not possible in stack?

a)

push

b)

pop

c)

insert at bottom

d)

top

28.

Which data structure uses FIFO?

a)

Queue

b)

Stack

c)

Tree

d)

Graph

29.

Worst-case time complexity of search in BST?

a)

O(log n)

b)

O(n)

c)

O(n log n)

d)

O(1)

30.

In which traversal is root between left and right subtree?

a)

Preorder

b)

Inorder

c)

Postorder

d)

Level order

31.

Which data structure is used in recursion?

a)

Stack

b)

Queue

c)

Array

d)

List

32.

Degree of a leaf node?

a)

1

b)

2

c)

0

d)

Undefined

33.

Which is a non-linear data structure?

a)

Array

b)

Linked list

c)

Stack

d)

Tree

34.

Used to implement priority queue?

a)

Stack

b)

Queue

c)

Heap

d)

Tree

35.

Time complexity to access array element by index?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n²)

36.

Supports dynamic memory allocation?

a)

Array

b)

Linked list

c)

Stack

d)

Queue

37.

Maximum number of children in binary tree?

a)

1

b)

2

c)

3

d)

n

38.

Traversal for sorting elements in BST?

a)

Preorder

b)

Inorder

c)

Postorder

d)

Level order

39.

Best data structure for undo functionality?

a)

Queue

b)

Stack

c)

Linked List

d)

Array

40.

Best for BFS in graph?

a)

Stack

b)

Queue

c)

Priority Queue

d)

Heap

41.

Not an application of queue?

a)

Printer scheduling

b)

Call center

c)

Undo

d)

CPU scheduling

42.

Null pointers in a binary tree with 4 nodes?

a)

3

b)

4

c)

5

d)

6

43.

Not a valid binary tree type?

a)

Full

b)

Complete

c)

Skewed

d)

Balanced

44.

Best for DFS in graph?

a)

Queue

b)

Stack

c)

Tree

d)

Array

45.

Data structure used in hash tables?

a)

Queue

b)

Stack

c)

Array

d)

Linked list

46.

Tree with at most 2 children?

a)

Binary tree

b)

Ternary tree

c)

AVL tree

d)

B-tree

47.

Not a linear data structure?

a)

Array

b)

Stack

c)

Graph

d)

Queue

48.

Height of a single-node binary tree?

a)

-1

b)

0

c)

1

d)

Undefined

49.

In circular queue, rear just before front means:

a)

Empty

b)

Full

c)

Half

d)

Overflow

50.

Which tree self-balances on insert/delete?

a)

BST

b)

AVL Tree

c)

Binary Tree

d)

Trie