C language: a concentrated review of the basic concepts of functions at the end of the term

The correct function declaration form:

 double fun(int x, int y)

The correct function definition form:

  double fun(int x, int y)

In a C source file, if you want to define a global variable that is only allowed to be used by all functions in the source file, the storage category that the variable needs to use is static

The application of static to calculate factorial (in my previous blog has an overview) can well understand its meaning.

For local variables whose storage category is not specified in the function, the implicit storage category is automatic (auto)

The following are correct statements (although they are not considered correct before the rule):

  1. Variables with the same name can be used in different functions
  2. Formal parameters are local variables
  3. Variables defined in the function are only valid within the scope of this function
  4. Variables defined in compound statements within a function are invalid within the scope of this function. Only valid in the compound statement.

It is worth noting that
if the initial value of the local variable is not specified, its initial value is not 0.
The user can redefine the standard library function, if so, the function will lose its original meaning

Error-prone point: the
following function call statement contains two actual parameters;
func((exp1, exp2), (exp3, exp4, exp5));
because it is enclosed in parentheses and counts as one actual parameter.

The type of the function value is inconsistent with the return value type, and the value behind return can be an expression based on the function value type

C language stipulates that when a simple variable is used as an actual parameter, the data transfer method between it and the corresponding formal parameter is one-way value transfer .

Typical error:
main()

{ int G=5, k;

void ptr_char( );

k = ptr_char (G);

}

**Error: **There is a contradiction between the function description and the function call statement

Second:
function definitions cannot be nested, but function calls can be nested

When using a one-dimensional array name as a function argument, the size of the array must be stated in the calling function

Call a function, and there is no return statement in this function, the function has no return value.

C language stipulates that the type of function return value is determined by the function type specified when the function is defined

Use the data group name as the actual parameter of the function call, then the first address of the array is passed to the formal parameter

In C language: the actual parameter and its corresponding formal parameter each occupy an independent storage unit

At present, understanding the basic concepts of functions is helpful for future pointer learning, and it is also a good final review.

Guess you like

Origin blog.csdn.net/yooppa/article/details/112254161