What is the size in bytes of these? str[]="hey"; str2[]={'h','e','y'} and str3[]="h";?

What is the size in bytes of these?

str[]="hey";

str2[]={'h','e','y'}

and

str3[]="h";?

Thanks :)
Try running the sizeof function:

1
2
3

cout << "The sizeof str is " << sizeof( str ) << "." << endl;
I don't have a C++ editor running currently. That's why I asked :P
str[]="hey"; is treated as a null terminates string, so the array has one extra byte to hold the null (character zero).

str2[]={'h','e','y'} is an array of exactly three characters, there is no null terminator.
Topic archived. No new replies allowed.