Learn C MCQs

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

Which of the following is used to allocate memory for an array dynamically?

1) malloc()

2) calloc()

3) realloc()

4) All of the above

Answer : All of the above

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

1) 14

2) 20

3) 26

4) 12

Answer : 14

What is the purpose of the `volatile` keyword in C?

1) To define constants

2) To indicate that a variable may change unexpectedly

3) To optimize code

4) None of the above

Answer : To indicate that a variable may change unexpectedly

What will be the output of printf("%d", 9 / 2);?

1) 4

2) 5

3) 3

4) 6

Answer : 4

Which of the following is a valid pointer arithmetic operation?

1) p++

2) p--

3) p + 1

4) All of the above

Answer : All of the above

What is the output of printf("%d", 10 && 5);?

1) 1

2) 0

3) 10

4) 5

Answer : 1

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

1) const int x = 5;

2) #define x 5

3) int x = 5;

4) Both 1 and 2

Answer : Both 1 and 2

What is the purpose of the `break` statement?

1) To exit a loop

2) To continue the next iteration

3) To terminate the program

4) To pause execution

Answer : To exit a loop

Which of the following statements is used to include standard input-output library in C?

1) #include <stdio.h>

2) #include <stdlib.h>

3) #include <string.h>

4) #include <math.h>

Answer : #include <stdio.h>

What is the size of an `int` data type in C?

1) 2 bytes

2) 4 bytes

3) 8 bytes

4) Depends on the compiler

Answer : Depends on the compiler