两个程序:
(1)#include <iostream>
#include<iomanip>
using namespace std;
void fun(int a,int b,int c)
{
a++;b++;c++;
cout<<"two:";
cout<<setw(4)<<a<<setw(4)<<b<<setw(4)<<c<<endl;
return;}
int main()
{
int i,a[3]={1,2,3};
cout<<"one:";
for(i=0;i<3;i++) cout<<setw(4)<<a[i];
cout<<endl;
fun(a[0],a[1],a[2]);
cout<<"three:";
for(i=0;i<3;i++)cout<<setw(4)<<a[i];
cout<<endl;
system("PAUSE");
}
(2)#include <iostream>
#include<iomanip>
using namespace std;
void fun(int x[],int num )
{
int i;
for(i=0;i<num;i++)x[i]++;
cout<<"two:";
for(i=0;i<num;i++)
cout<<setw(4)<<x[i];
cout<<endl;
return;}
int main()
{
int i,a[3]={1,2,3};
cout<<"one:";
for(i=0;i<3;i++) cout<<setw(4)<<a[i];
cout<<endl;
fun(a,sizeof(a)/sizeof(int));
cout<<"three:";
for(i=0;i<3;i++)cout<<setw(4)<<a[i];
cout<<endl;
system("PAUSE");
}
第一个输出的是one123 two234 three123;第二个输出的是one123 two234 three234;我想问一下为什么第二个程序的three的值储存起来了而不是123?
(1)#include <iostream>
#include<iomanip>
using namespace std;
void fun(int a,int b,int c)
{
a++;b++;c++;
cout<<"two:";
cout<<setw(4)<<a<<setw(4)<<b<<setw(4)<<c<<endl;
return;}
int main()
{
int i,a[3]={1,2,3};
cout<<"one:";
for(i=0;i<3;i++) cout<<setw(4)<<a[i];
cout<<endl;
fun(a[0],a[1],a[2]);
cout<<"three:";
for(i=0;i<3;i++)cout<<setw(4)<<a[i];
cout<<endl;
system("PAUSE");
}
(2)#include <iostream>
#include<iomanip>
using namespace std;
void fun(int x[],int num )
{
int i;
for(i=0;i<num;i++)x[i]++;
cout<<"two:";
for(i=0;i<num;i++)
cout<<setw(4)<<x[i];
cout<<endl;
return;}
int main()
{
int i,a[3]={1,2,3};
cout<<"one:";
for(i=0;i<3;i++) cout<<setw(4)<<a[i];
cout<<endl;
fun(a,sizeof(a)/sizeof(int));
cout<<"three:";
for(i=0;i<3;i++)cout<<setw(4)<<a[i];
cout<<endl;
system("PAUSE");
}
第一个输出的是one123 two234 three123;第二个输出的是one123 two234 three234;我想问一下为什么第二个程序的three的值储存起来了而不是123?