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

Discussion

Which is the correct form to declare main with command line arguments ?

  • A.int main(int argc, char argv[]){ }
  • B.int main(int argc, char* argv[]){ }
  • C.int main(int argc, char** argv){ }
  • D.int main(int* argc, char* argv[]){ }

Answer: B

Correct answer: int main(int argc, char* argv[]){ }

This is the conventional form: an int count followed by an array of char *, each pointing at one argument string.

char **argv is exactly equivalent, since an array parameter decays to a pointer to its first element - the third option is therefore also correct in practice, and only one answer being expected here, the array notation is the canonical spelling. char argv[] would be an array of single characters, and int *argc a pointer where a count is wanted.

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

Post your comment

Please log in or register to post a comment.