The essence of the function

1. Program = data + algorithm; C language = data + function; modular programming;

2. Process-oriented is a process-centric programming idea

3. First decompose complex problems into easy-to-solve problems

4. The problem after decomposition can be completed step by step

5. Function is the embodiment of process-oriented in C language

6. Each step of solving the problem can be implemented with a function

7. The declaration in the program can be understood as telling the compiler the existence of entities in advance, such as: variables, functions, etc.

8. Definitions in the program clearly indicate the meaning of the compiler entity

Declaration and definition are not the same

extern int a;//The declaration is a variable of other files, no need to allocate space int a=10;//Definition, allocate a space

9. Function parameters are essentially the same as local variables, all of which are allocated space on the stack

10. The initial value of the function parameter is the actual parameter value when the function is called

11. The evaluation order of function parameters depends on the implementation of the compiler. The order in which most operators in C language evaluate their operands depends on the implementation of the compiler! ! !

12. There are certain sequence points in the program

13. The sequence point refers to the latest time in the execution process to modify the value of the variable

14. When the program reaches the sequence point, everything done before must be reflected in subsequent visits

15. At the end of each complete expression

16. &&, ||, ? ; and after each operand of the comma expression is evaluated

17. After the evaluation of all actual parameters in the function call is complete (before entering the function body)

18. The C language will default the function parameter without type to int

19. Functions with variable parameters can be defined in C language

20. The implementation of variable parameter functions depends on the stdarg.h header file

21. The va_list variable is used in conjunction with va_start, va_end and va_arg to access parameter values

22. Variable parameters must be accessed one by one in order from beginning to end

23. There must be at least one definite command parameter in the parameter list

24. Variable parameter macros cannot determine the number of parameters that actually exist

25. Variable parameter macros cannot determine the actual type of the parameter

26. If the wrong type is specified in va_arg, the result is unpredictable

27. The macro is directly replaced and expanded by the preprocessor, and the compiler does not know the existence of the macro

28. A function is an entity compiled directly by the compiler, and the calling behavior is determined by the compiler

29. Multiple use of macros will increase the amount of program code

30. The function is executed by jumping, so the amount of code will not increase

31. Macros are more efficient than functions because they are expanded directly without calling overhead

32. Active records are created when the function is called, which is not as efficient as macros

33. Macros are slightly more efficient than functions, but their side effects are huge and error-prone

34. The function has the transfer of actual parameters to formal parameters, so there is no side effect, but the function needs to establish an active image, which affects the efficiency

35. The macro parameter can be any C language entity, the _MIN_ parameter type written by the macro can be int, float, etc., and the macro parameter can be the type name.

36. Active record is a record used to record a series of related information when a function is called

Temporary variable field: used to store the value of temporary variables, such as the intermediate results of K++

Local variable field: used to store local variables in this execution of the function

Machine state field: used to save information about the machine state before calling the function, including the current value of various registers and the return address, etc.

Real parameter field: used to store the actual parameter information of the function

Return value domain: store the return value for the caller function

37. Recursion is the application of concepts in mathematics to programming

38. Recursion is a powerful programming method

39. The essence of recursion is that the function calls itself at the appropriate time

40. Recursive functions in C language will inevitably use judgment statements

41. The recursive function defines the exit of the function when it needs to be written, otherwise the stack will overflow

42. Recursive functions are a divide and conquer idea

43. Don't use global variables in functions, try to make the function an independent function module in a sense

44. The parameter name should reflect the meaning of the parameter

45. If the parameter is a pointer and it is only used as an input parameter, const should be added before the type to prevent the pointer from being accidentally modified in the function body

46. ​​Do not omit the return type. If the function has no return value, it should be declared as void type

47. Check the validity of the parameters at the "entry" of the function body, and the check of the pointer is particularly important

48. The statement cannot return a "pointer" to "stack memory" because the memory is automatically destroyed at the end of the function body

49. The size of the function body should be small, try to control it within 80 lines of code

50. The same input should produce the same output, try to avoid the function with "memory" function

51. Avoid functions with too many parameters, and try to keep the number of parameters within 4

52. Sometimes functions do not need return values, but in order to increase flexibility, such as supporting chain expressions, return values ​​can be attached

53. The function name and the return value type are not semantically conflicting


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325951003&siteId=291194637