Your program will give the compilation error because you escaped `` by
putting \.
If you remove the `` escape then it works fine.
C has fixed set of escape character which it understand and if it is unable
to understand then it remove the escape character(\) and keep the remaining
part.
In
@Nidhi -
I guess thats correct.. but am still not 100% sure about how the
explanation goes..
Actually printf() is a variable argument function and so the
acceptance of a value of a data type depends on the way it is defined
in the library..
and since %f if encountered in the string must be
So its like the printf function cannot convert a int to float and hence
prints the last
float value which was given to printf.
Correct if i have understood it wrong.
On Mon, Oct 11, 2010 at 10:25 PM, Asquare anshika.sp...@gmail.com wrote:
This modified code also works in exactly the same way..
Here is the modified code. Maybe we can find something new.
Code:
#includestdio.h
int main()
{
union {
struct {
int x;
float t;
};
double u;
} a;
a.x=0;
scanf(%f,a.t);
printf(%f\n,a.t);
printf(%f\n,a.u);
a.x=90;
printf(%d\n,a.x);
printf(%f\n,a.x);
This modified code also works in exactly the same way..
The explanation I had given earlier is correct..
and holds for this code as well
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
As far as I have understood.. Its basically that
once you give the input to t as float, that value is displayed for all
the printf functions except one
because of the %f modifier.. the %f modifier cannot accept x (int) as
a successful argument so it takes the
latest float value..
but in case of
On Oct 9, 11:51 am, Ashutosh Tripathi ashu.nit...@gmail.com wrote:
hey! i am also unable to explain but one thing i got
if we use %d in place of %f,we will get the correct output.
we must use %d as x is of int data type.so the code is itself
wrong.
or
u
printf is very week to convert int to float or vice versa..
please read D. Ritchie for details.
On 10/9/10, @shu ashu.nit...@gmail.com wrote:
On Oct 9, 11:51 am, Ashutosh Tripathi ashu.nit...@gmail.com wrote:
hey! i am also unable to explain but one thing i got
if we use %d in