C + + functions

Source: Internet
Author: User

C + + function one, function introduction

A function is a method, which is a piece of code to implement a specific function

Second, function structure

return value type function name (parameter list) {

function body

}

Sum function
int sum (int a,int b) {
return a+b;
}

Forget function structure How to write, think of the main function structure, the main function will always write it

int main ()
{
}

The int description has a return value, the main description has the function name, the parentheses () description has the argument list, the curly brace {} Indicates the function body

Third, the Code
1 /*2 Function3 simple usage of functions4 */ 5#include <iostream>6 using namespacestd;7 8 //function Declaration9 intSumintAintb); Ten //Sum function One intSumintAintb) { A     returnA +b; - } -  the intMain () - { -     intans; -     //function Call +Ans=sum (3,5); -printf"%d\n", ans); +     return 0; A}

Iv. Results

8

C + + functions

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.