※スタイルシート未対応ブラウザではレイアウトを正確に再現できません。
  > | advanced by | contents  | that returns in <    
                   < [modosusu] > Color magazine monochrome light and shade   font predetermined, Gothic Ming-style type longhand   size Konaka large   standard  


  Memorize the numerical value.   

  1. ..clause 1..: Necessity of memory
  2. ..clause 2..: Memory of variable
  3. ..clause 3..: Declaration of variable
  4. ..clause 4..: Substitution of value for variable
  5. ..clause 5..: Use the variable instead of the numerical value.
  6. ..clause 6..: Substitution and the operation at the same time

[1] Necessity of memory

If it is a calculation by the content to the preceding chapter that uses the arithmetic operation, any complex expression is computable.
However, satisfying it with this is too low the will (aim).

Though the numerical value was written every time directly as a program in the method to the preceding chapter
At that time, everything was written foolish and honestly even though compared and was suitable of the same numerical value.
Made ahead, and in the program that calculates 10+3, 10-3, 10×3, and 10÷3
The numerical value called 10 and 3 was written many times though was the same.

I want to take the place of In a word, 10 and 3 in this method 20 and 7.
It is necessary to rewrite all numerical values purposely.

Frankly speaking, this is troublesome.
The means to memorize the numerical value is necessary to lose this trouble.
Memorize one frequency value, and if there is a method of taking out the numerical value and use
All numerical values can be changed only by substituting the numerical value to memorize.

It returns to contents.


[2] Memory of variable

The function to achieve the idea in the preceding clause exists in C language. It is a variable.
Though there might be a lot of people who recall mathematics and become unpleasant when hearing the variable, too
The variable of the programming and the variable of mathematics are complete different things.

The variable is to give the name to the memory area to preserve the numerical value.
Though it explains the box where the numerical value is put in this and most introductions
It might be a how to explain in the age when such [noha] and every computer had not been felt.
For the person who is using the computer as such, saying as the memory is refreshing.


[   Variable   ]
Method of management giving name to memory that memorizes numerical value
The memory of the computer is a structure like the locker hugely displayed in a row in side.
Each one of edge [kkokara] , of the locker is numbered.
And, the numerical value treated with the computer is somewhere in the locker.

Put and put out the numerical value based on the number of the locker if usual.
It is not about troublesome [nakotoko] on when a prosy number is used every time every time.
You do not think that it will want to distinguish the locker by the employer identification number for seven digits either.

Then, the name will be given to each locker.
Whether for what it is locker the name is seen if it does so is understood at once.
Moreover, because of saying that it will become very easy to treat

It returns to contents.


[3] Declaration of variable

It explained management giving the memory the name in the preceding clause.
In a word, give the name to the variable to use the variable.

In C language, it is called as the declaration of the variable to give the variable the name.
Use the following writing to declare a variable.

Type name   variable identifier;
The type name is a name that shows the kind of the numerical value to be memorized.
Remember int that means the integer for the time being.

The variable identifier is a name given to the variable as its name suggests.
In how to give this name, there is regulations like the under.

1, normal-width alphabet, normal-width figure, and normal-width _ can be used.
The first two characters, the figure cannot be used.
3 and the reserved word decided beforehand cannot be used.
Do not think seeing that, this, and somewhere?
It is so, and this is quite the same as how to give the name of the function name.

If only this is understood, it is possible to declare a variable.
The following program, variable value of the type named int (integral value) is declared.

 
#include <stdio.h> 

int main(void)  
{
	int value; /* part */ of variable declaration  Return 0;
}
The variable can be basically declared only at the head of the function.
For instance, it is not possible to declare a variable as follows.
 
#include <stdio.h> 

int main(void)  
{
	printf("Hello\n");  
	int value; /* part */ of variable declaration  Return 0;
}
It makes an error of this program when it is operated.
If the part of the variable declaration is brought to the head, it comes to operate.

[ Function of   compiler   ]
Actually, this program moves in a lot of compilers.
It is because of being able to use it in C++ ([shi-purapura]) of the extended version of C language it.
Moreover, it is possible to use it even with C99 that is a new case of C language decided in recent years.
However, remember if it is not possible to use it by original C language.

It returns to contents.


[4] Substitution of value for variable

The variable declared once can be used freely within the range.
It is possible to use it freely in the main function because it declares in the main function this time.
Because only the main function is used, it will not relate so much for the present.

There are two kinds of usages of the variable. One in that is substitution.
Substitution means the numerical value is memorized in the variable.


