指针和引用的区别
时间:2011-03-03 来源:香山飘雪
引用就是变量的别名。
1 #include <stdio.h>
2
3 //reference is nickname of the variable.
4 //pointer is address of variable.
5 int _tmain(int argc, _TCHAR* argv[])
6 {
7 int x = 1000;
8 int * pointer = &x;
9 int & reference = x;
10 //
11 printf("-----------------values-----------------------------\n");
12 printf("variable value: 0x%08x\n", x);
13 printf("reference value: 0x%08x\n", reference);
14 printf("pointer value: 0x%08x\n", (int)(pointer));
15
16 printf("-----------------address----------------------------\n");
17 printf("variable address: 0x%08x\n", &x);
18 printf("reference address: 0x%08x\n", &reference);
19 printf("pointer address: 0x%08x\n", &pointer);
20
21 printf("-----------------------------------------------------\n");
22 //
23 return 0;
24 }
相关阅读 更多 +