function arguments and function calls
1, function call the role:
• Transfer data to formal parameters using real parameters;
• Allocating storage space for data parameters and variables declared in the function body;
• Interrupt the current (call) function, and start the process to the entry of the called function and execute the called function.
When the parameter table is empty, it means that the function does not accept data from the calling function.
2, numerical parameters
Pass-value invocation: The parameter is allocated to the memory area only when the function is called, and remains until the function is returned. Formal parameters and arguments are just the same names, each possessing their own memory space and life cycle, so he does not change the variables in the main function.
3, Address parameters
Address calls: The addresses of the variables are transmitted, although the main function and the called functions operate on their own variables, but their addresses are the same, so the modulated function can change the value of the variable in the calling function.
function that returns a pointer
In C, the return type of a function can be any type other than a divisor group and a function, including data that returns a pointer type.
Example 1://the original function of a specified character in a lookup string
extern char *strchr(char *str,char character)
{
while(*str!=character)
str++;
return(str);
}
··
Attention... Unlike an address call, a function that returns a pointer returns data to the calling function in the form of a pass value. Therefore, you cannot use the address of an automatic variable as the return value because such a variable will be revoked upon return. Global variables do not need to return addresses. Therefore, the returned address variable should be local variable or dynamic.
Example 2://wrong get is garbled
char *strchr(char *str,char character)
{
char* substr;
substr[0]=str[0];
return substr;
}