Home>Article>Backend Development> c language definition function

c language definition function

尚
Original
2019-10-23 16:39:11 30183browse

c language definition function

A function is a piece of code that can be reused to complete a certain function independently. It can receive data passed by the user or not. Functions that receive user data must specify parameters when defining them. Functions that do not receive user data do not need to be specified. Based on this, functions can be divided into parameterized functions and parameterless functions.

The process of encapsulating a code segment into a function is called function definition.

The definition of a function includes a function head (declarator) and a function block.The function header specifies the name of the function, the type of the return value, and the type and name of the parameters (if there are parameters). The statements in a function block specify what the function does. The general format of a function definition is as follows:

c language definition function

In the function header in the above format, "name" refers to the function name, and "type" contains at least one type modifier, Used to define the type of function return value. The type of the return value can be void or any object type, but cannot be an array type.

Furthermore, the type part can also contain the function modifier inline or _Noreturn, and the storage class modifiers extern and static.

Definition of parameterless function

If the function does not receive data passed by the user, it can be defined without parameters. As shown below:

dataType functionName(){ //body }

Definition of parameterized function

If the function needs to receive data passed by the user, then it must bring parameters when defining it. As shown below:

dataType functionName( dataType1 param1, dataType2 param2 ... ){ //body }

Function cannot be nested definition

To emphasize, C language does not allow nested function definition; that is, it cannot be defined in a function Another function must be defined outside of all functions. main() is also a function definition, and new functions cannot be defined inside the main() function.

The above is the detailed content of c language definition function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What does for(;;) mean? Next article:What does for(;;) mean?