Minggu, 13 Oktober 2013

Pointer variable in C Language

Definition : A variable which holds address of another variable or obtained memory address is called a pointer variable. In other worlds, pointer variable is a variable which holds pointer value
(i.e. , address of a variable)

For example, if I is a variable and address of I is stored in a variable p as shown below:
P=&I;
Then the variable p is called a pointer variable. The memory organization after executing the above statement is shown below:

Variable
Address
Memory Locations

0



2



4
100
I
……..
200
J
65534
300
K



variables
address
Values

                                                    Physical representation

Pointer variable in C Language
Logical representation

Note that the address of a variable I which is 65535 is assigned to variable p. So, even though address of p is 50000 (pointer value), the value stored in that location is 65534. Since p is a variable which constants address of a variable, the variable p is called pointer variable. In the logical representation, the variable p points to the variable i. So, we say that the variable p points to I and hence the name pointer. The relationship between p and I is pictorially represented as shown below:

Pointer variable in C Language



If we use the statement: p = &j; then the variable p constants the address of a variable j.

Tidak ada komentar:

Posting Komentar