Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

Function-call operator ()

The () operator calls a function, passing argument values to parameters. It also works with a function pointer; it does not establish argument evaluation order.

Version: C23; repository compiler flag, production runtime not attested

Syntax

function_expression(argument1, argument2)
function_expression()

The () operator after an expression designating a function forms a call. Commas separate arguments; an empty list means no arguments. This differs from grouping parentheses (expression).

Arguments are passed by value. Each fixed parameter requires a corresponding argument, which is converted to that parameter's type. Additional arguments are allowed only if the parameter list contains .... These arguments have no corresponding parameters and undergo the default argument promotions. The result has the function's return type; void means no result value.

Argument evaluation order is unspecified. Avoid add(i++, i++): its behavior is undefined. Argument evaluations finish before entering the function.

In the example, operation(2, 3) calls add through a compatible function pointer. (*operation)(2, 3) is another valid spelling.

Examples

#include <stdio.h>

static int add(int a, int b)
{
    return a + b;
}

int main(void)
{
    int (*operation)(int, int) = add;
    int result = operation(2, 3);
    printf("%d\n", result);
    return 0;
}

Result

5

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources