标签:形参 eval 按引用传递 ios name play 数据传递 tor 它的
1 #include <iostream> 2 using namespace std; 3 // Function prototype. The parameter is a reference variable. 4 void doubleNum(int &SrefVar); 5 int main() 6 { 7 int value = 4; 8 cout << "In main, value is " << value << endl; 9 cout << "Now calling doubleNum..." << endl; 10 doubleNum(value); 11 cout << "Now back in main, value is "<< value << endl; 12 return 0; 13 } 14 void doubleNum (int &SrefVar) 15 { 16 SrefVar *= 2; 17 }
1 #include <iostream> 2 using namespace std; 3 //Function prototypes 4 void getNum(int &); 5 int doubleNum(int); 6 int main() 7 { 8 int value; 9 // Call getNum to get a number and store it in value 10 getNum(value); 11 value = doubleNum(value); 12 // Display the resulting number 13 cout << "That value doubled is " << value << endl; 14 return 0; 15 } 16 void getNum(int &userNum) 17 { 18 cout << "Enter a number: "; 19 cin >> userNum; 20 } 21 int doubleNum (int number) 22 { 23 return number *2; 24 }
1 #include <iostream> 2 using namespace std; 3 //Function prototypes 4 void getNumber(int *); 5 void doubleValue(int *); 6 int main() 7 { 8 int number; 9 //Call getNumber and pass the address of number 10 getNumber(&number); 11 // Call doubleValue and pass the address of number 12 doubleValue(&number); 13 // Display the value in number 14 cout << "That value doubled is " << number << endl; 15 return 0; 16 } 17 void getNumber(int *input) 18 { 19 cout << "Enter an integer number: "; 20 cin >> *input; 21 } 22 void doubleValue(int *val) 23 { 24 *val *= 2; 25 }
标签:形参 eval 按引用传递 ios name play 数据传递 tor 它的
原文地址:https://www.cnblogs.com/cxc1357/p/11945728.html