Address + Number= Address
Address - Number= Address
Address++ = Address
Address-- = Address
++Address = Address
--Address = Address
When a pointer is incremented or decremented in C, the outcome is a new memory address, and this new address can be computed based on the size of the data type the pointer is associated with. by following formula:
Examples:
(1)What will be output of following c program?
#include<stdio.h>
int main(){
int *ptr=( int *)1000;
ptr=ptr+1;
printf(" %u",ptr);
return 0;
#include<stdio.h>
double *p=(double *)1000;
p=p+3;
printf(" %u",p);
return 0;
#include<stdio.h>
float array[5]={1.1f,2.2f,3.3f};
float(*ptr)[5];
ptr=&array;
printf("%u",ptr);
ptr=ptr+1;
printf(" %u",ptr);
return 0;
#include<stdio.h>
int far*a;
double b;
unsigned char c;
}ABC;
int main(){
ABC *ptr=(ABC *)1000;
ptr=ptr+2;
printf(" %u",ptr);
return 0;
#include<stdio.h>
char near*a;
long double d;
unsigned int i;
}ABC;
int main(){
ABC *ptr=(ABC *)1000;
ptr=ptr-4;
printf(" %u",ptr);
return 0;
#include<stdio.h>
int max=5;
int main(){
float *(*ptr)(int,int);
ptr=display;
(*ptr)(2,2);
printf("%u",ptr);
ptr=ptr+1;
printf(" %u",ptr);
return 0;
float * display(int x,int y){
float f;
f=x+y+max;
return &f;
}
No comments:
Post a Comment