Learn C MCQs

Prepare C MCQs (Multiple choice Questions) for exam and job interviews.

What will be the output of printf("%d", 1 && 0);?

1) 1

2) 0

3) 10

4) 5

Answer : Option 2

Which of the following is used to concatenate two strings in C?

1) strcat()

2) strcpy()

3) strlen()

4) strcmp()

Answer : strcat()

What is the output of printf("%d", 7 % 4);?

1) 3

2) 1

3) 0

4) 4

Answer : 3

Which of the following functions can be used to sort an array?

1) qsort()

2) sort()

3) array_sort()

4) None of the above

Answer : qsort()

What is the purpose of the `sizeof` operator?

1) Returns the size of a variable

2) Returns the size of an array

3) Returns the size of a type

4) All of the above

Answer : All of the above

Which of the following statements is true about arrays in C?

1) They are static in size

2) They can store multiple data types

3) They can be resized

4) None of the above

Answer : They are static in size

What is the output of printf("%d", 3 * (4 + 2));?

1) 18

2) 21

3) 24

4) 30

Answer : 18

Which of the following is the correct way to define a structure in C?

1) struct name { int x; };

2) struct name; int x;

3) struct { int x; } name;

4) All of the above

Answer : struct name { int x; };

What is the output of printf("%d", (5 + 3) * 2);?

1) 16

2) 12

3) 8

4) 20

Answer : 16

Which of the following functions is used to compare two strings in C?

1) strcmp()

2) strncmp()

3) strncpy()

4) strdup()

Answer : strcmp()