i have associated a pointer to a char array. I would like to print each element of the char array using the dereference pointer notation. for some reason it would only display the first letter of each element in the char array.
An ordinary character literal that contains more than one c-char is a multicharacter literal . A multicharacter literal has type int and implementation-deļ¬ned value.
so why is that when i declare a pointer to a char* i am only able to get the first letter , however if i declare a pointer to a pointer , i am able to get the full word ?
so why is that when i declare a pointer to a char* i am only able to get the first letter , however if i declare a pointer to a pointer , i am able to get the full word ?
The answer to this is yet another example of the horror of c-style strings. The short answer is the use of single ' vs double " quotation marks.
Single quotes are a single character ie an array of characters with one and only one element, double a string ie an array with one or more than one character forgetting about empty strings/characters.
So 'aa' is not only incorrect syntax, it hides the obscurity what is going on even more.
All of that is why my line 7 is different to your line 7 (aside from the obvious number of array elements)
so why is that when i declare a pointer to a char* i am
only able to get the first letter , however if i declare a pointer to a pointer ,
i am able to get the full word ?
Go to your line 7 single quotes mean a character, double quotes means a C-style string. That's why I used double quotes.