0

Here are we use typecasting from pointer to integer, but output of arithmetic operation are different from expected answer, Why?

Source Code :

int main(){
    int *p,*q;
    p = 1000;
    q = 2000;
    printf("%d",q-p);
return 0;
}

Output: 250

1 Answers1

0

The same reason due to which p++ will give you 1004. Since sizeof(int) on your machine is 4, hence each operation is shown wrt sizeof(int), even the difference i.e. 1000/4.

Sandy
  • 895
  • 6
  • 17