wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C Programming Quiz

Total questions: 80

Worksheet time: 53mins

Name
Class
Date
1.

What is the output of

` printf("%d", 5 + 2 * 3); `?

a)

21

b)

11

c)

16

d)

15

2.

Which function returns the length of a string?

a)

strcopy()

b)

strlen()

c)

strcmp()

d)

strcat()

3.

Which of the following is a valid C identifier?

a)

int@num

b)

123abc

c)

_varName

d)

void

4.

What does `#include` do in a C program?

a)

Declares main function

b)

Links standard I/O functions

c)

Allocates memory

d)

None of the above

5.

What is the output of the following loop? for(int i = 0; i < 3; i++) { printf("%d ", i); }

a)

0 1 2

b)

1 2 3

c)

0 1 2 3

d)

0 1

6.

Which storage class maintains the variable value between function calls?

a)

auto

b)

register

c)

static

d)

extern

7.

Which operator is used to access the value at an address in C?

a)

&

b)

*

c)

->

d)

@

8.

How many bytes will this union occupy in memory?

union u1 { int a; float b; };

a)

0

b)

4

c)

8

d)

2

9.

In C, what is the index of the first element in an array?

a)

1

b)

0

c)

-1

d)

Depends on declaration

10.

Which bitwise operator is used to shift bits to the left?

a)

<<

b)

>>

c)

&

d)

~

11.

Which loop is guaranteed to execute at least once in C?

a)

for

b)

while

c)

do-while

d)

nested if

12.

Which function is used to open a file?

a)

open()

b)

fopen()

c)

startfile()

d)

read()

13.

Pseudocode output: sum = 0 for i = 1 to 3: sum = sum + i print sum

a)

6

b)

3

c)

9

d)

5

14.

What does `strcpy()` function do?

a)

Appends strings

b)

Compares strings

c)

Copies one string into another

d)

Calculates length

15.

Which of the following is a character constant?

a)

"A"

b)

'A'

c)

A

d)

"65"

16.

What is the output of

`printf("%d", a++);`

if int a = 5?

a)

5

b)

6

c)

4

d)

Error

17.

Which symbol is used for decision in a flowchart?

a)

Rectangle

b)

Parallelogram

c)

Diamond

d)

Circle

18.

What is recursion in C?

a)

Looping structure

b)

Function calling itself

c)

Infinite loop

d)

Memory allocation

19.

What is used to prevent memory leaks in C?

a)

free()

b)

malloc()

c)

calloc()

d)

memcpy()

20.

Which keyword is used to define integer variable in C?

a)

float

b)

double

c)

int

d)

var

21.

What is the result of `4 << 1`?

a)

2

b)

8

c)

1

d)

6

22.

Which of the following is used to declare a structure in C?

a)

union

b)

class

c)

struct

d)

object

23.

What is the role of `#define`?

a)

Include file

b)

Compile conditionally

c)

Create macro

d)

Debug

24.

Which of the following is a string literal?

a)

'abc'

b)

"abc"

c)

abc

d)

[abc]

25.

What is the output of: int x = 10;

if (x > 5) {

if (x < 15)

printf("A");

else printf("B");

}

else {

printf("C");

}

a)

A

b)

B

c)

C

d)

AB

26.

Which function is used to close a file?

a)

endfile()

b)

fclose()

c)

stopfile()

d)

closefile()

27.

What is the correct format specifier for printing a float value?

a)

%d

b)

%c

c)

%f

d)

%s

28.

What is a mask in bitwise operation?

a)

Input method

b)

Special operator

c)

Filter applied on bits

d)

Debugging mode

29.

In a 2D array declared as `int arr[3][2];`, how many elements are there?

a)

5

b)

6

c)

3

d)

2

30.

What does `strcmp()` return if both strings are equal?

a)

1

b)

-1

c)

0

d)

Error

31.

Which of these sorts arrays?

a)

intsort()

b)

bubblesort()

c)

quicksort()

d)

sort()

32.

What is the output of: int arr[] = {1, 2, 3}; printf("%d", arr[1]);

a)

1

b)

2

c)

3

d)

