Function Body

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Function Body.

A "function body" is a compound statement containing the statements that specify what the function does.

function-definition:
declaration-specifiers optattribute-seq optdeclarator declaration-list optcompound-statement

/* attribute-seq is Microsoft Specific */

compound-statement: /* The function body */
{  declaration-list optstatement-list opt}

Variables declared in a function body, "local variables," have auto storage class unless otherwise specified. When the function is called, storage is created for the local variables and local initializations are performed. Execution control passes to the first statement in compound-statement and continues until a return statement is executed or the end of the function body is encountered. Control then returns to the point at which the function was called.

A return statement containing an expression must be executed if the function is to return a value. The return value of a function is undefined if no return statement is executed or if the return statement does not include an expression.

C Function Definitions

Show: