If I have a string like this:
char myString [5];
But I didn't put any characters into the array
does it mean:
myString [0] = '\0'
myString [1] = '\0'
myString [2] = '\0'
myString [3] = '\0'
myString [4] = '\0'
????
Printable View
If I have a string like this:
char myString [5];
But I didn't put any characters into the array
does it mean:
myString [0] = '\0'
myString [1] = '\0'
myString [2] = '\0'
myString [3] = '\0'
myString [4] = '\0'
????
No. It means you can't know for sure what it does contain until you initialize it to something.
yep, vart said it right. but just a note:
inside of doing that, you could simple use the first line of code. sinceCode:myString [0] = '\0'
myString [1] = '\0'
myString [2] = '\0'
myString [3] = '\0'
myString [4] = '\0'
C stops processing a string after reaching the \0 sign.
How about following code?
Regards,Code:
static char myString [5];
Siddu
myString would have static storage duration, thus it would be zero initialised.Quote:
Originally Posted by Siddu_Kyocera
As long as the string is defined globally, it's same as static and is initialized to zeroes. If it's defined inside a function then its memory is the stack. It is not zeroed out when the function is executed.