You are on page 1of 2

Pointers

A pointer is a derived data type. This is the one which stores the address of data in
memory, we will be in position to access the data directly and do calculations over it. The
standard concept is, we access the data from memory using variable name it gets the
data and operations are done over them. But the pointer is different that the accessing is
done by address the data is stored so that it will be advantage of decreasing the
instructions and overheads of standard usage. This is very specific because every data
has its own memory space and we are working over it. We are able to store the address
in a variable, which is only done only using & operator. The one thing to remember here
is when we execute the program once we get one type of address and this will be
changed to other when we execute it other time.

pointer can be associated with following concepts


*pointer constant
*pointer variable
*pointer values

Pointer variable

A variable which holds address of another variable is called a pointer variable

P=&a

So the pointer p has address of a and the value that that cointained in that address can
accessed by *p

Pointer varible

It contains even and odd bank. Logical address from 0 to 65535

Pointer value

the memory address assigned to variable by the system are called pointer values.

Pointer declaration

Pointer declaration is done using the indirection operator; it is then followed by data type
we are using to store in it and name of pointer variable.
The pointer type can be of any data type we are in use of storing in it. It can be of int,
char, float etc.

Initialization of pointer variables

The garbage value will be collected in these variables till they are initialized. The same thing
happens in the pointers also, the pointer contain a value the could not be a valid address
location. So the removal of this is mandatory and if the address it has is valid it leads to
a run time error. So initializing a pointer variable is a important thing, it is done as follows
int x;
int *p = &x;
Here the two steps are done at once the two steps are
int *p;
*p=&x;

The combination of these two steps gives us the initialization of pointers. So to avoid the
run time errors we can initialize it with null. It can be as
int *p = NULL;

Pointers to Pointers

This concept says that we can point a pointer to pointer that is pointer
concerned to variable will have address of that variable and that pointer is pointed again
to that pointer. So that pointer with address of variable is stored in other pointer. We can
use in different operations. The indirection does not have limit but it is considerable only
up to two levels. If we take a variable a, this is pointed by pointer P and this p is pointed
by Q, we have the capability that
int a;
int *p;
int **q;
These are taken in program and if we give this
printf(“%d”, a);
printf(“%d”, *p);
printf(“%d”, **q);

Malloc

The malloc function allocates a block of memory that contains the number of bytes
specified in its parameter. It returns a void ponter to first byte of allocated memory. The
allocated memory is not initialized. You should therefore assume that it will contain
garbage and initialize is required.The prototype is as:
void *malloc (size_t size);

Calloc

It allocates a conyiguous block of memory large enough to contain an array of elements


of specified size. So it requires two parameters as number of elements to be allocated
and for size of each element. It returns pointer to first element of allocated array. Its
prototype is:
void *calloc (size_t element_count,size_t element_size);

You might also like