20+ Best MCQs on C Programming

20+ Best MCQs on C Programming

Best MCQs on C Programming: Friends, you must have also heard that practice makes man perfect, in the same way, we need to practice more and more in programming.

Because to understand any concept well, you have to practice questions, which will clear your concept.

That’s why in today’s blog post, I have brought more than 20 multiple-choice questions of C programming for you, which you can solve by yourself, and if there is any problem, you can see the answer, and that too with Explanation. Together.

So let’s get started.

Q1. Which of the following is not a basic data type in c language?

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

Q2. What are the entities whose values can be changed called?

a) Constants
b) Variables
c) Modules
d) Tokens

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

#include <stdio.h>

int main() {
    int x = 5;
    printf("%d", x++);
    return 0;
}

a) 5
b) 6
c) 4
d) Undefined

Q4. What is the correct way to declare a constant integer variable in C?

a) constant int x = 10;
b) int constant x = 10;
c) const int x = 10;
d) int const x = 10;

Q5. Which loop in C is executed at least once?

a) for loop
b) while loop
c) do-while loop
d) None of the above

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

#include <stdio.h>

int main() {
    int i;
    for (i = 0; i < 5; i++) {
        if (i == 2)
            continue;
        printf("%d ", i);
    }
    return 0;
}

a) 0 1 2 3 4
b) 0 1 3 4
c) 0 1 3
d) 0 1 2 3

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

#include <stdio.h>

int main() {
    int arr[] = {1, 2, 3, 4, 5};
    printf("%d", arr[5]);
    return 0;
}

a) 0
b) 5
c) Garbage value
d) Runtime error

Q8. What is the keyword used to define a structure in C?

a) struct
b) class
c) structure
d) typedef

Q9. What is the correct way to dynamically allocate memory for an integer in C?

a) int *num = malloc(sizeof(int));
b) int num = malloc(sizeof(int));
c) int num = malloc(int);
d) int *num = malloc(int);

Q10. What is the value of the result after the following code is executed?

int x = 10;
int y = 3;
float result = (float)x / y;

a) 3.33
b) 3
c) 3.0
d) 3.333

Q11. What is the purpose of the sizeof operator in C?

a) It returns the size of a variable in bytes.
b) It returns the size of a datatype in bytes.
c) It returns the address of a variable.
d) It returns the value of a variable.

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

#include <stdio.h>

int main() {
    char str[] = "Hello";
    printf("%c", str[5]);
    return 0;
}

a) H
b) e
c) o
d) Garbage value

Q13. Which escape sequence is used to represent the newline character in C?

a) \n
b) \r
c) \t
d) \

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

#include <stdio.h>

int main() {
    int a = 5, b = 10;
    a = a ^ b;
    b = a ^ b;
    a = a ^ b;
    printf("a = %d, b = %d", a, b);
    return 0;
}

a) a = 5, b = 10
b) a = 10, b = 5
c) a = 0, b = 0
d) a = 15, b = 5

Q15. What is the correct way to close a file in C after reading/writing?

a) fclose(file);
b) close(file);
c) file.close();
d) end(file);

Q16. Which function is used to read a character from the standard input in C?

a) getchar()
b) gets()
c) readchar()
d) scanf()

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

#include <stdio.h>

int main() {
    int num = 123;
    printf("%d", num++);
    return 0;
}

a) 124
b) 123
c) Undefined behavior
d) Compiler error

Q18. How do you access the nth element of a dynamically allocated array arr in C?

a) arr[n]
b) *(arr + n)
c) &arr[n]
d) n[arr]

Q19. What is the purpose of the break statement in C?

a) It terminates the program.
b) It skips the rest of the loop body and jumps to the next iteration.
c) It jumps to a labeled statement.
d) It exits from a switch statement.

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

#include <stdio.h>

int main() {
    int x = 10;
    printf("%d", x++);
    printf("%d", ++x);
    return 0;
}

a) 1011
b) 1111
c) 1112
d) 1012

Summary

If you want to learn similar programming questions and concepts in an easy language, then you can explore our site, where you will find a lot of content.

Similar articles

About The Author

Leave a reply

Your email address will not be published. Required fields are marked *