Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis0
Why casting pointer is unsafe if casting for example from long to float
Long var=10; Float*ptr=(floa*)&var;
4 Respostas
+ 3
Found this nice answer on StackOverflow
https://stackoverflow.com/questions/30276645/typecasting-int-pointer-to-float-pointer
Casting a value and casting a pointer are different scenarios. Casting a pointer changes theĀ wayĀ to refer to theĀ typeĀ value, which canĀ almost certainlyresult in a mis-alignment inĀ mostĀ of the cases.
As perĀ C11Ā standard document, chapterĀ Ā§6.3.2.3
A pointer to an object type may be converted to a pointer to a different object type. If the resulting pointer is not correctly aligned for the referenced type, the behavior is undefined.
+ 2
Both are depending on the compiler, but a pointer is the same size no matter what it points to. On most 32 bit compiler a pointer is 4 bytes while on 64 bit they are typically 8 bytes.
+ 1
In general yes. But, It depends on the compiler... I think š¤
Bcz size of pointer depends on memory size, like 32 bit, 16 bit etc., int size is specific to compiler.
Hope this helps....
0
Louis thanks A lotš
I got itšŖ
Can u tell me is there is a difference between the size of pointer and int?
Thanks in advance