I'm currently trying to learn C, with some prior experience in Python and pointer arithmetic is really confusing me right now.
#include <stdio.h>
int main()
{
char *s[] = {"String1", "Literal2", "Pointers3"};
printf("%c", s[1]+1);
return 0;
}
Why does it print m instead of i ?
When I replace the format string with %s it does what I expect and prints out iteral2(Go to the 0th index of the 1st string literal then move 1 memory adress forward and print the rest).
How does this work, why does it print out a seemingly arbitrary character instead of the 1st(or 1th?) index when I use the %c format string.
printfthe address ofs[1]and add 1 to that adress. You still need to dereference that:*(s[1]+1).%cexpects the actual value. You need to de-reference the argument:*(s[1]+1)