0
Quention on C
Why does the following piece of code display 8 the first time, but more the second. I do know that the fjrst time it acts like a pointer, but don't know anything about the second. https://code.sololearn.com/c5865583k8B8/?ref=app
5 Antworten
+ 4
Because the function doesn't take an array of chars, but a pointer to char as an argument. msg is a pointer to the first element of the char array. *msg and msg[0] are equivalent. You can change the function definition to fortune_cookie(char *msg) and it will work just the same. What the function shows is the size of a char pointer. The size may change depending on the platform, in this case it is 8
+ 2
When you pass a C string to a function like this, only a pointer to that string will be passed, and that has 8 bytes.
+ 1
The second time it shows the actual length of the string from the first character to the closing \0 character
+ 1
Oh ok, ty!
0
I do know that but why does it display more the second time??