Suppose, in C language I have the following code, where pointer variable "word" points to a string literal.
const char * word = "HELLO";
Why does this works -
printf("\nword[1]: '%c'", word[1]);
printf("\nword[2]: '%c'", word[2]);
and this doesn't ?
printf("\nAddress of word[1]: %p", word[1]);
printf("\nAddress of word[2]: %p", word[2]);
word[x]has a character type and not pointer... So your format specifiers are not matching. Why do you think it should work?&word[x]to get the address for printing.printf("........\n");as opposed toprintf("\n...");.printf("\nAddress of word[1]: %p", word[1]);doesn't work, do you mean doesn't work as expected? You're not having a compilation error, are you?