函数体

函数体 是包含指定函数行为的语句的复合语句。

语法

function-definition:
declaration-specifiersoptattribute-seqoptdeclaratordeclaration-listoptcompound-statement

/* attribute-seq 为 Microsoft 专用 */

compound-statement:/* 函数体 */
{declaration-listoptstatement-listopt}

除非另有说明,否则在函数主体中声明的变量(称为“局部变量”)包含 auto 存储类。 调用函数时,将为局部变量创建存储并执行本地初始化。 执行控制权将传递给 compound-statement 中的第一个语句并继续传递,直到执行了 return 语句或到达函数体末尾。 控制权随后返回到调用功能的点。

如果该函数返回了值,则必须执行包含表达式的 return 语句。 如果没有执行 return 语句或 return 语句不包含表达式,则函数的返回值是未定义的。

请参阅

C 函数定义