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

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

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

1) // comment

2) # comment

3) /* comment */

4) comment

Answer : Option 1

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

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

1) 3

2) 4

3) 2

4) 5

Answer : Option 1

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

1) 2

2) 4

3) 8

4) Depends on the compiler

Answer : Option 4

What does the `free()` function do?

1) Allocates memory

2) Deallocates memory

3) Resizes memory

4) None of the above

Answer : Option 2

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

1) 25

2) 20

3) 25

4) 15

Answer : Option 1

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

1) exit()

2) stop()

3) quit()

4) terminate()

Answer : Option 1

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

1) 1

2) 0

3) 3

4) 4

Answer : Option 1