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


  Use the pointer variable.   

  1. ..clause 1..: Declaration of pointer variable
  2. ..clause 2..: Substitute the address.
  3. ..clause 3..: Switch of mode
  4. , that is, ....clause 4..:.. short cut

[1] Declaration of pointer variable

Because it explained concerning three kinds of pointers in the foregoing paragraph
Here, it wants to actually declare the pointer variable, and to grip the sense.

I want to show the example of immediately declaring the pointer variable because it says.
Actually, this is troublesome goods again.
Two examples of declaring the variable to int of the pointer type are shown for the time being.

 
int *p;  
int* p;
It is writing of the declaration of the pointer variable that this is introduced by a lot of introductions.
This two are writing to declare the variable of the pointer type to int of the name of p.

* : in the sign that means the pointer type though the writing of eyes is one names of *p.
Actually, the variable of p that memorizes the address of the int type variable is declared.

Type..name..adhere..declaration..one..legible..think.
It is different from the type name of the appearance since the second when two variables or more are declared.
In the following example, the second p2 becomes a usual int type variable.

 
int* p1,p2;
Unite it by the writing of eyes because it is confusing when it thinks deeply here one.
In a word, if * is applied ahead of the variable identifier, the pointer variable can be declared.

It returns to contents.


[2] Substitute the address.

The pointer variable is a variable as explained in the foregoing paragraph for which the address is substituted.
The following of the declaration of the pointer variable want to substitute the address immediately.
By the way, is assumed the substitution of the address to be good, and how is done the substituted address?

On the reason, separately though any address can be substituted
Even if the address that cannot be used is substituted, it is not significant.

Actually, there is a method of substituting the address of the memory that can be used.
The method is a method of declaring another another one variable in an easy thing, and substituting the address.
The following program is an example of substituting the address of the variable for pointer variable p.

 int main(void)  
{
	int *p,i;  
	p = &i; 
	return 0;
}
First of all, because it is possible to declare as a pointer variable by applying * ahead of the variable identifier
Understand i that * has not adhered ahead of the variable identifier is a usual variable.

It substitutes it for pointer variable p in the operator in this example for the address of variable i.
In a word, there is an address of i in pointer variable p at this stage.
Naturally, contents of address and pointer variable p of i are sure to become the same with saying.
The following program is an example of the display of the address by the printf function and the confirmation.

 
#include <stdio.h> 

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

p = 0012FF80
&i = 0012FF80
It is splendidly the same value.
As for this, because the pointer variable is a variable, a certain meaning is natural.
Because i is substituted for p, and the value is displayed in the morrow.

However, note the type here.
The type of pointer variable p is a type to int of pointer type.
The address obtained by using the operator is a pointer type though the type of variable i is int type.
Therefore, i can be substituted for p and both can be displayed both by %p finger fixed child.


[   Null pointer   ]
..[detarame].. [atai] is substituted immediately after the pointer variable is declared.
Because it doesn't understand whether it is an address where the value can be used at all
If the address is used because of the misunderstanding, it surely becomes a bug.

It is necessary to distinguish whether to have substituted the address to prevent this.
Then, a null pointer is prepared in C language.
If you substitute the sign named NULL for the pointer variable
It can be shown that the address is not substituted.

 
int *p = NULL;
In the if sentence if you do like this If you compare whether it is p == NULL
Whether the address is substituted for p can be distinguished.

By the way, p = A null pointer is substituted as 0.
This is to decide as a grammar.
It is not NULL 0.

It returns to contents.


[3] Switch of mode

The pointer variable has two modes as explained in the foregoing paragraph.
It is usually a variable mode, and a pointer variable mode.
Especially, when the pointer variable is used without specifying anything, it becomes a pointer variable mode.

* Mark ahead of the variable to switch to the variable mode usually.
*The pointer variable to which the sign is applied becomes usually the same function as the variable quite.
The following program is an example of the usual switch of the pointer variable to the variable mode and use.

 
#include <stdio.h> 

int main(void)  
{
	int *p,i;  
	p = &i; 
	*p = 10; /* Substitute for the pointer variable switched to the variable mode usually */. 
	printf("*p = %d\n",*p);  
	printf("i = %d\n",i);  
	return 0;
}
The execution result of this program becomes as follows.

