+ 2
Is it legal for a pointer of data type 'int' point to a float value?
i think its illegal but I am not sure please someone tell me and thank you
5 Answers
+ 6
C++ doesn't make many things illegal and you can get around them if you truely want. I've modified constants via pointers to prove it is doable and here print a float as an integer. Note that I also initialized the pointer with 0, which worked and tests to nullptr. However, I've been on a system that -1 was the value of nullptr as 0 was a valid addressable address so for safety use the symbol.
https://code.sololearn.com/csj8LxOGGcbS
+ 3
John Wells thank you alot now it makes sense.
+ 2
it is better not to put
0
Rauan thank you and is it legal to assign 0 value to pointers when intializing them? like :int *ptr=0