top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Why does an integer pointer not store the address of a float variable?

+2 votes
639 views
Why does an integer pointer not store the address of a float variable?
posted Nov 16, 2018 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
Pointer is used to store the variable address irrespective of type/size of variable.
Only thing you need to take care is TYPECASTING if type of variable and type of pointer is not same.

1 Answer

+1 vote

You're getting undefined behaviour, because you're passing the wrong types to printf. When you tell it to expect a float, it actually expects a double - but you pass an int.
As a result it prints the wrong information, because printf relies entirely on the format string to access the arguments you pass it.

answer Mar 15, 2019 by Rushabh Verma R.
Similar Questions
+4 votes

What is the point of declaring Pointer of different types (eg. integer,float,char) as we all know pointer takes 4 bytes of space regardless which type of pointer it is and only contains address?

+1 vote

What type of conversion is not accepted in C and why?
a) char to int
b) float to char pointer
c) int to char
d) double to char

...