Hello friends...!!! welcome back.We studied arrays in previous post. here we will discuss on pointers. so here we go.
What is pointer?
Pointer
is one type of variable which stores the
address of another variable as its value.
We know that computer has lots of memory cells which stores
the values and each memory cells having an address. Each location in memory
stores one byte of data, multi byte data types like integer, float, character
double. Let us understand this concept
with an example.
A=1;
we know that computer cannot stored any value directly. we assume any variable for doing this and this
variable has its own address in the memory cells. Computer find this value via
this address. let assume that A=1 is stored in 10 location in the memory cell.
So address of this variable is 10.
Variable = A.
Value = 1.
Address = 10.
Now, if the address of A is stored in another variable, that variable can
be called as a pointer to variable A because that variable stores the address
of variable A as its value.
Let variable B store
the address of variable A. So B is a pointer of A.
To describe the memory address of variable, (&) sign is
used. So
B = &A; (B is a pointer to A)
To describe a pointer variable, we will use (*) sign. So
*B = &A;
(Pointer B is stores the address of variable A)
POINTER DECLARATION:-
syntax
is: data type *variable name;
int *iB;
char *cB;
float *fB;
There are some rules in the pointer. They are as mentioned below:
->Addition of two pointers is not valid.
->Multiplication operation with any number is not valid.
->Increment and Decrement operations are valid.
->Addition and subtraction integer number with pointer
variable are valid.
CHAIN OF POINTER:
Means
that it is a pointer variable, which stores the address of another pointer
varable.
syntax is: data type **variable to variable;
(**)
means that variable to variable is a pointer to pointer of data type.
Eample:
Int
a=2;
Int
*b =&a;
Int **c=&b;
Here C stores the address of variable B
which is 100 and B stores the address of variable A.
So
*C=B; and *B=A;
then *C=A;
POINTER OF ARRAY:-
Every
program written using array can always written with pointers. Following is array:
Int a[3]; == a[0],a[1], a[2];
Here, array variable works as an address of first element
which is a[0]. Variable a[i] is represent in pointer like *(a+i).
Examples are:
a[0] or *(a+0)
a[1] or
*(a+1).
Array of pointer is a collection of pointer known by a
single name.
Syntax is:
data type *variable name[size];
Example:
*a[4];
This concept is used in the
pointer.
I hope your basic concept of this topic is clear. If there is any doubt, please feel free to mention it in the comment box. If you are interested you may join our facebook group New Age Informers.
Until then bye bye...!!!!!
Comments
Post a Comment