In C, if I cast & dereference a pointer, does it matter which one I do first?

前端 未结 6 1767
南旧
南旧 2020-12-08 05:39

In C, you can cast both simple data types like int, float, and pointers to these.

Now I would have assumed that if you want to convert from

6条回答
  •  旧时难觅i
    2020-12-08 06:23

    Cast, then dereference means "pretend I am pointing to this other thing, and then get the other thing that is supposedly being pointed at".

    Dereference, then cast means "get the thing I am actually pointing at, and then convert it to this other thing by the usual rules".

    "The usual rules" can change the bits around in order to get a value of another type that logically represents the same value. Pretending you're pointing at something you're not actually pointing at cannot.

提交回复
热议问题