C ++ job: enter two integers and use the function to calculate the sum of the two. What is the role of function external declarations ?, Sum of two numbers
1 # include <iostream> 2 using namespace std; 3 4 int main () {5 // calculate the sum of two numbers? 6 7 8 int a, B, s; 9 cout <"enter two integer numbers:" <endl; 10 cin> a> B; 11 int sum (int x, int y); 12 s = sum (a, B); // The actual parameter, representing the specific value, in () among 13 cout <"The sum of a and B is:" <sum <endl; 14 // system ("pause"); 15 return 0; 16} 17 // first, are you sure the function requires a return value? If you want to return a value, write the return value type. If you do not need to return a value, write void 18 int sum (int x, int y) {// form parameter // the life cycle of the variable receives the value of the actual parameter int x = a, int y = B; 19 return x + y; 20}
What is the role of function external declarations?
This gives us a wider range of defined function applications and a longer life cycle. Share.
That is to say, all external functions can be called directly.
# Include <iostream> using namespace std; int sum (int x, int y); int main () {// evaluate the sum of two numbers? Int a, B, s; cout <"enter two integer numbers:" <endl; cin> a> B; s = sum (, b); // actual parameter, representing a specific value. In (), cout <"The sum of a and B is:" <sum <endl; // system ("pause"); return 0;} // first, determine whether the function requires a return value? If you want to return a value, write the return value type. If you do not need to return a value, write void int sum (int x, int y) {// format parameter // Variable Life Cycle receives the value of int x = a, int y = B; return x + y ;}