POINTER ARITHMETIC OPERATIONS
- · Pointers offers arithmetic operations in C-language.
- · But in pointer variables increment, decrement, postfix and prefix means increment or decrement by address of a variable.
- · Arithmetic operations applied on pointers, Not on addresses
/*
EXAMPLE PROGRAM FOR POINTER ARITHMETIC OPERATIONS */
main()
{
int *p,*q,x=20,y=10;
clrscr();
p=&x;
q=&y;
printf(“Addition=%d”, (*p) + (*q));
printf(“Substraction=%d”,(*p)-(*q));
printf(“Multiplication=%d”, (*p) * (*q));
printf(“Division=%d”,(*p)/(*q));
getch();
}
/*
EXAMPLE PROGRAM FOR INCREMENT, DECREMENT, PREFIX, POSTFIX OPERATIONS */
#include<stdio.h>
#include<conio.h>
main()
{
int a=10, *p;
p=&a;
clrscr();
printf("\n The address of a is
=%d",a);
printf("\n The address of a is
=%d",a++);
printf("\n The address of a is
=%d",++a);
printf("\n The address of a is
=%d",a--);
printf("\n The address of a is
=%d",--a);
printf("\n The address of a is
=%d",a);
getch();
}
No comments:
Post a Comment