Function Calls

A function call is a primary expression containing a simple type name and a parenthesized argument list. The argument list can contain any number of expressions separated by commas. It can also be empty. For example:

stub()
overdue(account, date, amount)
notify(name, date + 5)
report(error, time, date, ++num)

The arguments are evaluated, and each formal parameter is assigned the value of the corresponding argument. Assigning a value to a formal parameter within the function body changes the value of the parameter within the function, but has no effect on the argument.

The type of a function call expression is the return type of the function.The return value is determined by the return statement in the function definition. The result of a function call is an lvalue only if the function returns a reference. A function can call itself.

If you want a function to change the value of a variable, pass a pointer to the variable you want changed. When a pointer is passed as a parameter, the pointer and not the object pointed to is copied.

Arguments that are arrays and functions are converted to pointers before being passed as function arguments.

Arguments passed to non-prototyped C functions undergo conversions. Type short or char parameters are converted to int, and float parameters are converted to double. Use a cast expression for other conversions.

The compiler compares the data types provided by the calling function with the data types that the called function expects. The compiler might also perform type conversions if the declaration of the function is:

In C++, if a nonstatic class member function is passed as an argument, the argument is converted to a pointer to member.

If a class has a destructor or a copy constructor that does more than a bitwise copy, passing a class object by value results in the construction of a temporary that is actually passed by reference.



Functions
Types of Expressions
Operator Precedence and Associativity
Operands
lvalues


main() Function
Function Declarations
Function Definitions
return Statement
Function Specifiers