【发布时间】:2021-11-09 04:46:12
【问题描述】:
#include <stdio.h>
int main(void) {
int x = 5;
int y = 10;
int* px = &x;
int* py = &y;
printf("the adress of %d is %p.\n",x,px);
printf("the adress of %d is %p.\n",y,py);
*px = 8;//change the value at the adress of px
*py = 18;
//what happens if instead of *px = 8, just x = 8?
x = 99;
printf("the adress of %d is %p.\n",x,px);
printf("the adress of %d is %p.\n",y,py);
//so It did change, what's the point of using *px when changing the value?
return 0;
}
您好,我在学校开始学习C,遇到了一个可能非常简单的困难,但目前我不知道。 我正在尝试更改 x 的值,我首先使用方法 *px = 8 来更改它。 但是在那之后我使用了x = 99,它也改变了,所以我不知道它们之间有什么区别。 感谢您的任何反馈,谢谢!
【问题讨论】: