Just contacted C, array declaration problem

Can

C declare dynamic arrays? As far as I know, it doesn"t work. You must specify size
. For example, the following will report an error

.
string name[];

then the parameters of, command line implement the declaration of dynamic array in the following main function

int main(int argc, string argv[])
{

}

Please advise

C
Mar.19,2021

the [] that appears in the parameters of the function is actually a pointer.
is equivalent to int main (int argc, string * argv) in terms of the example you gave


The

array can be thought of as the syntax sugar of the pointer to some extent. So the dynamic array is actually

.
char *name = malloc(100);

// when you need to extend your string
name = realloc(name, 200);
The length of

argv is actually similar to that of a string, which is marked by the last '\ 0' . You can imagine that the system realloc has just enough memory.

Menu