黑马程序员技术交流社区
标题:
指针基础分享
[打印本页]
作者:
XiaoBaoMi
时间:
2015-6-29 22:10
标题:
指针基础分享
#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;
}
复制代码
作者:
mazhichao
时间:
2015-6-30 19:26
学习了~
作者:
张国繁
时间:
2015-6-30 21:13
好吧,整理的挺详细
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2