Learn C MCQs

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

Which of the following is not a valid way to declare a variable in C?

1) int x;

2) float x;

3) double x;

4) decimal x;

Answer : decimal x;

What is the purpose of the `break` statement in a loop?

1) To exit the loop

2) To skip the current iteration

3) To restart the loop

4) None of the above

Answer : To exit the loop

What is the correct way to comment a single line in C?

1) // comment

2) # comment

3) /* comment */

4) comment

Answer : // comment

Which of the following is the correct syntax for a while loop?

1) while (condition) {}

2) do {} while (condition);

3) for (initialization; condition; increment) {}

4) Both 1 and 2

Answer : Both 1 and 2

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

1) 3

2) 4

3) 2

4) 5

Answer : 3

What is the output of printf("%d", sizeof(int));?

1) 2

2) 4

3) 8

4) Depends on the compiler

Answer : Depends on the compiler

What does the `free()` function do?

1) Allocates memory

2) Deallocates memory

3) Resizes memory

4) None of the above

Answer : Deallocates memory

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

1) 25

2) 20

3) 25

4) 15

Answer : 25

Which of the following is used to terminate a program in C?

1) exit()

2) stop()

3) quit()

4) terminate()

Answer : exit()

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

1) 1

2) 0

3) 3

4) 4

Answer : 1