Untitled

Untitled

Untitled

Untitled

Untitled

Untitled

Untitled

Untitled

Untitled

Untitled

#include<stdio.h>
#include<stdlib.h>
int main(void){
	int *ptr,num = 20;
	
	ptr=&num;
	printf("num=&d, &num=%p\\n",num,&num);
	printf("*ptr = %d, ptr = %p, &ptr = %p\\n",*ptr,ptr,&ptr);
	system("pause");
	return 0;
}

Untitled

Untitled

Untitled

#include <stdio.h>
int main(void){
	int a = 7;
	int *aPtr = &a;
	printf("The address of a is %p" "\\nThe value of aPtr is %p", &a, aPtr);
	printf("\\n\\nThe value of a is %d" "\\nThe value of *aPtr is %d", a, *aPtr);
	printf("\\n\\nShowing that and & are complements of ""each other\\n&*aPtr = %p""\\n&aPtr = %p\\n", &*aPtr, &aPtr);
}

Untitled

7.10第11頁 摘要指標運算子& 和 的使用方法  在大多數的平台中,printf內的轉換指定詞%p會將記憶體位址以十六進制數印出。  請注意,在程式的輸出中,a的位址和aPtr的値印出來的結果是一樣的,由此驗證了a的位址確實會設定給指標變數aPtr(#8)。還有,&和這兩個運算子彼此是互補的,當他們同時連續應用到aPtr時(#18),可以看到相同的列印結果。輸出中顯示的位址會因系統而異

Untitled

pass by referece