The basic difference between in a character array and an integer array is the terminating null character : \0
If you declare your character array like this :
char b[] = {'h','i'};
Then your cout
statement fails to identify what to do, and will give strange output. But as soon as you do :
char b[] = {'h','i','\0'};
or
char b[] = "hi";
Your cout
works fine. This is because in first, you are explicitly adding a null character at the end, and in the second, it gets added automatically by the compiler.
And for the array, and array declared as a[]
or a[][]
, the compiler stores the address of the first element of the array in variable a
, so you get the address of the first element in case of an non-character array.
Refer to this link for more info :
What is the difference between int and char arrays?