0
int main() {

       char txt[] = "abcdefghij";
       char *pointer = &txt[1];

/* 1*/ printf("%p\n", txt);                     //0060FF21
/* 2*/ printf("%p\n", &pointer[0]);             //0060FF26
/* 3*/ printf("%c\n", *pointer);                //b
/* 4*/ printf("%p\n", pointer + 3);             //0060FF25
/* 5*/ printf("%c\n", *(pointer + 1 - 1));      //b
/* 6*/ printf("%p\n", ++pointer);               //0060FF23
/* 7*/ printf("%c\n", *++pointer);              //d
/* 8*/ printf("%p\n", pointer);                 //0060FF24
/* 9*/ printf("%c\n", --(*pointer));            //c
/*10*/ printf("test %c\n", *pointer);           //test c
/*11*/ printf("%c\n", *pointer++);              //c
/*12*/ printf("test %c\n", *pointer);           //test e <- why ? 
/*13*/ printf("%c\n", *(&pointer[1] - 1));      //e
/*14*/ printf("%c\n", *(pointer - 3));          //b
/*15*/ printf("%c\n", *pointer);                //e
/*16*/ printf("%c\n", pointer[-1]);             //c
/*17*/ printf("%c\n", (pointer + 1)[-1]);       //e
/*18*/ printf("%ld\n", pointer - txt);          //4

       return( EXIT_SUCCESS );
}

I wanted to ask, why the *pointer at /*10*/ printf is c, then the operation *pointer++ (/*11*/ printf) prints c again, but then *pointer is e.

It makes no sense in my mind. I thought *pointer++ means *(pointer++), so pointer++ would be the address of d, and *(pointer++) would print d.

What am I doing wrong?

Nisse Engström
  • 4,738
  • 23
  • 27
  • 42

0 Answers0