sir you said that char pointer can see only 1 byte so cant use for dereferencing but float is of 4 byte than why can’t we use it for dereferencing for integer as it look for 4 byte of block?
Datatype of pointer
Hello @S18ML0036,
You are right. Although int and float are different types, there should be no difference between their pointers int* and float*. In general, this is the case. However, the binary representation is different between int and float. Therefore accessing an int with a float* pointer leads to garbage being read from the RAM.
Furthermore, what you have on your machine is not the general case, but hardware and implementation-dependent.
For example, float and int variables are usually 32bit long. However, there are systems where the int has the only 16bit. What happens now if you try to read a float from an int* pointer?
Hope, this would help.
Give a like if you are satisfied.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.