I need help determining the size of a char array. I get confused when asked "How many chars does this char array store?"
For example:
char bacon[6]
Allocates 6 spaces for storage, but does it hold 5 or 6 chars?
I've used strlen and sizeof, but I'm not sure which to refer to. Also, when I use strlen and size of on this code, I get two different values.
char pancakes[] = {'s','y','r','u','p'}
For sizeof I get 5, and strlen I get 19. I'm not sure where 19 is coming from.
In your first example, char bacon[ 6 ], that code declares an array that will hold up to six characters; however, if you want to use strlen() or any of the functions that work on "C" strings (null-terminated character arrays), it should hold at most five characters and a null byte.
BTW, the positions that are valid for your example are these:
char bacon[ 0 ][ 1 ][ 2 ][ 3 ] [ 4 ][ 5 ]
In your pancakes example, the compiler will create an array of five characters, since you initialized each position with a single character. The compiler doesn't add a null byte in this case.