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 : Option 4

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

1) 14

2) 20

3) 26

4) 12

Answer : Option 1

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 : Option 2

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

1) 4

2) 5

3) 3

4) 6

Answer : Option 1

Which of the following is a valid pointer arithmetic operation?

1) p++

2) p--

3) p + 1

4) All of the above

Answer : Option 4

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

1) 1

2) 0

3) 10

4) 5

Answer : Option 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 : Option 4

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 : Option 1

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

1) #include

2) #include

3) #include

4) #include

Answer : Option 1

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 : Option 4