[   Generation insertion   ]
Memorize the numerical value in the variable.
Use the following writing to substitute the numerical value for the variable.
Variable identifier = numerical value;
Never misunderstand it. In this =, the equal sign of mathematics is completely a sign of another meaning.
= here means a right numerical value is memorized in a left variable.
In a word, think that this = is taking the place of the sign of ←.

If only this is understood, the numerical value can be substituted for the variable (Memorize it).
The following program is a variable of int (integral value) type To value Substitute ten.

 
#include <stdio.h> 

int main(void)  
{
	int value; /* part */ of variable declaration value =  10; /* part */ of substitution  Return 0;
}

It returns to contents.


[5] Use the variable instead of the numerical value.

The usage of another ..weirdy.. ..several.. is to use it as taking the place of the numerical value.
It is not because there is especially such writing for this.
It replaces the numerical value that the variable memorizes to write the variable identifier in the expression.
It is possible to apply it by all scenes of the display and the calculation, etc. of the numerical value that have used the expression up to now.
The following program is an example of displaying the value memorized in the variable.

 
#include <stdio.h> 

int main(void)  
{
	int value; /* part */ of variable declaration value =  10; /* part */ of substitution Printf("%d\n",value); /* part */ of display  Return 0;
}
The execution result of this program is as follows.

10
If this variable is used, the problem of taking it up at the head of this chapter is solved.
10 in a word Memorize the numerical value called three in the variable, and if you calculate by the variable
The rewritten place ends in one place even if coming to want to change the numerical value.
The following program is an example of calculating the arithmetic operation by using the variable.
 
#include <stdio.h> 

int main(void)  
{
	int left;  
	int right;  
	left = 10;  
	right = 3;  
	printf("%d\n",left + right);  
	printf("%d\n",left - right);  
	printf("%d\n",left * right);  
	printf("%d\n",left / right);  
	printf("%d\n",left % right);  
	return 0;
}
The execution result of this program is as follows.

13
7
30
3
1
The place where this program is good only rewrites the numerical value substituted for the variable.
It is in the point said one time the change and ending because all numerical values of the following calculation are replaced, too.
Actually, change the numerical value substituted for left and right.

It returns to contents.


[6] Substitution and the operation at the same time

The numerical result of the expression can be substituted directly for the variable.
In the following program, the result of 10+30 is substituted for value.

 
#include <stdio.h> 

int main(void)  
{
	int value;  
	value = 10 + 30;  
	printf("%d\n",value);  
	return 0;
}
The execution result of this program becomes as follows.

40
In addition, it is also already possible in the value that the variable remembers to calculate directly.
The following program is an example of adding 30 to the numerical value memorized in variable value.
 
#include <stdio.h> 

int main(void)  
{
	int value;  
	value = 10;  
	value += 30;  
	printf("%d\n",value);  
	return 0;
}
The execution result of this program becomes as follows.

40
The point of this program is in the += operator.
This operator provides the function that only a right number increases the value of a left variable.
It had already been substituted ahead To ten The value in which 30 was added was substituted.

It is also possible to rewrite the part of this operator as follows.


value = value + 30;
This writing is considerably a strange expression for the person who is not accustomed to the program.
Because with value Because it is written that value+30 is equal.
However, solve it in C language if you recall that = is a meaning of ←.
This expression : to value The numerical value that adds 30 It means substitution for value.

As the += operator etc. are unnecessary if you can achieve an increase in the value of the variable by this writing though it is possible to think
+= The description is and there is an advantage of easiness because it is good to write the variable if the operator is used only by one.
The operator with a similar function is prepared in other calculations.
Operator Function
+= Substitute addition with the value of the variable for the variable.
-= Substitute the subtraction with the value of the variable for the variable.
*= Substitute multiplication with the value of the variable for the variable.
/= Substitute division with the value of the variable for the variable.
%= Substitute [yozan] with the value of the variable for the variable.
In addition, one ..value of the variable.. ..one.. expands or decreases, and has the operator only for one increase and decrease.
The value of the variable is ++ operator of one the expanded operator, and is called an increment.
The operator ..one.. decreased : oppositely. --It is called that it decreases by the operator.
The following program is an example that uses the increment and decrement.

 
#include <stdio.h> 

int main(void)  
{
	int value;  
	value = 10;  
	printf("%d\n",value);  
	value++;  
	printf("%d\n",value);  
	value--;  
	printf("%d\n",value);  
	return 0;
}
The execution result of this program becomes as follows.

10
11
10
In the programming, as for one increasing the value of the variable, an awful lot and this operator are convenient.

It returns to contents.


< - It is advanced -> | in | head that returns  to returning  next |.