Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
int a = 5; int *p = &a; printf("%d\n\n", ++*p); printf("%d\n", *p++);
++*p相当于++(*p)。但是*p++增加指针,而不是 p 指向的值。但我无法理解为什么我的代码中的 printf 语句显示相同的值“6”。这背后有什么具体的逻辑吗?
++*p
++(*p)
*p++
当然。当您*p第二次打印时,您已经在第一次调用printf().
*p
printf()
int a = 5; int *p = &a; // p = &a, *p = 5 printf("%d\n\n", ++*p); // p = &a, *p = 6 printf("%d\n", *p++); // p = &a + 1, *(p - 1) = a = 6 (still!)