對於下面的代碼值* IP的印刷,因爲它指向的變量的地址
int main()
{
int x = 2;
int *ip = &x;
printf("%d",*ip); // Printing the value of *ip gives 2
//Now if the value of ip is incremented
ip++;
printf("%d",*ip); //Printing the value of *ip gives the incremented memory
}
可有人請,如何的*ip
值越來越打印爲增加的內存位置說明。 *ip
作爲參照運算符應該返回地址右邊的值嗎?
啓用所有編譯器警告,看看是否有幫助。 –
你的意思是做'(* ip)++'嗎?我假設你想通過你的指針增加'x',而不是增加你的指針。 –
int * ip = x實際上意思是,將ip聲明爲int指針,並將ip(它是int)的值賦給ip(這是一個指向int的指針) –