- 37
- 0
- 约6.96千字
- 约 15页
- 2018-03-27 发布于河南
- 举报
实验8 指针及其应用
实验八 指针及其应用
【实验目的】
1.理解指针概念、求变量地址和指针寻址操作,掌握指针的各种运算方法。
2.掌握指针作为函数参数,实现函数与被调用函数之间数据传递的方法。
3.理解指针与数组的关系,掌握运用指针访问数组元素的方法。。
【实验内容】
一、读程序,运行程序,解释程序结果。
程序1:
#include stdio.h
main()
{
int x,y,*pt1,*pt2,t1,t2,t3;
x=8;
y=4;
pt1=x;
pt2=y;
t1=*pt1**pt2 -11;
t2=3*-*pt2+*pt1+5;
printf(Address of x =%u\n,pt1);
printf(Address of y =%u\n,pt2);
printf(\n);
printf(x=%d,y=%d\n,x,y);
printf(t1=%d,t2=%d\n,t1,t2);
*pt1=*pt2+7;
*pt2=*pt1-6;
t3=*pt1**pt2+3;
printf(\n);
printf(x=%d,y=%d\n,x,y);
printf(t3=%d\n,t3);
}
程序2:
#include stdio.h
main()
{
int *pt, tot=0,i;
int x[5]={6,7,8,9,10};
i=0;pt=x;
p
原创力文档

文档评论(0)