Pointers in C Programming Study Material
Pointers in C Programming Study Material
Material
Pointers
One of the most important and powerful g) Pointers allows for references to function,
features in C language is pointer. this may facilitate passing of function as
“A pointer is a variable, it may contain the arguments to other functions.
memory address of the another variable.”
pointer can have any name that is legal for Pointer declaration:
other variable. It is declared in the same Syntax data-type * pointer name ;
manner like other variables. It is always Example:
denoted by * operator. int *a
A pointer is a variable whose value is, also char *b
an address. Each variable has two attributes; float *c
address and value. A variable can take any int *a - means „a‟ contains the address of
value specified by its data type. variable, which is integer variable.
char *b - means „b‟ contains the address of
variable, which is character variable.
float *c - means „c‟ contain the address of
variable which is float variable.
Accessing variable through pointers:
Example:
• A pointer to an integer is a variable that int *p
can store the address of that integer. x = 15 ;
• Second the value contained by a pointer p=&x
must be an address which indicates the Variable Value Address
location of another variable in the memory. x 15 4001
So pointer is called as address variable. p 4001 4005
Program to access through variable
Features of pointers: pointer:
a) Pointers are efficient in handling data and # include < stdio.h>
main ( )
associated with array.
b) Pointers are used for saving memory {
space. int a = 22, *a ;
c) Pointers reduce length and complexity of float b = 2.25 , *b ;
the program. a=&a;b=&b;
d) Pointer helps to make letter use of the printf ( “ \ n value of a = % d”, * a) ;
available memory. printf ( “ \ n value of b = % d”, * b) ;
e) Since the pointer data manipulation is }
done with address, the execution time is-
faster. Output:
f) Two-dimensional and multidimensional Value of a = 22
array representation is easy in pointers. Value of b = 2.25