/*
* Copyright (c) 2014, 烟台大学计算机学院
* All rights reserved.
* 文件名称:test.cpp
* 作 者:刘畅
* 完成日期:2014 年 12 月 3 日
* 版 本 号:v1.0
*
* 问题描述:阅读下列程序;
* 输入描述:啥也不用输;
* 程序输出:输出该输出的。
。
(1)
#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;
}
运行结果:
(2)
#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;
}
运行结果: