C
Chapman
Some questions about strings: this is the extracted piece of my test code:
/** **/
char *arry;
arry = malloc(30*sizeof(arry));
arry[0] = 'B';
arry[1] = 'S';
arry[2] = 'c';
/** **/
The questions are:
1. Now does the variable arry contain the null character immediately because
of malloc?
2. or I should append '0' at arry[3] ? (which in fact what I did next, but
when testing the compiler without '\0', it worked (??)
Because in both cases (whether I append '\0' or not), if I use the
functions atoi or any other string functions, the compiler
does not give warning or error message, what happened?
Thanks in advance
/** **/
char *arry;
arry = malloc(30*sizeof(arry));
arry[0] = 'B';
arry[1] = 'S';
arry[2] = 'c';
/** **/
The questions are:
1. Now does the variable arry contain the null character immediately because
of malloc?
2. or I should append '0' at arry[3] ? (which in fact what I did next, but
when testing the compiler without '\0', it worked (??)
Because in both cases (whether I append '\0' or not), if I use the
functions atoi or any other string functions, the compiler
does not give warning or error message, what happened?
Thanks in advance