hello guys,
here is my problem, pls go through.
pls tell me the answer and ***why***
main()
{
int *p,*q;
p=(int *)1000;
q=(int *)2000;
printf("%d",(q-p));
}
hello guys,
here is my problem, pls go through.
pls tell me the answer and ***why***
main()
{
int *p,*q;
p=(int *)1000;
q=(int *)2000;
printf("%d",(q-p));
}
srinu
If you use p = (int *)1000; you tell the compiler that you want to set p to point to memory address 1000. You should use *p = 1000; and *q = 2000;
Because the memory addresses are of an integer type, the output given will still be 1000, but the value pointed to by p will not be 1000 and the value pointed to by q will not be 2000.
Some kind of forced pointer difference exercise
The answer is 500 (if sizeof(int)==2)
The answer is 250 (if sizeof(int)==4)
There's a 1000 bytes between p and q, but pointer difference (q-p) returns the number of ints between the two pointers