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


  Handling of value of invariability   

  1. ..clause 1..: Value of invariability from first to last
  2. ..clause 2..: Give the numerical value the name.
  3. ..clause 3..: Give the character string the name.

[1] Value of invariability from first to last

The value that doesn't change is called a constant while executing it.
Numerical values that have been written directly up to now while programming it are all constants.
The character string written directly is a constant, and it is called the string literal.

When being programming it, the same numerical value and the character string might be used many times.
For instance, pi is about 3.14159, and this value is the same at any time when.

It is useless to write the same value and the character string many times in this manner.
Moreover, when the necessity for changing the numerical value and the character string is caused, the correction is troublesome.

For instance, when there is calculator software that adheres the function to calculate the consumption tax
Suddenly, when the consumption tax becomes 5% from 3%
It is necessary to rewrite the numerical value of 0.03 under programs in all 0.05.
Because there might be 0.03 of the meanings besides the consumption tax possibly
Rewriting confirming not to change it by mistake one by one is serious.

Then, use the name giving the numerical value the name beforehand.
All numerical values are corrected only by correcting the part where the name was given.
The meaning becomes comprehensible from a free numerical value if written by the name.

It returns to contents.


[2] Give the numerical value the name.

The method of giving the numerical value the name is prepared in C language.
It is # define ([dei;fain]) quasi-instruction.
#The usage of the define quasi-instruction is as follows.
 
#Define name numerical value
First of all, in # define quasi-instruction at the end of the sentence;[Wotsuke].
Moreover, it is general to put this sentence on the head of the program.
Moreover, the alphabet of the capital letter is general though the same character as the variable can be used for the name.
When the price of the main body is input, the following program displays the price including tax.
 #Include < stdio.h >  The  constant is declared  # define EXCISETAX 0.03 /* here */  Int main. (void) 
{
	int price; 
	Printf ("Price of main body");
	scanf("%d",&price); 
	price = (int)((1 + EXCISETAX) * price); /* constant use */ Printf ("Price including tax: %d\n" price);
	return 0; 
}
The result when this program is executed, and 300 is input becomes as follows.

Price of main body: 300 (input value)
Price including tax: 309
In this program, the constant by # define quasi-instruction is used for the math calculation.
In the expression that calculates the tax-inclusive price Though the name called EXCISETAX is used
This name : by the first # define quasi-instruction It is replaced by 0.03.

The numerical value that replaces EXCISETAX in this expression Because 0.03 is a real number value
Usually because it doesn't use the real number for the price though the numerical result also reaches the real number value
It is Cast (conversion) and it substitutes it for the int type.

#If the numerical value of the define sentence is changed, the numerical value under the program is changed.
The following program : the consumption tax It is the first part when changing to 0.05.

 #The  constant is declared define EXCISETAX 0.05 /* here */. 
The result when this program is executed, and 300 is input becomes as follows.

Price of main body: 300 (input value)
Price including tax: 315
The meaning of the numerical value becomes comprehensible if the constant is used, and it becomes easy to correct in this manner.

It returns to contents.


[3] Give the character string the name.

#In the define quasi-instruction, the name is given to not only the numerical value but also the character string.
Naturally, it is necessary to apply ""to the character string though the usage is the same as the case of the numerical value.
The following program displays the name of the author of the program.

 # # define AUTHOR "
Masanori Moriguchi"  Include < stdio.h >   Int 
main(void) 
{
	Printf ("Name of author: %s\n" AUTHOR);
	return 0; 
}
The execution result of this program becomes as follows.

Name of author: Masanori Moriguchi
AUTHOR is replaced by "Masanori Moriguchi" here.
Of course, all if the part of # define quasi-instruction is changed It influences AUTHOR.

It returns to contents.


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