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

Discussion

What is the signature of the main function when using command line arguments ?

  • A.int main(int argc, char const *argv[]);
  • B.int main(int argc, char const **argv);
  • C.int main(int argc, char **argv);
  • D.all of the mentioned

Answer: D

Correct answer: all of the mentioned

All three declarations are acceptable. char *argv[] and char **argv are equivalent, since an array parameter decays to a pointer to its first element.

Adding const is also permitted and is arguably better practice, since the program has no business modifying the strings the environment supplied. What the standard actually requires is only that the second parameter be a char ** or something that reduces to one, which all three do.

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

Post your comment

Please log in or register to post a comment.