- #include <stdio.h>
- #include <stdlib.h>
- int main() {
- int a = 2;
- printf("(1)变量a的地址为%p\n",&a);
- int *p = &a;
- printf("(2)p的地址为%p,p的值(所指变量的)%p\n",&p,p);
- int *q = p;
- printf("\t执行int *q = p后:\n");
- printf("(3)q的地址为%p,q的值为(所指变量)%p\n",&q,q);
- printf("(4)p的地址为%p,p的值为(所指变量)%p\n",&p,p);
-
- //选项A p = q
-
- p = q;
- printf("\t执行p = q后:\n");
- printf("(A)q的地址为%p,q的值为(所指变量)%p\n",&q,q);
- printf("(A)p的地址为%p,p的值为(所指变量)%p\n",&p,p);
-
-
-
- //选项B *p = *q
-
- //*p = *q;
- //printf("\t执行*p = *q后:\n");
- //printf("(B)q的地址为%p,q的值为(所指变量)%p\n",&q,q);
- //printf("(B)p的地址为%p,p的值为(所指变量)%p\n",&p,p);
-
-
-
- //选项C a = *q
-
- //a = *q;
- //printf("\t执行a = *q后:\n");
- //printf("(C)q的地址为%p,q的值为(所指变量)%p\n",&q,q);
- //printf("(C)p的地址为%p,p的值为(所指变量)%p\n",&p,p);
-
-
-
- //选项D q = a
-
- //q = a;
- //printf("\t执行q = a后:\n");
- //printf("(D)q的地址为%p,q的值为(所指变量)%p\n",&q,q);
- //printf("(D)p的地址为%p,p的值为(所指变量)%p\n",&p,p);
- return 0;
- }
复制代码 |
|