- 1
Why does the array have an ending / 0, but the stringing is not necessary?C langauge
Why does the array have an ending / 0, but the stringing is not necessary?
6 Antworten
+ 4
STOP
The first one is an array of `int`.
The second one is an array of `char`. In C language, a string is an array of `char` with a null char '\0' as the string terminator (last character element in array).
The string terminator is used to signify the end of a string. Without the '\0' as the last char, computer will keep on printing the data in memory (casted as `char`) into the screen when we print the string, until a null char was located (somewhere far off).
`char` array only needs to have a string terminator '\0' when it is to be treated as a string.
+ 1
You accidentally posted 2 copies of this thread. Please remove either one to help community reduce duplicate questions 👍
+ 1
Ipang thank you, check DM please
0
Ipang int a[5]={1,2,3,4,5};
char b[5]=[a,b,c,d,'/0'];
like this
0
Ipang Is the strings aray, but the last one is 0 / and expresses the characters?
0
STOP
No problem 👌
But I have problem using DM, can't reply, only read