Академический Документы
Профессиональный Документы
Культура Документы
What is Pointer?
Pointer is a powerful concept in the C language that provides more
efficiency and flexibility in the program execution. A Pointer is basically
variable that store the address of another variable
When we want to access a variable, the computer will search for that
variable in the memory sequentially, taking so much of time. To overcome
this problem the concept of Pointer is introduced. The Pointer stores the
address of variable which helps to locate the variable in the memory quickly
and efficiently.
N
P
50
735
735
N is a variable that holds the value 50. The address of the n is 735 which is
stored in pointer. The addresses of the Pointer are 831 which is stored in one
register in the processor. When we access the pointer it provides us the
address of variable in the memory which saves the time for searching the
variable in the memory.
Advantages of Pointer:1. Pointers are more efficient in handling array and data table.
2. Pointer can be used to return multi-values from a function.
3. Pointers make string handling easier and save storage place.
4. Pointer allows C language to support Dynamic memory management.
5. Pointers reduce length and complexity of the program.
6. Pointers increase the execution speed and reduce the program execution
time.
7. Pointer provides a efficient tool for handling data structure.
8. Pointer permits reference to function.
Declaration of Pointer:Like simple variable we can also declare the pointer variable. The Data type
of the Pointer variable must be same as the data type of the variable the
address of which we are going to store in the Pointer.
Syntax:Example:-
To declare the Pointer special operator (*) asterisk sign is used before
the Pointer variable name in the declaration.
Assigning address of the Variable to the Pointer:After declaring the next step is to assign the variable address to the pointer
using the assignment statement.
1
Syntax:-
Example:-
p=&n;
Explain Pointer and one dimensional array:Like a simple variable we can also use the pointer with array. An array
is a collection of elements each having their own address in memory. The
Pointer is assign to the address of first element. To move the pointer to the
next address Pinter value is incremented by 1.
Example:-
500
502
504
506
508
Porgram:void main()
{
int om[10], per[10],*p,*q,n;
p=&om[0];
q=&per[0];
printf(enter marks of 10 students);
for(n=0;n<=9;n++)
{
scanf(%d,&*p);
*q= *p*100/500;
p++;
q++;
}
p=p-10;
q=q-10;
for(n+0;n<=9;n++)
{
printf(%d\t%d\n, *p, *q);
p++;
q++;
}
getch();
}
Note- The pointer is incremented by scale factor like in case of integer
scale factor is 2. If the first address is 500, after incremented the next
address is 502.