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


  Relation between variable and memory   

  1. ..clause 1..: The variable exists in the memory.
  2. ..clause 2..: Display the number in the memory.
  3. ..clause 3..: Number of two or more variables
  4. ..clause 4..: Number of array

[1] The variable exists in the memory.

It explained that the variable was made in the memory when it explained the variable in Chapter 5.
However, it had not explained the concrete content at all.
It is because of did not have being necessary to know so much only if the variable is treated.

However, to understand the concept of pointer handled ahead of this
It is necessary to know how the variable is stored in the memory.

The memory of the computer is up to a structure as explained in the foregoing paragraph like a huge one row locker.
And, each one memorizes two states of on and off in this locker.
It is called one byte bringing 1 bit and this one locker 8 together.
The number is applied and distinguished by this every one byte by the memory.

The variable declared in the program is memorized in this memory by numbered.
However, the name is given because it is cramped to distinguish by the number.
The variable identifier is converted into the number when compiling to the execution file.

In short, all variables are made in the memory.
First of all, have numbering and the distinction in mind there.


[   C language is such a language   ].
Thereafter, the development that approaches the realities of C language is seen a lot in this chapter.
It is clarified that it was not the explanation in the current chapter a lot in this chapter.
A lot of developments that criticize the grammar etc. of C language are seen in that, too.

To begin with, the person named Dennis rich : C language.
It is a programming language made only to use it for myself.
It was not thought that it came to be used all over the world at all.
Therefore, the part matched to the convenience of the person who made it is seen.
It is a language of an unkind grammar in common folk.

However, C language is still used all over the world.
It is a language that has the generality though there is a mysterious in some places part.
It is widely used from small parts to the game of PlayStation.

It returns to contents.


[2] Display the number in the memory.

In the preceding clause, all variables explained numbering and the distinction being made in the memory.
Actually, it is possible to look up at the number applied to the variable by the program.

Looking up at the number only handles %p finger fixed child by the printf function unexpectedly easily.
However, it should be [wotsukeru] ahead of the variable identifier.
The following program is an example of displaying the number of int type variable i.

 
#include <stdio.h> 

int main(void)  
{
	int i;  
	printf("%p\n",&i);  
	return 0;
}
The execution result of this program might be as follows.

0012FF80
The figure of the result : this though the result executed in author's environment.
It is different depending on the personal computer and the compiler used.
Is allocated the specified variable in the memory of which number?
The compiler (Linker accurately) automatically decides it.
It is in addition because the value changes by the virtual memory function of OS, too.

This number is a display method of hexadecimal number. When making it to the decimal number It becomes 1245056.
When you say why to be displayed by a cramped method like the hexadecimal number
The numerical value of the computer is memorized by the binary number as explained in the preceding clause.
  In the binary number,   2, 4, 8, 16, ・・・・, and the digit go up.
In the decimal number, 10,100, 1000, and the digit go up.
In the hexadecimal number, 16,256, 4096, and the digit go up.
Neither the decimal number nor the binary number have the god combination well though it might be noticed that this is seen.
The hexadecimal number is good with the binary number and ..god ..combination.. song.. convenient.


[  Is the computer a binary number why?  ]
To how many is the number counted from you by ten fingers of both hands though it is sudden?
It is usually actually counted theoretically up to 1024 though ten.
Only have to make one finger correspond to one binary number digit and to count.
Counting from the decimal number by the binary number : in this manner.
The circuit can be made small and simple.
However, the hexadecimal number commenting is not very important here.
An important thing is a point that it is possible to look up at the number applied to the variable easily.
This number applied to the variable is called an address.

[   Address   ]
Number on memory applied to variable
The problem is not in this by thinking quite the same meaning as the URL address and the said address.
It is the number in which the address of the variable is shown, that is, address.

It returns to contents.


[3] Number of two or more variables

It searches for the address of two or more variables this time because only one was examined in the preceding clause.
The locker number applied to the variable is called an address though it repeats.
The following program is an example of displaying the address of three int type variables.

 
#include <stdio.h> 

int main(void)  
{
	int i1,i2,i3;  
	printf("i1(%p)\n",&i1);  
	printf("i2(%p)\n",&i2);  
	printf("i3(%p)\n",&i3);  
	return 0;
}
The execution result of this program might be as follows.

I1(0012FF78) It is 1245048 in the decimal number.
I2(0012FF7C) It is 1245052 in the decimal number.
I3(0012FF80) It is 1245056 in the decimal number.
This is an execute in author's environment example. The numerical value is different according to the environment.
Apparently, the sequential number for the gap by four watches seems to be allocated in the int type variable.
Therefore, this doesn't have four byte size of the int type ..another...
However, it becomes two bytes in LSI C-86.

Because four bytes are 4x8=32, it becomes 32 binary number digits of 32 bits.
Numerical values up to about 4.3 billion can be memorized when not thinking about +-.
It becomes it up to 65535 for two bytes.

Variables other than the int type are different the size in each compiler.
However, only the char type is decided one byte without fail.
To put the character for which the number within the range to which it decides is used in the char type
It is because of a variety of inconveniences if it doesn't make it to the same size.

This time..ream..watch..variable..address..always..without fail..sequential number..limit.
Because these three variables are variables separately used
The reason for any problem is that it is not even in case of being in an asunder place.
It is likely to become reverse order according to the compiler.

It returns to contents.


[4] Number of array

The array can also display the address as well as the number of the variable.
The address is a locker number applied to the variable though it is persistent.
It is [wotsukeru] in the head in case of the array.
However, apply natural because an individual element of the array is the same treatment as the variable.
The following program is an example of displaying the array and the address of the element.

 
#include <stdio.h> 

int main(void)  
{
	int array[10];  
	printf("array___(%p)\n",array);  
	printf("array[0](%p)\n",&array[0]);  
	printf("array[1](%p)\n",&array[1]);  
	printf("array[2](%p)\n",&array[2]);  
	return 0;
}
The execution result of this program might be as follows.

array___(0012FF5C) In the decimal number
Array[0] (0012FF5C) In the decimal number
Array[1] (0012FF60) In the decimal number
Array[2] (0012FF64) In the decimal number
Apparently, four bytes seem to be allocated in the sequential number at the array.
In addition, when the array identifier is specified, it seems to become the same number as the first element of the array.

Actually, all of the trick of the array are exposed here.
The array identifier actually showed the address of the first element of the array.
This meaning : though the element number called [0] and [1] was applied when each element is referred.
It becomes a meaning of referring to the memory of address + element number of the array identifier.

In a word, in adding up the number to it if the first address is decided
The state that do the arrangement of a lot of variables can be expressed.

However, four has been that an actual address increased in a little doubt here at element number 1.
If the size of the int type can be recalled, it understands at once.
In this compiler, the size of the int type is four bytes.
In a word, the address of the variable of the previous one int type becomes the first address +4.
Similarly, the address of the variable of two previous int type becomes the first address +8.

Do the explanation thrust further later about the mechanism of this array.

It returns to contents.


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