C is statically typed, the expression sizeof *double_ptr
is solely computed according to these static type rules, namely double_ptr
points to a double
which has size 8
.
This program has undefined behavior, because you are writing to a memory range that you don't "own". All bets are off, it might crash or not. When doing such nasty conversions you are the responsible for that, not the compiler.
Edit, for nitpicks:
- functions without return type should not be tolerated by a conforming compiler. increase the warning level.
- when posting code here, please indent it properly
- the result of the
sizeof
operator is notint
butsize_t
an unsigned type. Printing that with"%d"
also has undefined behavior. Use"%zu"
.