Casting Pointers

When casting a double into integer pointer, which 4 bytes will be assigned to the pointer ? first or last ?

1
2
  double x = 10.25;
  int *p = (int *) &x;  // output 
The first, meaning that p will point to the byte of x with the lowest address.
But a better question to ask is "what will be the value of *p, the integer that you're pointing to? It probably won't be 10. It depends on the hardware you're running on. When you make a cast like this you're saying "take the 4 bytes (if sizeof(int)==4) at the beginning of x and reinterpret them as an integer." The value will only be useful if you know the representation of a double on the hardware.
Topic archived. No new replies allowed.