- True colors of variable with ..clause 1..:
- ..clause 2..: All are call-by-value.
- ..clause 3..: It is scanf function and [wotsukeru] reason.
In the foregoing paragraph, it explained the method of displaying the address of the variable.
At this time, though [wotsukete] was displayed ahead of the variable identifier
When the scanf function was used in Chapter 6, this writing was used.
In a word, only when the address is displayed, the adhering variable is not used.
It is writing used in various places.
The true colors of this adhering variable is very simple.
Actually, it is an operator from which it peels off and the address of the variable is requested.
It is a sign to do some calculations similarly to + and ×.
The address of the variable can be requested by any variable's using the operator.
It can know the number in the memory of the variable by using the operator when paraphrasing it.
In the preceding clause, it explained that it was able to know the address of the variable by using the operator.
However, why should I on earth know the address of the variable?
Actually, the mechanism of the function of C language is related to this.
Chapter 12 explained the scope of the self-made function and the variable.
Here, it explained that the numerical value was able to be passed to the function by the mechanism of argument.
However, being able to pass by this argument is a numerical value to the last.
When you specify the variable when the function is called
The value memorized in the variable is copied onto the actual argument of the called function.
In a word, the data passed to the function by the argument are all numerical values.
The method to pass the numerical value by the argument might be called call-by-value in this manner.
Even if importance here specifies the variable for the actual argument, it is at the point that is passed that is the numerical value of contents.
[ Call-by-value ]
Method of passing function information as mere numerical value.
It is usually this, there is no problem, and to change contents of the variable directly, it embarrasses it.
Because it is only a copy of contents of the variable that was passed to the function
There is not an influence in the variable on the call side no matter how the copy is changed either.
Then, pass the numerical value of the address by using the operator for the address.
The address of the variable on the call side, that is, the number in the memory ..function.. is understood if it does so.
If the memory of the number is rewritten, the variable on the call side is rewritten.
In a word, it is a reason why this should learn the address of the variable.
[ Call-by-reference ]
There is a language where the function of call-by-reference exists for call-by-value, too.
This is to do processing that passes the address automatically by the function of the language.
Though only call-by-value can be done to the last in C language
It might be called call-by-reference to pass the address in the custom.
I think that the reason to put up [wo] by the scanf function is understood if it thinks from the explanation in the preceding clause.
The scanf function is a function that is input from the keyboard, and memorized in the variable.
However, only call-by-value can be done in C language as explained in the preceding clause.
In a word, only the copy of the value memorized in the variable can be passed to the function.
It becomes impossible to memorize a new value in the variable with this.
If you pass the address of the variable in that case as a numerical value as explained in the preceding clause
Data can be memorized at the address on the side of the function.
This is scanf function and [wotsukeru] reason for the variable.
However, it is [wotsukenakattakotodesu] in the doubtful one to input the character string ahead of the array identifier.
The array identifier shows the address of the first element of the array like having explained this in the foregoing paragraph.
If the array identifier is passed therefore, it is ..peel.. unnecessary because the place of the array is understood.
In a word, only have to specify even the address of the array even if it is not a certain meaning array identifier.
For instance, if as follows is done, it is possible to input it even if it is not an array identifier.
The execution result of this program becomes as follows.#include <stdio.h> int main(void) { char str[256]; scanf("%s",&str[0]); /* address */ of the 0th element FONT> Printf("%s\n",str); return 0; }
This program only specified the address of the 0th element instead of the array identifier.
Character string input from MARIO keyboard
MARIO
The execution result of this program becomes as follows.#include <stdio.h> int main(void) { char str[256] = "DRAGON"; scanf("%s",&str[6]); /* address */ of the sixth element Printf("%s\n",str); return 0; }
To the array at the stage of initialization in this program The character string of DRAGON is substituted.
Character string input from QUEST keyboard
DRAGONQUEST
In a word, to externals certainly when you have passed only the array identifier though it is not [hawotsuke]
Going actually is quite the same as the specification of the variable of adhering.