Machine-translated by Google. Questions are authored in English.
Top

Discussion

Does there exist any way to make the command-line arguments available to other functions without passing them as arguments to the function?

  • A.Yes
  • B.No

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.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.