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

printf() unusual behavior

Discussion in 'C' started by rex sinha, Aug 12, 2008.

  1. rex sinha

    rex sinha New Member

    Joined:
    Jun 26, 2008
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Hi friends...

    void main()
    {
    float a=2.45;
    printf("%d%f",a,a);
    }
    what would be the output of above mentioned question and why?
    plz. help me.
    thanx in advance.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    Try running and see what it gets?
     
  3. rex sinha

    rex sinha New Member

    Joined:
    Jun 26, 2008
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    thanx...
    It gives unexpected output...
    let me tell u an example

    void main()
    {
    float a=0.7;
    printf("%d%f",a,a);
    }
    output :---------
    0
    and
    0.0000000
     
  4. arkangel

    arkangel New Member

    Joined:
    Aug 11, 2008
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    what about this

    printf(%d%f,(int) a,a);
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    Change your declaration to
    float a = 0.7f;
    and see whats the output.
     
  6. faizulhaque

    faizulhaque New Member

    Joined:
    May 23, 2008
    Messages:
    213
    Likes Received:
    3
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Karachi
    Home Page:
    nothing is heppened.
    it b/c float takes the 4bytes in stact memory of type floating point, but if our program give him a integer value than it's will converted into 0 or 0.00000000,
     

Share This Page