C - Pointers - Discussion

You Are Here :: Home > C > Pointers - Discussion

 



Q.

#include

int main(){
int *p=(int *)1000;
int *temp;
temp=p;
p=p+2;
printf("%u %u\n",temp,p);
printf("difference=%d",p-temp);
return 0;
}

A. 1000 1000 B. 1000 1002
C. 1000 1004 D. 1002 1000

Answer: Option C
Explaination:

Here two pointer p and temp are of same type and both are pointing to int data type varaible.

p-temp = (1004-1000)/sizeof(int)
=4/2
=2



Discussion

Your Comments Goes here...
NameDiscussion