09-Dark Horse Programmer------C language Learning notes---C language functions

Source: Internet
Author: User

Dark Horse programmer------<a href= "http://www.itheima.com" target= "blank" >java training, Android training, iOS training,. NET training </a>, look forward to communicating with you! -------

A function definition

01 functions are divided into library functions and custom functions.

Function General format:

The function returns a value type function name (data type parameter 1, data type parameter 2, ...)

{

function body;

}

* If the function does not need to return a value type, it is represented by void

* The mark of the function is the parentheses, regardless of the parameters, the parentheses exist

* When defining a function, you should not add a semicolon after the closing parenthesis

* Do not define the variables that appear in the parameter list again in the function list

* Multiple parameters are separated by commas, even if the data type is the same, it cannot be declared at the same time, that is, the data type and parameters must appear in pairs

//expression k!/(m!+n!) The value#include<stdio.h>DoubleFactintf) {    inti; DoubleR =1;  for(i=1; i<f;i++) {R= r*i; returnR; }}intMain () {intK,m,n; Doublef1,f2,f3; printf ("Please enter a three integer: \ n"); scanf ("%d%d%d",&k,&m,&N); F1=fact (k); F2=fact (m); F3=fact (n); printf ("k!/(m!+n!) =%f\n", f1/(f2+f3)); }

Two function calls

01 general form of function invocation:

function name (actual parameter table) if the called function has no arguments, the "actual parameter table can be empty"

02 parameter passing between functions

The rules of C are simple, all the parameters of the C-language function are passed in the "call-to-value" mode, and the parameter passing direction is always passed to the formal parameter.

03 Return value of function

return expression;

The function of the return statement is to immediately end the execution of the current function and return to the keynote function.

//enter two integers to calculate their average, requiring the calculation of the average value with a function#include<stdio.h>DoubleAverageintXinty);intMain () {intb; Doubleresult; printf ("Please enter a two integer: \ n"); scanf ("%d%d",&a,&b); Result=average (A, b); printf ("the average of%d and%d is%f\n", A,b,result); return 0;}DoubleAverageintXinty) {    DoubleAve; Ave= (x+y)/2; returnAve;}

09-Dark Horse Programmer------C language Learning notes---C language 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.