1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

what will be the output?

Discussion in 'C' started by spoddar66, May 31, 2010.

  1. spoddar66

    spoddar66 New Member

    Joined:
    May 25, 2010
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    void main()
    {
    float a=0.7;
    if(a<0.7){
    printf("C");
    }
    else{
    printf("C++");
    }
    }
    
     
  2. pkbis28

    pkbis28 New Member

    Joined:
    May 25, 2010
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    ANS:c
    0.7f is float constant. Its binary value is written in 32 bit.
    0.7 is double constant(default). Its binary value is written in 64 bit.
    0.7L is long double constant. Its binary value is written in 80 bit.
    binary value of 0.7=(0.1011 0011 0011 0011 0011 0011 0011 0011 0011 0011 0011)
    now here a is a float variable while 0.7 is double constant .so a contain only 32 bit value
    i.e
    a=0.1011 0011 0011 0011 0011 0011 0011 0011
    while
    0.7=0.1011 0011 0011 0011 0011 0011 0011 0011 0011 0011 0011....
    It is obvious a<0.7>
     
  3. gpk kishore

    gpk kishore New Member

    Joined:
    Jun 30, 2011
    Messages:
    82
    Likes Received:
    0
    Trophy Points:
    0
    very good explanation sir
    i have understood it
    but i have heard that 0.7 will store in memory space as 0.699999999 some what
    so it will be less than 0.7
    therefore it prints c
    sir
    did my explanation is correct or not
     
  4. gpk kishore

    gpk kishore New Member

    Joined:
    Jun 30, 2011
    Messages:
    82
    Likes Received:
    0
    Trophy Points:
    0
    sir(spoddar66)

    which book are you following
    please tell me sir
     
  5. HARIT

    HARIT New Member

    Joined:
    Jul 16, 2011
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    Ans: C

    a float variable (0.7) stores as 0.69999999...
     

Share This Page