C Language-Function call

Source: Internet
Author: User

Before you know what a function call is, what is a function first? A function is a self-contained unit of program code that is used to complete a particular task. Why use a function? 1) The use of functions can eliminate the duplication of code writing. 2) Facilitate the reading, modification and improvement of the program.

What is a function call? Function call is a much more concept used in program design, for example, there is a main function, function is required to calculate a+b, we can go ahead to define a custom function for the process, the function is to calculate the a+b, and then let main to call. But the invocation is principled, and the main function can call all the non-main functions, and the non-main functions can call each other, but the main function cannot be called.

In the actual project, a program is usually composed of many sub-program modules, a module to achieve a specific function, in C language, the module is represented by a function. A C program is generally composed of a main function and several other functions. The main function can call other functions, and other functions can call each other, but other functions cannot call the main function.

The general form of a function call is the function name (the argument list), the function name is the name of the function that needs to be called, and the argument list is the parameter list that calls the function to be passed to the called function according to the actual requirement, no need to pass parameters, only the parentheses are allowed, and the arguments are separated by commas.

A small example:

#include <stdio.h>

int main ()
{
int a,b,sum;
a=10;
b=24;
Sum=add (A, b); function Call, the following add function is called
printf ("sum=%d\n", sum);
}

int Add (int x,int y)//define a function
{
int z;
Z=x+y;
return (z);
}

C language-function call

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.