I. Recognize the truth of functions
1. Origins of functions
Program = Data + Algorithm
C program = Data + Function
2. Functions
Modular Program Design
Modularization in C Language
3. process-oriented programming
# Process-oriented is a process-centric programming idea
# First, resolve complex problems into problems that are easy to solve. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + o6OhobfWveK5/kernel + kernel/K5/kernel + kernel/K/cc0yrxp1?vcd4kpha + kernel/kernel + signature + PC9wPgo8cD48YnI + signature/Signature/J + cP30ru49s3isr + signature + CmludCBtYWluKCk8YnI + Cns8YnI + signature + CiAgICA8YnI + Signature = "% d \ n ", g (3 ));
Return 0;
}
Void f (int I, int j) // define
{
Printf ("I + j = % d \ n", I + j );
}
Int g (int x)
{
Return 2 * x + g_var;
}
4. Function Parameters
# Function parameters are essentially the same as local variables and are allocated space on the stack.
# The initial value of a function parameter is the real parameter value during function calling.
Instance: # include
Int f (int I, int j)
{
Printf ("% d, % d \ n", I, j );
}
Int main ()
{
Int k = 1;
F (k, k ++ );
Printf ("% d \ n", k );
Return 0;
}
The order in which function parameters are evaluated depends on the implementation of the compiler !!! In C language, the order in which most operators evaluate their operands depends on the implementation of the compiler !!! Int I = f () * g (); // do not blindly think that f () is computed before g ()??? 5. Sequence points in the Program # Some sequence points exist in the Program # sequence points refer to the latest time point for modifying values during execution # When the Program reaches the sequence point, all previous operations must be reflected in subsequent access # When each complete expression ends # &, | ,? :, And after each calculation object of the comma expression is calculated # after the actual parameters in the function call are evaluated (before entering the function body) # include
Int main ()
{
Int k = 2;
Int a = 1;
K = k ++;
Printf ("k = % d \ n", k );
If (a -- &)
{
Printf ("a = % d \ n", );
}
Return 0;
}
Default identification of functions # C language will default function parameters with no type as intf (I, j) {return I + j;} is equivalent
Int f (int I, int j) {return I + j;} summary: 1. C language is a process-oriented language 2. The function can be understood as a solution Step 3. The real parameters of the function do not have a fixed computing order 4. The order point is a variable change in the C language. the latest time of 5. The parameter and return value are int by default.