-
Actually, you can understand the problem this way, int
a=1,b=2;It can be seen that a, b are real arguments, and 1 and 2 are form arguments, so when calling the function swap(a,b), the form arguments are passed, that is, 1 and 2 are passed, not a and b are passed. then swap(a,b) is swap(1,2).
Therefore, the value of the output parameter after conversion is the value after the exchange, and the actual parameter is still the original value
-
No, in the C language, there are address values and parameter values, and parameter values can only pass the actual parameters to the form parameters, so option A is correct. External variables in C can pass data between functions.
The automatic variable in C is the default variable, which is actually a local variable in the function, so the d option is correct. Once defined, global variables need to allocate memory units, and will occupy a fixed space from beginning to end during the running of the program, so it is best not to use global variables in the case of unknown memory.
When the function is called, the value can be passed in both directions, and there is no restriction on whether to use global or local variables, and you need to choose according to the logical needs of the program.
-
void fun(int arr,int n);
When defining a function, the parameter int arr does not represent the value of an element, but tells the compiler that the first argument is an array pointer that can receive the array address passed from the argument.
In fact, the above definition is equivalent to the following definition.
1.The number of elements in the array:
void fun(int arr[constant], int n);
The constant here can be any positive integer, and in fact the compiler will ignore it, because it just tells the compiler that I am receiving an array pointer, and it doesn't matter how many elements it has, because the argument is just an address. The number of elements is controlled by parameter 2. As for why this is agreed, you can see the supplementary explanation below.
fun(int *arr, int n);
Use pointers, this way and the way in the question are the most commonly used, and the first is the least used.
Imagine that there is a function as follows.
int fun(int nums[1000], int size) its argument one has to deal with an array of more than 1000 elements, if it is to pass the value that is, each element, then in the function body, you have to apply for more than 1000 integer memory, and you also need to copy the value from the arguments, which is very time-consuming and unnecessary, because a certain block in memory has stored these data. Just tell me where to put it, and you can find it there. This is all about passing the address, you only need to pass the first address of the array, and then tell how many elements to be processed.
Passing the address only needs to copy the address to the form parameters, which is much faster than passing each element.
-
int arr is equivalent to int *arr, which is the pointer type, array is the first address of the array, and the address is the pointer, of course, you can assign a value.
-
A parameter is the data that is passed to a function.
Arguments are the data that is being passed.
For example, there is a function fum(int a).
The variable int b that you define in the main function
Then b is the real argument.
A is the form of the parameter.
Similar to when you use QQ to send files to others.
Your file is called the real parameter.
The file that is in the process of being transferred and ends up with someone else is called a parameter.
-
Form Parameter: Full name"Formal parameters"It is a parameter that is used when defining the function name and function body, and is used to receive the parameters passed when the function is called.
Actual Parameters: Full name"Actual parameters"It is to pass a parameter of the function when it is called.
When the parameters and arguments are not pointer types, when the function is running, the parameters and arguments are different variables, they are located in different positions in memory, and the arguments make a copy of the content of the arguments, and the arguments are released at the end of the function, while the arguments do not change.
If the argument of the function is a pointer type variable, in the process of calling the function, the address of the argument is passed in the function, and the address of the argument is also used inside the function body, that is, the argument itself is used. So inside the function body it is possible to change the value of the arguments.
To give you a very simple example::
int f(int b) *b is the parameter *main().
-
There are the following differences:1. The main body is different: When the argument is called, the parameter in parentheses after the function name is "actual parameter". Parameters are not actual variables, also known as dummy variables.
2. Different purposes: Arguments can be constants, variables, or expressions, and no matter what type of quantity the arguments are, they must have definite values when making a function call, so that these values can be transmitted to the parameters.
It should be noted that when the parameters and arguments are not pointer types, when the function is running, the arguments and arguments are different variables, they are located in different positions in memory, and the arguments make a copy of the content of the arguments, and the arguments are released at the end of the function, while the arguments do not change.
-
Parameters appear in the function definition and can be used in the entire body of the function, but cannot be used outside of the function. The arguments appear in the tonal function, and cannot be used after entering the modulated function.
The parameter variable allocates the memory cell only when it is called, and at the end of the call, the allocated memory cell is immediately released. The arguments, on the other hand, are allocated memory units in the tonal function.
Arguments can be constants, variables, expressions, functions, and so on, and no matter what type of arguments they are, they must have definite values when making a function call in order to pass these values to the parameters.
The parameters and parameters should be strictly consistent in number, type, and order, otherwise the type mismatch error will occur.
The data transfer that occurs in a function call is one-way. That is, the value of the argument can only be transmitted to the parameter, and the value of the argument cannot be transmitted to the argument in reverse.
-
The actual argument is the actual argument given by the main function called the subfunction, and after entering the subfunction, the subfunction will copy a copy of the actual parameter into a local variable inside the subfunction, which is the form parameter.
-
Arguments are the arguments written when the function is called, the parameters are the parameters used inside the function, a temporary variable of the argument should be created when the function is called, and then the temporary variable will be converted into the type of the argument when needed, and then the variable will be assigned to the argument to destroy the temporary variable, and the variable after the return of the function and the return value of the function are also similar to the process.
-
To put it simply, the parameters used in your function definition are arguments when you call the function. The real argument is passed to the one-way value of the form parameter.
-
The difference between real and form parameters:
1. The addresses assigned to the real and form parameters are different. It can be compared to one villa, and the ginseng is another. The contents of the ginseng were copied and moved to the ginseng, and the contents of the villa were thrown away or new things were added, which would not affect the villa.
2. If you don't use pointers or references, the real argument can only pass things (values) to the parameters, just like the above example, the things in the parameters can be copied and moved to the parameters, and the things (values) in the parameters are changed but will not be passed in reverse, that is, the things in the parameters will not cover the things (values) in the parameters.
3. To put it simply, the address of the argument and the parameter operation is different, if you need to get the value of the change, you generally use return to return the value, and if you want to change the argument, you will use a pointer or reference to achieve it, so that the manipulation of the address makes the argument more convenient to manipulate.
4. The scope of the parameter is limited to the defined function, and once the function is out, the defined parameter will be released.
To change the value of a variable by passing a function, you must pass an address. Your program is passing the value of the variable swap(a,b); If you want to change the value of a variable, you must pass the address of the variable, or do it by a pointer, if it is an array, you can directly use the array name, but if it is an element of the array, you still need to use the address. Just change it like the one upstairs did him. >>>More
The address assigned to the parameter and the parameter is different. >>>More
Scope. You static char *chh;
static char *ch1;Although the address pointed to by the two pointers does not change, have you ever wondered whether the memory address they point to has been released, char chc[10]; It's local, the function is out, the lifecycle is over, and you're trying to access it with a pointer in void times(). >>>More
The program calculates the angle between the two needles at any time between 0:00 and 23:59. >>>More
Use the ITOA function.
Prototype: extern char *itoa(int i); >>>More