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'
????
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.
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
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.Originally Posted by Siddu_Kyocera
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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.
Last edited by nonoob; 03-23-2010 at 04:19 PM.