Pointers
Pointers
----------
int a;
a=10;
float b;
b=12.33;
int *p;
where p is a pointer variable of type integer. That means it stores the address of
an integer variable.
* Unlike the normal variables, pointers are designed for taking addresses.
Initializing pointers
-----------------------
To initialize the pointer, use & the symbol, called address operator.
Syntax:
--------
data-type *pointer;
pointer=&variable-name;
for eg:
--------
int a=100;
int *p; /* p is an integer pointer */
p=&a; /* initializing the pointer */
* Because pointers representing address, getting the value of that address is very
fast.
* Though pointers stores the address, when the pointer is referenced it gives the
value of that address.
/* Prg on pointers */
#include <stdio.h>
#include <conio.h>
void main()
{
int a=100,*p;
/* p is an integer pointer */
clrscr();
p=&a; /* initialization of the pointer */
printf("The Value of a is %d\n",a);
printf("The Value of a is %d\n",*p);
printf("The Address of a is %u\n",&a);
printf("The Address of a is %u\n",p);
getch();
}
output
--------
The Value of a is 100
The Value of a is 100
The Address of a is 65345
The Address of a is 65345