mahaju
Full Member level 2
#include<stdio.h>
int main(){
float a=2.5;
printf("%f\n",a);
printf(" as int = %d \n as float = %f \n as hex = %x",a,a,a);
printf("\n%f",a);
return 0;
}
The output is
2.500000
as int = 0
as float = 0.000000
as hex = 40040000
2.500000
So what is up with the middle 3 lines??? I am not sure about the hex representation but I am sure it shouldn't show 0 for the int and float representations.
I used codeblocks 8.2 for compiling and it uses gcc I think.
---------- Post added at 02:19 ---------- Previous post was at 02:04 ----------
Also,
#include<stdio.h>
int main(){
float a=2.5;
printf("%f\n",a);
printf(" as int = %d\n", a);
printf(" as float = %f\n",a);
printf(" as hex = %u\n", a);
printf("\n%f",a);
return 0;
}
here as int = 0, as float = 2.500000 and as hex = 0
But why??
I thought it should show as int = 2
and how do I see what hex value it keeps in memory for floating points?
int main(){
float a=2.5;
printf("%f\n",a);
printf(" as int = %d \n as float = %f \n as hex = %x",a,a,a);
printf("\n%f",a);
return 0;
}
The output is
2.500000
as int = 0
as float = 0.000000
as hex = 40040000
2.500000
So what is up with the middle 3 lines??? I am not sure about the hex representation but I am sure it shouldn't show 0 for the int and float representations.
I used codeblocks 8.2 for compiling and it uses gcc I think.
---------- Post added at 02:19 ---------- Previous post was at 02:04 ----------
Also,
#include<stdio.h>
int main(){
float a=2.5;
printf("%f\n",a);
printf(" as int = %d\n", a);
printf(" as float = %f\n",a);
printf(" as hex = %u\n", a);
printf("\n%f",a);
return 0;
}
here as int = 0, as float = 2.500000 and as hex = 0
But why??
I thought it should show as int = 2
and how do I see what hex value it keeps in memory for floating points?