C
chandanlinster
I came to know that using format specifiers(in printf or scanf) to
convert between float and int is a really bad idea. This is because the
printf prints junk values when it encounters such a type of conversion.
For eg:
#include <stdio.h>
int
main()
{
float a = 3.1415;
printf("a = %d\n", a);
return 0;
}
/*Output*/
a = -1073741824
My doubt is, Would this case only apply between INTs and FLOATs, or is
the same reasoning valid for other types.
If the same reasoning is valid for other types, how come the following
program works correctly?
#include <stdio.h>
int
main()
{
unsigned int ch;
for(ch = 65;ch <= 255;ch++)
printf("%d %c\n", ch, ch++);
return 0;
}
convert between float and int is a really bad idea. This is because the
printf prints junk values when it encounters such a type of conversion.
For eg:
#include <stdio.h>
int
main()
{
float a = 3.1415;
printf("a = %d\n", a);
return 0;
}
/*Output*/
a = -1073741824
My doubt is, Would this case only apply between INTs and FLOATs, or is
the same reasoning valid for other types.
If the same reasoning is valid for other types, how come the following
program works correctly?
#include <stdio.h>
int
main()
{
unsigned int ch;
for(ch = 65;ch <= 255;ch++)
printf("%d %c\n", ch, ch++);
return 0;
}