Discussion
Does there exist any way to make the command-line arguments available to other functions without passing them as arguments to the function?
Answer: A
Correct answer: Yes
The parameters of main are local to it, but their values need not stay there. The straightforward method is to copy them into file-scope variables at the top of main, after which any function in the translation unit can read them.
Some environments also expose them directly: Turbo C provides the globals _argc and _argv, and several Unix systems have equivalents. Either way the answer is yes, though the portable route is the explicit copy into globals of one's own.
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development