C Online Test - MCQ Questions

Welcome to the C Programming Online Test! This test is designed to evaluate your knowledge and skills in C programming through a variety of questions ranging from basic syntax to more complex programming concepts. The test consists of 25 multiple-choice questions, each accompanied by a coding snippet that provides a practical challenge to solve.

The questions are designed to test various aspects of the C language, including data types, control structures, memory management, and pointer operations. This will help assess your ability to write and understand C code, as well as your problem-solving skills in a programming context.

Before you begin, ensure you have a good understanding of C fundamentals. Read each question carefully and select the most appropriate answer. Each question has an explanation for the correct answer, which will be provided at the end of the test. This feedback is designed to help you learn and improve your understanding of C programming.

Good luck, and we hope you find this test both challenging and educational!

1. What is the output of the following C program snippet?

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

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

#include <stdio.h>
int main() {
    int x = 10;
    x += x -= x * x;
    printf("%d", x);
}
a) 1
b) 0
c) 10
d) -90

3. What does this code fragment print?

#include <stdio.h>
int main() {
    char *ptr = "Hello World";
    printf("%c", *&*ptr);
}
a) H
b) e
c) Hello World
d) Error

4. Analyze the output of this code snippet:

#include <stdio.h>
int main() {
    int a = 10, b = 0, c = 10;
    int d = a == b == c;
    printf("%d", d);
}
a) 1
b) 0
c) 10
d) An error occurs

5. Determine the output for the following C function:

#include <stdio.h>
void myFunc(int x) {
    printf("%d", x * x);
}
int main() {
    int a = 4;
    myFunc(a);
    return 0;
}
a) 4
b) 8
c) 16
d) None of the above

6. What output does the following program generate?

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

7. What is printed by this C code?

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

8. What does the following program output?

#include <stdio.h>
int main() {
    printf("%d", sizeof("Hello, World!"));
}
a) 12
b) 13
c) 14
d) 15

9. What is the result of the following C expression?

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

10. What will the following code snippet print?

#include <stdio.h>
int main() {
    int num[] = {5, 15, 25};
    int i;
    for (i = 0; i < 3; i++) {
        printf("%d ", *(num + i));
    }
}
a) 5 15 25
b) 5
c) 5 15
d) Compilation error

11. What is the result of the following C function call?

#include <stdio.h>
void update(int *p) {
    *p = (*p) * 2;
}
int main() {
    int x = 5;
    update(&x);
    printf("%d", x);
}
a) 5
b) 10
c) 2
d) None of the above

12. What is the outcome of executing this C program?

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

13. What does the following code print?

#include <stdio.h>
int main() {
    int i = 1024;
    for (; i; i >>= 1)
        printf("%d ", i);
}
a) 1024 512 256 128 64 32 16 8 4 2 1
b) 1024 512 256 128 64 32 16 8 4 2
c) 512 256 128 64 32 16 8 4 2 1
d) 1024

14. Identify the output of this C snippet:

#include <stdio.h>
int main() {
    int arr[5] = {1, 2, 3, 4, 5};
    int *p = arr;
    ++*p;
    printf("%d", *p);
}
a) 1
b) 2
c) 3
d) None of the above

15. What will be printed by the following program?

#include <stdio.h>
int main() {
    char str[] = "C Programming";
    char *ptr = str;
    while (*ptr) printf("%c", *ptr++);
}
a) C Programming
b) C
c) Programming
d) Compilation error

16. What error does the following C code have?

#include <stdio.h>
int main() {
    int *ptr = (int *)malloc(sizeof(int));
    *ptr = 10;
    free(ptr);
    *ptr = 20;
    printf("%d", *ptr);
}
a) No error
b) Segmentation fault
c) Memory leak
d) Compilation error

17. Analyze the output of this C program:

#include <stdio.h>
int main() {
    int x = 0;
    if (x == 0)
        printf("true ");
    else
        printf("false ");
    printf("%d", x);
}
a) true 0
b) false 0
c) true 1
d) false 1

18. What will the following code snippet print?

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

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

#include <stdio.h>
int main() {
    int a = 5, b = 10;
    int max = (a > b) ? a : b;
    printf("%d", max);
}
a) 5
b) 10
c) 0
d) Compilation error

20. What does this code fragment print?

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

21. What is the result of the following code execution?

#include <stdio.h>
int main() {
    int x = 1, y = 2, z = 3;
    printf("%d", x < y < z);
}
a) 1
b) 0
c) 2
d) Compilation error

22. Determine the output of this program:

#include <stdio.h>
int main() {
    char s[] = "hello";
    char *p = s;
    while (*p) printf("%c", *++p);
}
a) hello
b) ello
c) llo
d) olleh

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

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

24. What does this C code output?

#include <stdio.h>
int main() {
    int a = 3;
    switch (a) {
    case 1: printf("One ");
    case 3: printf("Three ");
    case 2: printf("Two ");
    default: printf("Default ");
    }
}
a) Three Two Default
b) Three
c) One Three Two Default
d) Default

25. What will this C code output?

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

Comments