What is the difference between calloc() and malloc()?
Acalloc() initializes memory to zero, malloc() does not
Bmalloc() is faster than calloc()
Ccalloc() takes two arguments, malloc() takes one
DAll of the above
Correct Answer:
D. All of the above
Explanation:
calloc(n, size) allocates n blocks of size bytes and initializes to 0. malloc(size) allocates size bytes without initialization. calloc() is typically slower due to initialization.
What does the static keyword do when used with a global variable?
AMakes it accessible only within the same file
BMakes it a constant
CIncreases its memory allocation
DMakes it thread-safe
Correct Answer:
A. Makes it accessible only within the same file
Explanation:
When static is used with a global variable, it restricts its scope to the file where it is declared. Without static, global variables are accessible across files using extern.
What is the difference between declaration and definition in C?
AThey are the same thing
BDeclaration informs compiler about type, definition allocates memory
CDefinition comes before declaration
DDeclaration is only for functions
Correct Answer:
B. Declaration informs compiler about type, definition allocates memory
Explanation:
Declaration tells the compiler about a variable's name and type (e.g., 'extern int x;'). Definition actually allocates memory (e.g., 'int x = 5;'). A variable can be declared multiple times but defined only once.