4 ms·
This totally destroyed me when I was learning C. The theory was: int *foo; makes more sense, because to access the int, you write: *foo = ...; But th
by millstone 9y ago
This totally destroyed me when I was learning C. The theory was:
int *foo;
makes more sense, because to access the int, you write:
*foo = ...;
But that's not an int, it's a crash! If you want an int, you have to make one.
Placing the asterisk next to the type made it all click for me.
- Y_Y 9y agodouble foo; compute(foo); That's not even a crash, just silent garbage. I don't know how you expect to do better with an uninitialised variable (except ints that default to 0). foo dereferences to an int, but what could you hope to happen if you never gave it some memory to point to?