Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

functions and parameters — concept C23

A function has a declared result type and typed parameter list; arguments pass by value, so modifying the caller’s object requires a valid pointer. A compatible prototype must be visible before the call, recursion needs a terminating case, and a returned pointer must not designate an expired automatic object.

Version: C23

Syntax

functions and parameters

A function has a declared result type and typed parameter list; arguments pass by value, so modifying the caller’s object requires a valid pointer. A compatible prototype must be visible before the call, recursion needs a terminating case, and a returned pointer must not designate an expired automatic object.

Design a function around one contract: input parameters as values or const pointers, output parameters only when one result is insufficient, and an error status separate from data. Pass arrays as pointer plus length because an array parameter adjusts to a pointer.

Check NULL, zero length, overlapping arguments, and two parameters designating the same object. A pointer-returning function must state ownership and lifetime; a callback needs a compatible prototype, and calling through an incompatible function type is undefined.

Examples

#include <stdio.h>

static int add(int left, int right) { return left + right; }
int main(void) { printf("%d\n", add(19, 23)); return 0; }

Result

42

A function has a declared result type and typed parameter list; arguments pass by value, so modifying the caller’s object requires a valid pointer. A compatible prototype must be visible before the call, recursion needs a terminating case, and a returned pointer must not designate an expired automatic object.

Sources