What is the meaning of the value placed between braces in char str []?

To be clear, I do not set the difference between char * str and char str []. I'm even more new. I am implementing the following code:

// Convert long long to string 
    char number_str[];
    sprintf(number_str, "%lld", number_ll);

When I run printf("%s\n", number_str);, it spills out the correct number, regardless of whether I put 2 or 256 between these brackets. What makes me ask what these brackets are for?

I was exposed char str[]in this post .

+4
source share
2 answers

printf("%s\n", number_str);, , , 2 256 . , ?

, undefined . .

, char str[]?

, . , , .. ( ), .

+3

[ ] .

:

char number_str[];
sprintf(number_str, "%lld", number_ll);

. , ; - sprintf .

:

char number_str[100];
sprintf(number_str, "%lld", number_ll);

number_str, 100 char . :

char number_str[3];
sprintf(number_str, "%lld", number_ll); /* let say number_ll == 12345 */

, undefined. sprintf 6 3- .

C . , , , , .

- :

extern char array[];

, array, ( ) char .

( ) , , :

void func(char param[42]) {
    /* param is a pointer; the 42 is silently ignored */
}

, - . . 6 comp.lang.c FAQ.

+2

All Articles