*p = 10
i = 10
In this program, it usually switches to the variable mode applying * to pointer variable p.
*p is pointer variable p that usually changes into the variable mode.
*It is possible to treat quite similarly to a usual variable as long as it is p.

Though the pointer variable that changes into the variable mode functions just like a usual variable usually
The memory used at that time is an address substituted at the pointer variable mode. In a word

Substitute the address of the memory to be read and written at the pointer variable mode.
Afterwards, usually switch to the variable mode and operate the memory.
Saying becomes the most basic usage of the pointer variable.

It is not specified that rewrite the memories how many directly.
The address of the memory to be rewritten is substituted, and switch and rewrite the mode.
It might be ..[natteirutame].. intuitively cramped in two step caring so to speak.

Substitute the address of variable i for pointer variable p in the fifth line in the program ahead.
p is usually switched to the variable mode by the sixth line, and ten is substituted for the address that p memorized.
At this time, because it is an address of variable i, what is the address that p memorized? ,in a word,
Consequently, the value of variable i will be rewritten in ten.

Variable i at this time and usual *p of the variable mode : if it explains a little more concretely.
Quite the same memory area is used.
*Do not say that i automatically changes into ten, too, if ten is substituted for p but
To begin with, this two shows the same place.


[   Strange sign *  ]
*..drinking.. sign has indeed three kinds of meanings, and becomes a cause of the mess.
Here, three distinctions are clarified.

Eyes are the one multiplication operators. It is so-called multiplication.
In the sign used in the expression, kai = 5 * Make eighthly and use it.

The second is an indirect reference operator. Usually make the pointer variable a variable mode.
Make like * p by the sign used in the expression and use it.
Because it is not possible to multiply by the pointer variable at the pointer variable mode
The distinction adheres even if the same sign as the multiplication operator is used.

The third is a sign used when the pointer variable is declared.
Only when declaring, it is used, and make like int *p and use it.
With indirect reference operator * usually switched to the variable mode though here is confusing
The sign of * used when declaring is another completely regardless sign.
It is not passed only to use the same by chance character.

I think that it must be more comprehensible to use all another characters in this three.
It is one of the defects of C language that allocates the same character.
However, because there is now no mending way
You must recognize that this three are signs of another meaning firmly.

It returns to contents.


[4], that is, short cut

It explained all functions of the pointer variable in the preceding clause.
Actually, the pointer has only the function as explaining in the preceding clause it.
Substitute the address of the memory at the pointer variable mode.
This is a full spectrum of the pointer that operates the memory after it switches to the variable mode usually.

There is naturally after here is understood [tekuru] doubt.
Will [jo] and ..drinking.. pointer after all be functions for which for what it is useful?
Substitute the address of the variable like the preceding clause in the pointer variable mode.
It switches to the variable mode, it operates, and it might be in how a troublesome thing usually what meaning.

This is not useful for such usage as having already doubted it it.
Usually operating the variable decreases and the mistake decreases very easily, too.

A true usage of the pointer is to use it as a short cut.
It is the same as that short cut that queues up in desktop of Windows.

The short cut is a file that indicates the file in another place somewhere.
If the short cut is opened, the indicated file is opened.
[Nimo] is not related, and because the short cut is not an indicated file, it
The short cut can be freely made anywhere.
Two or more pieces are not made, it even deletes, and there is an influence in the indicated file, too.

Only this is exactly a role of the pointer.
If you memorize the address of the variable that actually exists in the pointer variable
Even if it is a place where former variable cannot be used if it is a place where the pointer variable can be used
If the pointer variable is usually switched to the variable mode, it is possible to use it as well as former variable.
Exactly, it is possible to work like the short cut.


[ Pointer of   other language   ]
In general, it is said that the pointer is C language and a function only of C++.
Certainly, that's right in the meaning of operating the address of the specified memory.

However, a true usage of the pointer is to use it as a short cut.
There is a pointer in most practicable languages if it is the viewpoint.
The reference to Java is frequently used and exactly by such a function.
You may say that the SET statement etc. of Visual Basic are also similar.

To begin with, it is connected list and a tree structure, etc. there is no pointer.
A complex data structure cannot be achieved, and object-oriented is also difficult.
In that sense, from the pointer of Java and Visual Basic with an uncertain mechanism
It is easy to understand the pointer of C language to which the mechanism is clear.

It returns to contents.


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