{
int *p,*q,i;
p=(int *)100;
q=(int *)200;
i=q-p;
printf("%d",i);
}
it is getting output 50 in turbo c compiler.I do not know how it is working please reply me...
|
Light Poster
|
|
| 19Aug2011,21:49 | #1 |
|
main()
{ int *p,*q,i; p=(int *)100; q=(int *)200; i=q-p; printf("%d",i); } it is getting output 50 in turbo c compiler.I do not know how it is working please reply me...
|
|
Go4Expert Founder
|
![]() |
| 19Aug2011,22:14 | #2 |
|
Garbage value because it is actually subtracting the value stored at location 200 and 100 and not 200 and 100.
|
|
Mentor
|
![]() |
| 20Aug2011,12:27 | #3 |
|
No, C doesn't dereference pointers unless you use *, i.e. you would get the difference between the contents if you did
Code:
i = *q - *p; Do this: Code:
printf("%d",sizeof(int));
|
|
Ambitious contributor
|
![]() |
| 10Sep2011,00:09 | #4 |
|
Yup, I agree with xpi0t0s
On My Linux box, the output was 25 since on my machine int captures 4 bytes |
|
Banned
|
|
| 29Oct2011,00:06 | #5 |
|
in linux (gcc) the memory for int is 4.............
in turbo c the memory for int is 2............ i want to know which is the standard one declared by ANCI .................... |