ACtE03 · Chapter 3Programming & Applications🏛️ Past Licensure QuestionID: e36b171d
Passing a pointer to a struct as an argument to a function (void process(struct Data *ptr)) is preferred over passing by value because:
Passing a pointer to a struct as an argument to a function (void process(struct Data *ptr)) is preferred over passing by value because:
Multiple Choice Options
- A✓ Correct Option
It avoids copying large structure byte contents and enables direct modification of the original structure
- B
Structures cannot be passed by value in C
- C
It automatically converts the struct into a union
- D
It forces the struct to reside in CPU cache registers
Detailed Technical Solution & Explanation
Passing a structure pointer passes only the memory address (typically 8 bytes on 64-bit systems), avoiding costly memory copy operations for large structs and enabling the callee to modify the caller's structure directly.
Option Analysis:
•
Option A (It avoids copying large structure byt...): Correct. Main engineering reason for passing struct pointers.
•
Option B (Structures cannot be passed by value ...): False; C permits passing structs by value.
•
Option C (It automatically converts the struct ...): False.
•
Option D (It forces the struct to reside in CPU...): Pointers refer to RAM addresses.
Reference: Demo · Set 4NEC Licensure Syllabus