Let's say I have
char *names[] = { "Tom", "Jerry" };
and I want to print the "e" in "Jerry" using printf
. My first instinct was
printf("%c\n", *names[5]);
but when I applied what I've been learning about pointers, I realized this is total junk code because the 5 refers to the nonexistent fifth pointer in names
, not the "e" in "Jerry". The pointers contained in names
will only ever refer to the memory addresses of the first characters in their respective strings.
So it seems what I really need to do is to add one byte to names[1]
to point to, and print the "e" in "Jerry". But I'm not sure how to do this, or whether it's even allowed in C.
What is the best way to accomplish this? Thank you in advance.