Answer: In variable-length argument lists such as printf's, the old "default argument promotions" apply, and type float is implicitly converted to double. So printf always receives doubles, and defines %f to be the sequence that works whether you had passed a float or a double.
(Strictly speaking, %lf is *not* a valid printf format specifier, although most versions of printf quietly excepts it.)
scanf, on the other hand, always accepts pointers, and the types pointer-to-float and pointer-to-double are very different (especially when you're using them for storing values). No implicit promotions apply.
Showing posts with label scanf. Show all posts
Showing posts with label scanf. Show all posts
Thursday, April 9, 2009
Wednesday, January 21, 2009
Find the correct output
void main()
{
char a[]=”rama”;
char b[]=a;
printf (“%d %s”, sizeof (b),b);
}
(a) 5 rama
(b) 4 rama
(c) 5 r
(d) None of these, some other reason
{
char a[]=”rama”;
char b[]=a;
printf (“%d %s”, sizeof (b),b);
}
(a) 5 rama
(b) 4 rama
(c) 5 r
(d) None of these, some other reason
Subscribe to:
Posts (Atom)