Is it legal for a pointer of data type 'int' point to a float value? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 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

8th Apr 2018, 2:55 PM
RiGeL
RiGeL - avatar
4 Antworten
+ 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
8th Apr 2018, 3:42 PM
John Wells
John Wells - avatar
+ 3
John Wells thank you alot now it makes sense.
8th Apr 2018, 4:00 PM
RiGeL
RiGeL - avatar
+ 2
it is better not to put
8th Apr 2018, 3:01 PM
🅿️АУАН🇰🇿
🅿️АУАН🇰🇿 - avatar
0
Rauan thank you and is it legal to assign 0 value to pointers when intializing them? like :int *ptr=0
8th Apr 2018, 3:02 PM
RiGeL
RiGeL - avatar