When I run
char * a = "string";
char * b = a;
while (*a != '\0')
printf("%p %c\n", *(a), *(a++));
printf("%p\n", *(b+2));
The output looks like
0x73 s
0x74 t
0x72 r
0x69 i
0x6e n
0x67 g
0x72
Also,how does the program figure out that (b+2) is located at 0x72. I thought it would just add 2 to the starting address of b, in this case 0x73.
Edit: This isn't a case of unspecified behaviour. As explained in the answers, I was mistakenly passing the value to the address format specifier instead of the pointer itself.