ACtE03 · Chapter 3Programming & Applications🏛️ Past Licensure QuestionID: 5bbfb5f2
What occurs when the following code snippet is compiled in C?
Cprintf("%d", a = &10);
What occurs when the following code snippet is compiled in C?
C
printf("%d", a = &10);Multiple Choice Options
- A
Prints the value 10
- B
Prints the memory address of 10
- C✓ Correct Option
Compile-time syntax error (lvalue required as unary '&' operand)
- D
Runtime segmentation fault
Detailed Technical Solution & Explanation
The unary address-of operator & requires an lvalue (an object that occupies an identifiable location in memory, such as a variable). The literal 10 is an rvalue (temporary literal constant); therefore, &10 causes a compile-time error: 'lvalue required as unary & operand'.
Option Analysis:
•
Option A (Prints the value 10): Incorrect; code fails compilation.
•
Option B (Prints the memory address of 10): Literals do not have accessible persistent addresses in this syntax.
•
Option C (Compile-time syntax error (lvalue req...): Correct. Address-of operator cannot be applied to an rvalue literal.
•
Option D (Runtime segmentation fault): The error is caught at compile-time, so no executable is generated.
Reference: Demo2 · Set 1NEC Licensure Syllabus