+ 1

What is the difference between character array with and without null terminating character ?

25th May 2021, 9:19 AM
Krishna Kumar
Krishna Kumar - avatar
9 Respuestas
+ 3
#include <stdio.h> int main() { char string[4] = {'a','b','c',0}; printf("%s\n",string); char array[3] = {'a','b','c'}; int i; for (i=0; i<3; ++i) { printf("%c",array[i]); } return 0; }
25th May 2021, 10:24 AM
visph
visph - avatar
+ 3
a char array with a null terminating char could be safely used as a string... while without it must be handled as an array, by knowing its length ^^
25th May 2021, 9:29 AM
visph
visph - avatar
+ 1
Previously related thread, seems to be the root of the question ... https://www.sololearn.com/Discuss/2794334/?ref=app
25th May 2021, 10:32 AM
Ipang
0
visph Can u please elaborate these two cases along with a sample code for both …
25th May 2021, 10:04 AM
Krishna Kumar
Krishna Kumar - avatar