Program 1.1

C ++ test program 1.2.1

Understand the following procedures, see the results and run under VC ++ 6.0, answer the questions at the end of the program.

#include <iostream>

using namespace std;

int max_def(int x, int y)

{

return (x>y?x:y);

}

max_def you (you x, y you, you z)

{

int temp = 0;

return (temp=(x>y?x:y))>z?temp:z;

}

double max_def(double x, double y)

{

return (x>y?x:y);

}

int main ()

{

int x1 = 0;

int x2 = 0;

double d1 = 0.0;

double d2 = 0.0;

x1 = max_def(5,6);

x2 = max_def(2,3,4);

d1 = max_def(2.1,5.6);

d2 = max_def(12.3,3.4,7.8);-----------------------------------------------------①

cout<<"x1="<<x1<<endl;

cout<<"x2="<<x2<<endl;

cout<<"d1="<<d1<<endl;

cout<<"d2="<<d2<<endl;--------------------------------------------------------②

return 1;

}

Question 1: The output of the above program what is?

x1=6

x2 = 4

D1 = 5.6

d2=12

Second problem: what circumstances can participate overloaded function?

It has the same function name, functions of different argument list

Question three: ① at which function is called?

max_def you (you x, y you, you z)

Question 4: The output ② at why d2 = 12, rather than d2 = 12.3?

Type of the function parameter is an integer parameter from the "double" to type "int" type.

Reproduced in: https: //www.jianshu.com/p/babe4126af46

Guess you like

Origin blog.csdn.net/weixin_34415923/article/details/91252745