C Programming - Control Instructions - Discussion

9. 

What will be the output of the program?

#include<stdio.h>
int main()
{
    float a = 0.7;
    if(0.7 > a)
        printf("Hi\n");
    else
        printf("Hello\n");
    return 0;
}

[A]. Hi
[B]. Hello
[C]. Hi Hello
[D]. None of above

Answer: Option A

Explanation:

if(0.7 > a) here a is a float variable and 0.7 is a double constant. The double constant 0.7 is greater than the float variable a. Hence the if condition is satisfied and it prints 'Hi'
Example:

#include<stdio.h>
int main()
{
    float a=0.7;
    printf("%.10f %.10f\n",0.7, a);
    return 0;
}

Output:
0.7000000000 0.6999999881


Alisha said: (Nov 24, 2010)  
please give me explanation of your example
#include<stdio.h>
int main()
{
float a=0.7;
printf("% 10f %f\n",0.7,a);
return 0;
}
please explain printf statement

M.Manoji said: (Mar 29, 2011)  
How i know this 0.7 is double ? and why i can not assume that 0.7 is float value ? is there any default assumption for this declaration ?

Sundar said: (Mar 29, 2011)  
@M.Manoji

0.7 --> The compiler will assume it as a double value by default.

If you want the compiler should treat 0.7 as float value then you have specify the value along with a postfix character 'f'.

Example: 0.7f

/* Example Program executed in Turbo C */

#include
int main()
{
printf("%d, %d, %d", sizeof(0.5), sizeof(double), sizeof(3.14f));
return 0;
}

//Output: 8 8 4

Rahul said: (Sep 16, 2011)  
@sundar.

Good explaination. !

Ketaki said: (Dec 14, 2011)  
How the value comes 0.699999818?

Pon said: (Dec 16, 2011)  
Please give me explanation of your example

#include<stdio.h>
int main()
{
float a=0.7;
printf("% 10f %f\n",0.7,a);
return 0;
}

Govind Verma said: (Apr 6, 2012)  
What will be the output.
int main()
{
flaot a=3.5;
if(a==3.5)
printf("tru");
else
printf("false");
return 0;
}

S.R.Rambabu said: (Aug 25, 2012)  
The given value is 0.7 and the value of a is 0.7 the symbol > it defines both the symbol equalto(=) and (>) so the output is "hi".

Mallesh said: (Nov 28, 2012)  
#include<stdio.h>
int main()
{
float a=0.7;
printf("%.10f %.10f\n",0.7, a);
return 0;
}

Explanations please.

Naresh N said: (Jul 22, 2014)  
#include <stdio.h>
main()
{
if (sizeof(int) > -1)
printf("True");
else
printf("False");
}

Can any one explain me why answer is false?

Ayush Rai said: (Jul 28, 2014)  
It doesn't give the same output for 0.66 neither for 0.8 even in your compiler. And when I tried printing the digits it came out to be opposite in trend both times 0.66!>a neither is 0.8. See for yourself and please explain.

Pratibha said: (Mar 7, 2015)  
#include<stdio.h>
int main()
{
float a=0.7;
printf("%10f %10f\n",0.7, a);
return 0;
}

This gives output: 0.70000 0.70000

#include<stdio.h>
int main()
{
float a=0.7;
printf("%.10f %.10f\n",0.7, a);
return 0;}

0.7000000000 0.6999999881.

Then what %f differs from %f?

Naresh Kalluri said: (Mar 27, 2016)  
They are not given (0.7 >= a)
So the condition is false.
It will prints the else statement in that hello message will be printed.

Swati said: (Jul 18, 2016)  
When we place 0.8 instead of 0.7 then prints Hi. Why?

Please elaborate.

Jason said: (Dec 28, 2017)  
What happens if the 0.7 is replaced by 0.6? or simply by Experiment (gcc on Ubuntu) shows a different story than the theory (double to float).

Saneh Sharma said: (Mar 24, 2018)  
please explain this.

#include <stdio.h>
int main()
{

char a='\101';
printf("%c",a);
}

Divya said: (Dec 9, 2018)  
Here not mention 0.7 has double? Then how can I take it as double maybe it is float also?

Kaira said: (Sep 24, 2019)  
How can we understand that 0.7 is double not float? Please explain me.

Gaurav said: (Sep 25, 2019)  
As per my knowledge, it's.

#include <stdio.h>
main()
{
if (sizeof(int) > -2)
printf("True");
else
printf("False");
}

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.