C MCQ (1-30)

1. Which of the following is the correct syntax for declaring a pointer in C?
a) pointer ptr;
b) ptr *pointer;
c) ptr;
d) int
ptr;

Answer: d) int* ptr;


2. Which operator is used to get the address of a variable in C?
a) &
b) *
c) @
d) #

Answer: a) &


3. What is the size of an integer in C on a 32-bit machine?
a) 2 bytes
b) 4 bytes
c) 8 bytes
d) 16 bytes

Answer: b) 4 bytes


4. What does the following C statement do?

printf("%d", sizeof(int));

a) Prints the size of an integer in bytes.
b) Prints the value of an integer variable.
c) Prints the size of the variable.
d) Prints the value of the int data type.

Answer: a) Prints the size of an integer in bytes.


5. Which of the following is the correct syntax to define a macro in C?
a) #define MACRO value
b) define MACRO(value)
c) macro MACRO = value;
d) define macro(MACRO value)

Answer: a) #define MACRO value


6. Which of the following is a valid function signature in C?
a) void func();
b) func void();
c) void func(int x);
d) func void(int x);

Answer: c) void func(int x);


7. Which of the following is the correct way to initialize a two-dimensional array in C?
a) int arr[3][4];
b) int arr[3] = {1, 2, 3};
c) int arr[3][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};
d) Both a and c

Answer: d) Both a and c


8. Which of the following C functions is used to allocate memory dynamically?
a) malloc()
b) alloc()
c) calloc()
d) Both a and c

Answer: d) Both a and c


9. In C, which header file is required for input-output operations?
a) stdio.h
b) conio.h
c) iostream.h
d) inputoutput.h

Answer: a) stdio.h


10. What is the default value of a static variable in C?
a) 0
b) -1
c) Undefined
d) NULL

Answer: a) 0


11. Which of the following is used to exit a program in C?
a) stop();
b) break;
c) exit();
d) return;

Answer: c) exit();


12. What is the purpose of the break statement in C?
a) To end the program
b) To terminate a loop or switch statement
c) To skip a loop iteration
d) To go to the next iteration in a loop

Answer: b) To terminate a loop or switch statement


13. Which of the following is NOT a valid data type in C?
a) int
b) float
c) bool
d) char

Answer: c) bool


14. Which of the following is a valid C string?
a) “Hello”
b) ‘Hello’
c) Hello
d) (Hello)

Answer: a) “Hello”


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

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

a) 2.5
b) 2
c) 3
d) Error

Answer: b) 2


16. In C, what is the size of the char data type?
a) 1 byte
b) 2 bytes
c) 4 bytes
d) 8 bytes

Answer: a) 1 byte


17. Which of the following is used to perform a logical AND operation in C?
a) &
b) &&
c) |
d) ||

Answer: b) &&


18. 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) Error

Answer: b) 6


19. Which of the following C keywords is used to declare a constant?
a) constant
b) const
c) final
d) static

Answer: b) const


20. What is the maximum number of dimensions allowed in a C array?
a) 1
b) 2
c) 3
d) No fixed limit

Answer: d) No fixed limit


21. Which of the following is the correct way to pass a 2D array to a function in C?
a) void func(int arr[][]);
b) void func(int arr[3][3]);
c) void func(int arr[ ][3]);
d) void func(int arr[3][]);

Answer: b) void func(int arr[3][3]);


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

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

a) 4 4
b) 5 4
c) 4 5
d) 5 5

Answer: b) 5 4


23. Which of the following is used to define an inline function in C?
a) inline
b) define
c) function
d) static

Answer: a) inline


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

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

a) 1
b) 2
c) 3
d) Error

Answer: b) 2


25. Which of the following functions is used to get the length of a string in C?
a) strlen()
b) length()
c) size()
d) strsize()

Answer: a) strlen()


26. Which of the following C operators is used to access members of a structure through a pointer?
a) .
b) ->
c) *
d) &

Answer: b) ->


27. Which of the following is the correct syntax to declare a structure in C?
a) struct { int x, y; } point;
b) struct point { int x, y; };
c) struct point(int x, int y);
d) Both a and b

Answer: d) Both a and b


28. Which of the following statements is true about a union in C?
a) A union can store multiple types of data at once.
b) A union can store only one type of data at any given time.
c) A union consumes more memory than a structure.
d) A union and structure are the same in C.

Answer: b) A union can store only one type of data at any given time.


29. Which of the following C operators is used to perform the modulo operation?
a) %
b) &
c) #
d) /

Answer: a) %


30. Which of the following is NOT a valid C function declaration?
a) void func(int x);
b) int func(int x, int y);
c) func(int x, int y);
d) float func(int x);

Answer: c) func(int x, int y);

Leave a Reply