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

Source: Internet
Author: User
Tags integer numbers

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 ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.