In a quiz today, we got this as our question2.
After seeing this, most of us believe that we will fail quite badly.
#include <stdio.h>
int main ( ) {
char str[] = "StanfordIsGreat";
char *ptr = str;
printf("%s", ptr);
printf("%s", ptr + 8);
printf("%s", ptr + 'l' - 'b');
printf("%s", ptr + 'k' - ptr[3]);
}
So can anyone guide me answer this question?
what i applied for 1st printf was that the actual string will be printed StanfordIsGreat
for 2nd printf, i think the pointer will shift 8 indexes to the right generating IsGreat
for 3rd printf, ptr + 'l' gave me StanfordIsGreatl, i didn't understand what - 'b' meant
for 4rth printf ptr + 'k' was same as above and ptr[3] stands for 'a' so i wrote StnfordisGretk
i am really confused about 3rd and 4rth, can someone guide me, so i can learn and not make mistakes like this for future quizes.