4

33.

What is a segmentation fault?

a)

Infinite loop

b)

Hardware error

c)

Invalid memory access

d)

File error

34.

What is the result of: int a = 5;

int *p = &a; printf("%d", *p);

a)

5

b)

Address of a

c)

Error

d)

0

35.

Which of the following is NOT a loop control statement?

a)

while

b)

if

c)

for

d)

do

36.

What is the purpose of `exit(0);`?

a)

Exit from loop

b)

Exit from block

c)

Exit program

d)

End recursion

37.

What is `malloc()` used for?

a)

Static memory allocation

b)

Dynamic memory allocation

c)

File handling

d)

None

38.

What is the output of:

int fun() {

static int x = 0; x++;

return x;

}

main() {

printf("%d", fun());

printf("%d", fun());

}

a)

11

b)

12

c)

22

d)

01

39.

What is `void` used for in functions?

4 lines
40.

What is `void` used for in functions?

a)

To declare integer type

b)

To indicate function returns nothing

c)

For memory access

d)

To free memory

41.

What does `feof()` return at end of file?

a)

-1

b)

0

c)

1

d)

NULL

42.

Which format specifier is used to print a single character?

a)

%d

b)

%s

c)

%f

d)

%c

43.

What is the output of this pseudocode? void swap(int x, int y) {

int temp = *x;

x = y;

*y = temp;

}

int main() {

int a = 10;

int b = 20;

swap(&a, &b);

printf("%d %d\n", a, b);

return 0;

a)

10 20

b)

20 10

c)

Error

d)

Undefined

44.

What will `sizeof(char)` return?

a)

1

b)

2

c)

4

d)

8

45.

What is the keyword used to define a constant value in C?

a)

const

b)

static

c)

final

d)

define

46.

In memory representation, how are 2D arrays stored?

a)

Column major

b)

Random access

c)

Row major

d)

Diagonal

47.

Which is true about function declaration?

a)

Optional in C

b)

Mandatory before main

c)

Always ends with return

d)

Never ends with semicolon

48.

What is the default value of an uninitialized local variable?

a)

0

b)

Garbage

c)

NULL

d)

-1

49.

Which of the following is used to comment in C?

a)

// or /* */

b)

c)

# comment

d)

--

50.

Which operator has the highest precedence in C?

a)

*

b)

++

c)

=

d)

&&

51.

What is the result of the expression `5 % 2`?

a)

1

b)

2

c)

0

d)

2.5

52.

Which keyword is used for calling by reference in C?

a)

&

b)

*

c)

->

d)

None (C uses pointers instead)

53.

In a structure, how are members accessed?

a)

. (dot operator)

b)

->

c)

&

d)

*

54.

Which of the following is used to read a character from the keyboard?

a)

getch()

b)

scanf()

c)

getchar()

d)

Both a and c

55.

What will `strcmp("abc", "abd")` return?

a)

0

b)

1

c)

Negative value

d)

Positive value

56.

What is time complexity of printing first n natural numbers?

a)

O(n^2)

b)

O(1)

c)

O(n)

d)

O(log n)

57.

Which file mode is used to read a file in binary mode?

a)

"r"

b)

"rb"

c)

"b"

d)

"br"

58.

What is the role of `fseek()`?

a)

Read file

b)

Write file

c)

Move file pointer

d)

Close file

59.

Which loop is used when the number of iterations is known?

a)

for

b)

while

c)

do-while

d)

switch

60.

What is the output of:

int a = 4, b = 2;

printf("%d", a & b);

a)

0

b)

2

c)

4

d)

6

61.

Which algorithm is based on Divide & Conquer?

a)

Bubble sort

b)

Quick sort

c)

Linear search

d)

Insertion sort

62.

What is the result of the following pseudocode?

int main() {

int n = 3;

int fact = 1;

for (int i = 1; i <= n; i++) {

fact = fact * i;

}

printf("%d\n", fact);

a)

3

b)

6

c)

5

d)

9

63.

Which header file is needed for string functions?

a)

stdlib.h

b)

conio.h

c)

string.h

d)

stdio.h

64.

