- 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?

24th Mar 2021, 9:01 AM
STOP
STOP - avatar
6 Answers
+ 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.
24th Mar 2021, 9:29 AM
Ipang
+ 1
You accidentally posted 2 copies of this thread. Please remove either one to help community reduce duplicate questions 👍
24th Mar 2021, 9:14 AM
Ipang
+ 1
Ipang thank you, check DM please
24th Mar 2021, 9:37 AM
STOP
STOP - avatar
0
Ipang int a[5]={1,2,3,4,5}; char b[5]=[a,b,c,d,'/0']; like this
24th Mar 2021, 9:18 AM
STOP
STOP - avatar
0
Ipang Is the strings aray, but the last one is 0 / and expresses the characters?
24th Mar 2021, 9:20 AM
STOP
STOP - avatar
0
STOP No problem 👌 But I have problem using DM, can't reply, only read
24th Mar 2021, 10:58 AM
Ipang