edited by
341 views
3 votes
3 votes

Cosider the code snippet

CODE 1

float a= 10.25;

if(a==10.25)
       ptint " A "
else 
   print "B"
print "C"


CODE 2

float a =10.25;
n=15.25;
while(n!=10.25)
{
    print "*";
    n--;
}
Number of times * printed ?

Please explain the output in both cases

edited by

1 Answer

0 votes
0 votes

Yes, your argument is quite ostensible.Though the output may vary with compilers.

For CODE1, OUTPUT = > AC

For CODE2, OUTPUT = > ***** (5 times)   (You havn't specified the data type of n , so I am assuming it to                                                                                be FLOAT) 

If you don't specify "10.25"  as "10.25f"  ,then the program will store it in "Double Precision Floating Point format " albeit the right hand side of the expression i.e. variable "a"  is declared as FLOAT (Single Precision Format )  due to which the program may give "an unexpected output"

Related questions

0 votes
0 votes
1 answer
1
0 votes
0 votes
1 answer
4
Karthik Akula asked Oct 29, 2016
4,070 views
what is the output for the below program ?main() { float x=1/2; float y=1/2.0; printf("%f, %f", x,y); }A) 0.500000, 0.500000B) 0.500000, 0.000000C) 0.000000, 0.000000D) 0...