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 unni krishnan.r, Feb 12, 2011.

  1. unni krishnan.r

    unni krishnan.r New Member

    Joined:
    Apr 20, 2010
    Messages:
    204
    Likes Received:
    3
    Trophy Points:
    0
    Occupation:
    education
    Location:
    Kerala
    Home Page:
    Guys
    What will be output of following code snippet
    Code:
    Int n=1;
    while(n>0)
    {
    l++
    }
    
    :confused::confused:
     
  2. Stringx

    Stringx New Member

    Joined:
    Feb 9, 2011
    Messages:
    3
    Likes Received:
    1
    Trophy Points:
    0
    'Int'?
     
    rami hassan likes this.
  3. rpbear

    rpbear New Member

    Joined:
    Feb 11, 2011
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    is this your complete code?didn't the complier generate any error?
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    Output would be few errors.
     
  5. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Nothing, because it won't compile. Unless you mean "compiler output", in which case: errors.

    Int is not a valid type (C++ is case sensitive so "int" does not mean the same as "Int")
    l (lowercase L) is not defined so this will also throw an error.
    Also there is a semicolon missing after the ++.

    If the errors are fixed (and l really means n), then the output will be 1,2,3,... until n<0, which will be when the most significant bit of n is 1, which depends on sizeof(int). If int is four bytes on your system, the loop will terminate when n=0x80000000.
     
    shabbir likes this.
  6. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Unless of course Int isn't an error, and is actually typedef'd somewhere. If Int is typedef unsigned int, then the loop will never terminate (because n<0 is never true for unsigned variables), but the compiler should throw a warning about this.
     

Share This Page