一个让人糊涂的问题
											 程序代码:
程序代码:
#include <iostream>
using namespace std;
int main( )
{
    void sort(int x, int y, int z);                    //声明函数 sort
    int x,y,z;
    cin >> x >> y >> z;
    sort( x,y,z);
    system("pause");
    return 0;
}
void sort(int x,int y,int z)
{
    int temp;
    if( x > y) { temp = x;x = y;y = temp;}
    if( z < x) cout << z << ',' << x << ',' << y << endl;
    else if( z < y) cout << x << ',' << z << ',' << y << endl;
    else cout << x << ',' << y << ',' << z << endl;
}
#include <iostream>
using namespace std;
int main( )
{
    void sort(int a, int b, int c);                    //声明函数 sort
    int a,b,c;
    cin >> a >> b>> c;
    sort( a,b,c);
    system("pause");
    return 0;
}
void sort(int x,int y,int z)
{
    int temp;
    if( x > y) { temp = x;x = y;y = temp;}
    if( z < x) cout << z << ',' << x << ',' << y << endl;
    else if( z < y) cout << x << ',' << z << ',' << y << endl;
    else cout << x << ',' << y << ',' << z << endl;
}
    上面两段代码,大家应该看得很清楚,都是经过编译的,结果也一样。上面那一段,给人的感觉好像对 int x,y,z;三个数给予了重复定义,因为在主函数里定义了int x,y,z; 又在定义函数时,在函数参数里也有 int x,y,z; 请问这种情况到底算不算重复定义?我想应该不算,否则通不过编译,但这种写法跟下面的写法相比,究竟都是对的呢,还是存在什么问题?我觉得上面的写法让人犯糊涂,下面的写法要清楚一些。
[ 本帖最后由 hmsabc 于 2010-8-18 22:25 编辑 ]

 
											





 
	    