Which of the following is **not** a valid keyword in C?

a)

return

b)

continue

c)

start

d)

goto

65.

What is `&a` in C?

a)

Address of a

b)

Value of a

c)

Reference to a

d)

Pointer

66.

What happens if you forget to close a file?

a)

Compiler error

b)

Memory leak

c)

Nothing

d)

File corruption

67.

Which pointer type can store address of any variable?

a)

int *

b)

char *

c)

float *

d)

void *

68.

What will be the output of:

int a = 3;

printf("%d", a == 3 ? 5 : 10);

a)

3

b)

5

c)

10

d)

Error

69.

What does `continue;` do inside a loop?

a)

Ends loop

b)

Restarts program

c)

Skips current iteration

d)

Reverses loop

70.

Which operator is used to compare equality?

a)

=

b)

==

c)

!=

d)

:=

71.

What will be the output of the following code?

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

printf("%d", *(a + 3));

a)

2

b)

3

c)

4

d)

5

72.
  1. What does the following code snippet do?

int a = 10, b = 20;

int p = &a, q = &b;

int temp = *p;

p = q;

*q = temp;

a)

Swaps the values of a and b

b)

Assigns value of b to a only

c)

Assigns value of a to b only

d)

Does nothing

73.

What will this code print?

struct Node {

int data;

struct Node* next;

};

struct Node a = {10, NULL};

struct Node b = {20, NULL};

a.next = &b;

printf("%d", a.next->data);

a)

10

b)

20

c)

0

d)

Garbage value

74.

What will be the result of the following queue code?

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

int front = 0, rear = 4;

printf("%d", queue[front++]);

a)

1

b)

2

c)

5

d)

Compilation Error

75.

What is the output of the following binary search code?

int arr[] = {1, 3, 5, 7, 9}, key = 5;

int low = 0, high = 4;

while (low <= high) {

int mid = (low + high) / 2;

if (arr[mid] == key) {

printf("%d", mid);

break;

} else if (arr[mid] < key) low = mid + 1;

else high = mid - 1;

}

a)

0

b)

1

c)

2

d)

3

76.

What is the time complexity of this recursive function?

void recur(int n) {

if (n <= 1) return;

recur(n/2);

recur(n/2);

}

a)

O(n)

b)

O(log n)

c)

O(n log n)

d)

O(n)

77.

What is printed by this linked list traversal code?

struct Node {

int data;

struct Node* next;

};

struct Node n3 = {30, NULL};

struct Node n2 = {20, &n3};

struct Node n1 = {10, &n2};

struct Node* ptr = &n1;

while (ptr != NULL) {

printf("%d ", ptr->data);

ptr = ptr->next;

}

a)

10 20 30

b)

30 20 10

c)

10 30

d)

Segmentation fault

78.

Which operation causes overflow in a stack (array implementation)?

if (top == MAX - 1) {

printf("Overflow");

}

a)

Pushing when top is -1

b)

Popping when top is 0

c)

Pushing when top == MAX - 1

d)

Popping when top > 0

79.

What will be the output of this tree traversal?

(Given a BST with values inserted in order: 5, 3, 7, 2, 4)

// In-order traversal

void inorder(struct Node* root) {

if (root != NULL) {

inorder(root->left);

printf("%d ", root->data);

inorder(root->right);

}

}

a)

5 3 7 2 4

b)

2 3 4 5 7

c)

7 5 4 3 2

d)

2 4 3 5 7

80.

What will be the output of the following C code involving a singly linked list?

#include <stdio.h>

#include <stdlib.h>

struct Node {

int data;

struct Node* next;

};

void printList(struct Node* head) {

while (head) {

printf("%d ", head->data);

head = head->next->next;

}

}

int main() {

struct Node* head = malloc(sizeof(struct Node));

head->data = 1;

head->next = malloc(sizeof(struct Node));

head->next->data = 2;

head->next->next = malloc(sizeof(struct Node));

head->next->next->data = 3;

head->next->next->next = NULL;

printList(head);

return 0;

}

a)

1 2 3

b)

1 3

c)

1

d)

Segmentation Fault