1. What is the size of the int
data type in C typically on a 32-bit system?
A) 2 bytes
B) 4 bytes
C) 8 bytes
D) Depends on the compiler
Answer: B) 4 bytes
2. Which operator is used for modulus operation in C?
A) %
B) &
C) ^
D) /
Answer: A) %
3. How many times will the loop for(int i=0; i<5; i++)
execute?
A) 4
B) 5
C) 6
D) 0
Answer: B) 5
4. What is the default return type of a function in C if not specified?
A) void
B) int
C) float
D) Compilation error
Answer: B) int
5. Which is the correct way to initialize an array?
A) int arr[] = {1, 2, 3};
B) int arr[3] = [1, 2, 3];
C) int arr[3] = {1; 2; 3};
D) array arr = {1, 2, 3};
Answer: A) int arr[] = {1, 2, 3};
6. A pointer variable stores:
A) A value
B) An address
C) A data type
D) A memory size
Answer: B) An address
7. How is a string terminated in C?
A) \0
B) \n
C) \t
D) ;
Answer: A) \0
8. Which operator is used to access structure members?
A) .
B) ->
C) ::
D) ,
Answer: A) .
9. Which mode opens a file for reading in C?
A) "w"
B) "r"
C) "a"
D) "x"
Answer: B) "r"
10. Which function dynamically allocates memory in C?
A) malloc()
B) calloc()
C) realloc()
D) All of the above
Answer: D) All of the above
11. What does the #include
directive do?
A) Includes a source file
B) Includes a header file
C) Links a library
D) Defines a macro
Answer: B) Includes a header file
12. The ternary operator in C is:
A) ?:
B) &&
C) ||
D) !!
Answer: A) ?:
13. A variable defined inside a function has:
A) Global scope
B) Local scope
C) Static scope
D) File scope
Answer: B) Local scope
14. What is the output of printf("%d", 10 == 10);
?
A) 10
B) 1
C) 0
D) Compilation error
Answer: B) 1
15. Which is NOT a valid loop in C?
A) for
B) while
C) do-while
D) repeat-until
Answer: D) repeat-until
16. Which header is required for printf()
?
A) <conio.h>
B) <math.h>
C) <stdio.h>
D) <stdlib.h>
Answer: C) <stdio.h>
17. What is sizeof(float)
typically?
A) 2 bytes
B) 4 bytes
C) 8 bytes
D) Compiler-dependent
Answer: B) 4 bytes
18. Which is a valid function declaration?
A) void func();
B) func() void;
C) void func
D) func();
Answer: A) void func();
19. What is NULL
in C?
A) 0
B) A macro for void pointer
C) Both A and B
D) An integer
Answer: C) Both A and B
20. What does strlen("Hello")
return?
A) 5
B) 6
C) 4
D) Undefined
Answer: A) 5
21. Which function is used to compare two strings in C?
A) strcomp()
B) strcmp()
C) compare()
D) string_cmp()
Answer: B) strcmp()
22. What will be the value of x
after x = 5 / 2;
in C?
A) 2.5
B) 3
C) 2
D) Compilation error
Answer: C) 2
23. How do you define a constant in C?
A) #define PI 3.14
B) const float PI = 3.14;
C) Both A and B
D) None of the above
Answer: C) Both A and B
24. Which keyword is used to exit from a loop in C?
A) exit
B) continue
C) break
D) stop
Answer: C) break
25. What does void*
represent in C?
A) A function pointer
B) A pointer to any type
C) A void function
D) None of the above
Answer: B) A pointer to any type