You are on page 1of 9

POINTER

DEFINITION:
In computer science, a pointer is a programming language
data type whose value refers directly to (or "points to")
another value stored elsewhere in the computer memory
using its address
It contains only the Memory Location of the variable
rather than its content.

EXAMPLE FOR POINTER:

int X = 547;
int *ptr;
ptr=&X;

HERE:
Variable
name

ptr

Content
s

Locatio
n

547

4000

4000

4036

According to above figure, By the help of ptr variable we


stored the address of variable X in address 4036

Pointers are used in following variables


Variables of any basic data type
An Array
Functions
Structures, and
Unions

Advantages of Pointers
To point to different data structures
To achieve clarity and simplicity
More compact and efficient coding
To return multiple values via functions
Dynamic memory Allocation

Operators used with Pointers


1.The address operator
& [ampersand]
An address operator gives the address of
the variable.
2.The direction operator
* [asterisk]
The direction operator gives the
value of the variable that the pointer is
pointing to. This is known as dereferencing

POINTER DECLARATION
In c Every Variable must be Declared its type
,since pointer variables contain address of separate
Data type , They must be Declared before use them
the declaration of pointer variable takes the
following form

Syntax:

data _type
name

* pt_

EXAMPLE:

1. Int *p ;
2. float *p;
HERE:
1. Declares the variable p as a pointer variable that points to an integer data
type
2. Declares the variable p as a pointer variable that points to an float data type

POINTER
INITIALIZATION
As ordinary variables are Initialized with in Declaration
part of the program ,
The Pointer variables can initialized by Accessing address of the
variable that are
Used in the program .

Syntax
:

Data_type *ptr =
expression

Where:
data_type = Any Basic Data type
*ptr

= pointer variable

expression = another variable or may be constant

PROGRAM EXAMPLE
# include < stdio.h>
# include < conio.h>
void main()
{
int a=486;
int *b=NULL ;
b=&a;
printf( Address of a = %d ,b);
printf ( The content of a = %d ,*b);
}
OUT PUT:
Address of a = 4056
The content of a = 486486

CONCLUSION
Pointers are one of the most useful
and dangerous features in c.
Unintialised pointers can cause the
system to crash and moreover they
can create bugs within the
programs.
But their advantages overshadow
their limitations

You might also like