What will be printed by the following code?
#include
int main() {
int arr[5] = {1, 2, 3, 4, 5};
int *p = arr;
printf("%d %d", *(p+2), arr[2]);
return 0;
}
A3 3
B2 4
C4 3
D3 4
Correct Answer:
A. 3 3
EXPLANATION
*(p+2) accesses the element at index 2 (value 3), and arr[2] also accesses index 2 (value 3). Both print 3.
Which of the following about register variables is TRUE?
AThey must be initialized
BThey are faster to access than normal variables
CThey cannot be pointers
DThey are stored in RAM
Correct Answer:
B. They are faster to access than normal variables
EXPLANATION
register keyword suggests the compiler to store the variable in CPU register for faster access. Modern compilers often ignore this hint. You cannot take address of register variables.
Correct Answer:
A. Variable value can change unexpectedly
EXPLANATION
volatile tells the compiler that a variable's value can change unexpectedly (e.g., in hardware registers or interrupt handlers), so it should not optimize away repeated reads.