CDAC Pre-CAT C Programming Practice Questions with Answers
1. What is the output of the following code snippet?
int main() {
printf("%d", sizeof('A'));
return 0;
Answer: 4
2. Which of the following is a valid variable name in C?
A) int B) 2value C) _count D) main()
Answer: C) _count
3. What will be the result of the following expression?
int a = 5;
int b = 2;
float c = a / b;
Answer: c = 2.0
4. Which operator has the highest precedence?
A) * B) ++ C) = D) &&
Answer: B) ++
5. Predict the output:
int i = 0;
for(; i < 3; i++);
printf("%d", i);
Answer: 3
6. Which of the following is not a loop in C?
A) for B) while C) do-while D) repeat-until
Answer: D) repeat-until
7. What will be the output?
char str[] = "CDAC";
printf("%c", str[2]);
Answer: A
8. Which of the following declares an array of 10 integers?
A) int arr[10]; B) int arr(); C) int[10] arr; D) array int[10];
Answer: A) int arr[10];
9. Which is correct to declare a function that returns an int and takes two float arguments?
A) int func(float, float); B) float func(int, int); C) int func(int, float); D) void func(float, float);
Answer: A) int func(float, float);
10. What is the output?
int func(int x) {
if(x == 0) return 0;
return x + func(x - 1);
printf("%d", func(3));
Answer: 6
11. What does the following print?
int a = 10;
int *p = &a;
printf("%d", *p);
Answer: 10
12. Which is true about pointers in C?
A) * declares a pointer B) & gives address C) Pointers store addresses D) All of the above
Answer: D) All of the above
13. Which keyword is used to define a structure in C?
A) union B) typedef C) struct D) enum
Answer: C) struct
14. What will be the size of the following structure?
struct sample {
int a;
char b;
};
Answer: Likely 8 bytes
15. Which function is used to open a file in C?
A) fopen() B) open() C) file_open() D) read()
Answer: A) fopen()
16. Which mode opens the file for both reading and writing?
A) "r" B) "w" C) "rw" D) "r+"
Answer: D) "r+"
17. Which of the following is used to allocate memory dynamically?
A) malloc() B) alloc() C) memalloc() D) None
Answer: A) malloc()
18. What happens if you forget to free memory allocated with malloc()?
Answer: Memory leak occurs
19. What is the purpose of #include<stdio.h>?
Answer: To include standard input/output functions like printf() and scanf()
20. Which of the following is a valid comment in C?
A) // This is a comment B) /* This is a comment */ C) Both A and B D) None of the above
Answer: C) Both A and B