Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

FIND THE OUTPUT IF THE INPUT IS 5 5.75
void main()
{
int i=1;
float f=2.25;
scanf("%d%f",&i,&f);
printf("%d %f",,i,f);
}
ANSWER IS 5 AND 2.25 WHY?

Answer Posted / suman halder

There is a tiny mistake in the question..It should be..

FIND THE OUTPUT IF THE INPUT IS 5 5.75

void main()
{
int i=1;
float f=2.25;
scanf("%d %d",&i,&f);
printf("%d %f",,i,f);
}
ANSWER IS 5 AND 2.25 WHY?

The answer of this question actually lies within the question itself..
if we look at the scanf statement ,then the actual reason of the output will be revealed..
In scanf,we are trying to get the input into a floating point number through %d format specifier which is the format specifier for integers..here,lies the anomaly..
nothing actually get stored within f through scanf ,so the previous value of f is retained..and that gets printed..
thats it..

*** if we try the reverse of it.i.e using %f,we wanna get the value into an integer..the compiler may report some error like "floating point format not linked"...we can abstain the error by intoducing a linkfloat function but still there will be some anomaly in the value that get stored in the variable ..so,to get the expected output we need to specify the correct format specifier....dnt trust printf or scanf to perform the proper typecasting for u..
do it explicitly..

linkfloat()
{
float a,*b;
b=&a;
a=*b;
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between call by value and call by reference in c?

1216


Write a code to remove duplicates in a string.

1084


WRITE A PROGRAM TO MERGE TWO SORTED ARRAY USING MERGE SORT TECHNIQUE..

2138


What is declaration and definition in c?

1180


what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;

2698


Why header file is used in c?

1164


If fflush wont work, what can I use to flush input?

1155


how to write optimum code to divide a 50 digit number with a 25 digit number??

3301


What is modifier & how many types of modifiers available in c?

1074


i want to know the procedure of qualcomm for getting a job through offcampus

2519


What is the correct declaration of main?

1266


What is clrscr in c?

1173


In the DOS enveronment, normal RAM that resides beyond the 1mb mark. a) expanded memory b) swapped memory c) Extended memory d) none

1267


Is array a primitive data type in c?

1133


Explain what does it mean when a pointer is used in an if statement?

1108