本帖最后由 hero200521296bj 于 2015-3-13 16:30 编辑
void Change(int *p){ *(p-1) = 5; *(p-2) = 8; }
int main(int argc, const char * argv[]) { int a = 10,b = 20,c =30; printf("a = %d,b = %d,c = %d\n",a,b,c); Change(&a); printf("a = %d,b = %d,c = %d\n",a,b,c);
}
运行的结果如下: a = 10,b = 20,c = 30
a = 10,b = 5,c = 8
主函数里并没有给b、c赋值,但是通过指针p-1,p-2的地址真的可以改变b、c的值,是因为连续定a,b,c吗?
|