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?

Answers were Sorted based on User's Feedback



FIND THE OUTPUT IF THE INPUT IS 5 5.75 void main() { int i=1; float f=2.25; scanf("..

Answer / biren

5 2.25

Is This Answer Correct ?    6 Yes 4 No

FIND THE OUTPUT IF THE INPUT IS 5 5.75 void main() { int i=1; float f=2.25; scanf("..

Answer / hari.11

hey,
if we give input as 5 5.75
output would be: 5 5.750000

for further queries and discussions, visit..

http://forum.campusmaniac.com/
http://www.campusmaniac.com/

Is This Answer Correct ?    1 Yes 0 No

FIND THE OUTPUT IF THE INPUT IS 5 5.75 void main() { int i=1; float f=2.25; scanf("..

Answer / 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

FIND THE OUTPUT IF THE INPUT IS 5 5.75 void main() { int i=1; float f=2.25; scanf("..

Answer / reshma pawar

there is error in
printf("%d %f",,i,f);
because 2 (,) operators are used
an if operator is removed then output will be
5 5.750000

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

Can a pointer be static?

0 Answers  


what is computer engg

1 Answers  


Explain what is the difference between a string and an array?

0 Answers  


What is the output of below code? main() { static int a=5; printf("%3d",a--); if(a) main(); }

1 Answers  


what is use of malloc and calloc?

0 Answers  






How to add two numbers with using function?

2 Answers   Miracle Solutions,


12345 1234 123 12 1

2 Answers  


Explain how does flowchart help in writing a program?

0 Answers  


how to find out the union of two character arrays?

2 Answers  


What is 2c dna?

0 Answers  


Is c is a high level language?

0 Answers  


3. Program to print all possible substrings. ex: String S St Str Stri Strin String t tr tri trin tring r

3 Answers   Huawei,


Categories