* pointer ++跳过一个char?

时间:2017-05-09 16:01:47

标签: c pointers

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 );
}

我想问一下,为什么*pointer /*10*/ printfc,然后操作*pointer++/*11*/ printf)再次打印c ,然后*pointere

在我看来没有任何意义。我想 *pointer++表示*(pointer++),因此pointer++将是d的地址,*(pointer++)会打印d

我做错了什么?

0 个答案:

没有答案