C Online Quiz

This C Programming Online Test simulates a real online certification exam. You will be presented with multiple-choice questions (MCQs) based on C programming language concepts and will be given four options. You will select the most suitable answer for each question and then proceed to the next question without wasting time. You will get your online test

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

#include <stdio.h>
int main() {
    int x = 10, y = 20;
    printf("%d", x + y);
    return 0;
}
a) 10
b) 20
c) 30
d) 40

2. Which data type is used to store a single character in C?

a) int
b) float
c) char
d) string

3. What will the following C program output?

#include <stdio.h>
int main() {
    int a = 5;
    if (a = 0)
    printf("a is zero");
    else
    printf("a is not zero");
    return 0;
}
a) a is zero
b) a is not zero
c) Compilation error
d) None of the above

4. Which operator is used for pointer access in C?

a) &
b) *
c) #
d) $

5. What does the following C code snippet output?

#include <stdio.h>
int main() {
    int a = 10;
    int *ptr = &a;
    printf("%d", *ptr);
    return 0;
}
a) 10
b) Address of variable a
c) 0
d) Error

6. What is the standard return type of the main function in C?

a) int
b) void
c) float
d) char

7. What is the output of the following C code?

#include <stdio.h>
int main() {
    char c = 'A';
    printf("%d", c);
    return 0;
}
a) A
b) 65
c) Error
d) None of the above

8. Which header file is required to use the printf and scanf functions in C?

a) <string.h>
b) <stdio.h>
c) <stdlib.h>
d) <math.h>

9. How do you declare a one-dimensional array of integers in C?

a) int arr[10];
b) int arr[];
c) array arr[10];
d) int array 10;

10. What is the output of the following C code?

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

11. In C, which function is used to dynamically allocate memory?

a) alloc()
b) malloc()
c) calloc()
d) Both b) and c)

12. What is the purpose of the return 0; statement in a C main function?

a) To exit the program
b) To indicate that the program executed successfully
c) To pause the execution
d) To return control to the operating system

13. What will be the output of the following C code snippet?

#include <stdio.h>
int main() {
    int num = 10;
    printf("%d ", num++);
    printf("%d", num);
    return 0;
}
a) 10 10
b) 10 11
c) 11 11
d) 11 12

14. Which keyword is used to prevent any changes to the variable within a C program?

a) constant
b) const
c) fixed
d) immutable

15. What is the output of the following C code?

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

16. Which of the following is not a loop structure in C?

a) for
b) while
c) do-while
d) repeat-until

17. What does the following C code snippet output?

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

18. Which of the following correctly declares a pointer to an integer in C?

a) int *p;
b) ptr int;
c) int p*;
d) pointer int;

19. What is the output of the following C code?

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

20. How can you correct the following C code to display "Hello, World" on the screen?

#include <stdio.h>
int main() {
    prontf("Hello, World");
    return 0;
}
a) Replace prontf with printf
b) Replace prontf with print
c) Add a semicolon at the end
d) Include <string.h>

21. What is the function of the #include directive in a C program?

a) It includes a standard library to the program.
b) It defines new functions.
c) It creates a variable.
d) It starts the main function.

22. What will happen if you try to access an array element with an index that exceeds its size in C?

a) The program will crash.
b) It will print a garbage value.
c) It will automatically resize the array.
d) It will throw an index out of bounds exception.

23. What is the correct way to initialize an array of integers with zero in C?

a) int arr[5] = {0};
b) int arr[5] = {0, 0, 0, 0, 0};
c) int arr[5];
d) Both a) and b)

24. What is the output of the following C code?

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

25. In C, what is the keyword used to go to the next iteration of a loop immediately?

a) break
b) continue
c) pass
d) next

Comments