What is the type of command-line argument `argv` in C?

前端 未结 6 1002
广开言路
广开言路 2020-12-28 17:45

I\'m reading a section from C Primer Plus about command-line argument argv and I\'m having difficulty understanding this sentence.

It says that,

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-28 18:01

    This thread is such a train wreck. Here is the situation:

    • There is an array with argc+1 elements of type char *.
    • argv points to the first element of that array.
    • There are argc other arrays of type char and various lengths, containing null terminated strings representing the commandline arguments.
    • The elements of the array of pointers each point to the first character of one of the arrays of char; except for the last element of the array of pointers, which is a null pointer.

    Sometimes people write "pointer to array of X" to mean "pointer to the first element of an array of X". You have to use the contexts and types to work out whether or not they actually did mean that.

提交回复
热议问题