C Programming MCQ Questions and Answers

Welcome to C Programming Coding MCQ Questions. Here, we present 20 MCQs (Multiple-Choice Questions) with code snippets to test your understanding of C programming coding and logical stills. Let's get started!

1. What will the following C program output?

#include <stdio.h>
int main() {
    printf("%d", 5==5);
}
a) 1
b) 0
c) True
d) False

2. What is the output of this C code?

#include <stdio.h>
int main() {
    int a = 5, b = 7;
    printf("%d", a + b);
}
a) 12
b) 57
c) Compilation error
d) 5b

3. What will the following C code snippet output?

#include <stdio.h>
int main() {
    char c = 'A';
    printf("%c", c + 1);
}
a) A
b) B
c) C
d) 66

4. Consider the following C program. What will it output?

#include <stdio.h>
int main() {
    int x = 10;
    int y = x--;
    printf("%d %d", x, y);
}
a) 9 10
b) 10 9
c) 10 10
d) 9 9

5. What does the following C program print?

#include <stdio.h>
int main() {
    int nums[] = {1, 2, 3, 4, 5};
    printf("%d", nums[3]);
}
a) 3
b) 4
c) 5
d) Error

6. What will this C program output?

#include <stdio.h>
int main() {
    int i = 1;
    printf("%d", i++);
}
a) 0
b) 1
c) 2
d) Error

7. What is printed by the following C code?

#include <stdio.h>
int main() {
    int i = 10;
    if(i == 10) printf("i is ten");
    else printf("i is not ten");
}
a) i is ten
b) i is not ten
c) Compilation error
d) No output

8. What does the following C code output?

#include <stdio.h>
int main() {
    int i;
    for(i = 0; i < 5; i++);
    printf("%d", i);
}
a) 0
b) 4
c) 5
d) Compilation error

9. What will the following C code snippet output?

#include <stdio.h>
int main() {
    int x = 5, y = 3;
    printf("%d", x / y);
}
a) 1.67
b) 1
c) 2
d) Error

10. What is the output of this C program?

#include <stdio.h>
int main() {
    int a = 1, b = 2;
    if(a-- > 0 && b++ > 2) printf("Yes");
    else printf("No");
    printf(" %d %d", a, b);
}
a) Yes 0 3
b) No 0 3
c) No 0 2
d) Yes 0 2

11. What will this code snippet print?

#include <stdio.h>
int main() {
    int arr[] = {10, 20, 30, 40, 50};
    int *ptr = arr;
    printf("%d", *(ptr+3));
}
a) 10
b) 20
c) 40
d) Error

12. What will the following C code output?

#include <stdio.h>
int main() {
    char c = 'a';
    printf("%c", c - 32);
}
a) A
b) a
c) z
d) Error

13. What is the output of the following C program?

#include <stdio.h>
int main() {
    int i = 0;
    while(i < 3) {
        printf("%d ", i);
        i++;
    }
}
a) 0 1 2
b) 1 2 3
c) 0 1 2 3
d) Infinite loop

14. Analyze the following code snippet. What will it output?

#include <stdio.h>
int main() {
    int x = 5;
    int y = x * 10;
    printf("%d", y);
}
a) 5
b) 10
c) 50
d) 100

15. What will the following C program output?

#include <stdio.h>
int main() {
    int i = 10;
    if(i == 10)
    printf("i is ten\n");
    printf("i is definitely ten\n");
}
a) i is ten
b) i is definitely ten
c) i is ten
d) Compilation error

16. What is the output of this C code?

#include <stdio.h>
int main() {
    int num = 4;
    printf("%d", num++);
}
a) 3
b) 4
c) 5
d) 6

17. Consider the following C program. What will it print?

#include <stdio.h>
int main() {
    for(int i = 1; i <= 5; i++) {
        if(i % 2 == 0) continue;
        printf("%d ", i);
    }
}
a) 1 3 5
b) 1 2 3 4 5
c) 2 4
d) None

18. What does the following C program output?

#include <stdio.h>
int main() {
    int a = 5, b = 0;
    printf("%d", a / b);
}
a) 0
b) 5
c) Runtime error
d) Undefined

19. What will be the output of the following C code?

#include <stdio.h>
int main() {
    int x = 10, y = 5;
    printf("%d", x % y);
}
a) 0
b) 5
c) 10
d) None of the above

20. What does this code snippet output?

#include <stdio.h>
int main() {
    int i = 3;
    while(i--) {
        printf("%d ", i);
    }
}
a) 3 2 1
b) 2 1 0
c) 2 1
d) 1 0

Comments