/*
* Copyright (c) 2014, 烟台大学计算机学院
* All rights reserved.
* 文件名称:test.cpp
* 作 者:呼亚萍
* 完成日期:2014年 12 月 4日
* 版 本 号:v1.0
*
* 问题描述:阅读程序,用课堂上老师讲课的方式,将变量对应内存的“框子”画出来,用大脑当CPU,写出变量的变化过程;
* 输入描述:相应的程序
* 程序输出:程序的运算结果
*/
#include <iostream>
using namespace std;
int sub(int*);
int main()
{
int i, k;
for (i=0; i<4; i++)
{
k=sub(&i);
cout<<"sum="<<k<<'\n';
}
cout<<"\n";
return 0;
}
int sub(int *s)
{
static int t=0;
t=*s + t;
return t;
}
运算结果:
#include <iostream>
using namespace std;
int *p;
void pp(int a, int *b);
int main()
{
int a=1, b=2, c=3;
p=&b;
pp(a+c, &b);
cout<<"(2)"<<a<<','<<b<<','<<*p<<endl;
return 0;
}
void pp(int a, int *b)
{
int c=4;
*p=*b+c;
a=*p-c;
cout<<"(1)"<<a<<','<<*b<<','<<*p<<endl;
}
知识点总结:
指针的应用,全局变量与局部变量的应用
学习心得:
学会单步执行与阅读程序能够帮助我们更好地掌握知识,好好读程序,加油!