What will be the output

Skilled contributor
12Feb2011,12:19   #1
unni krishnan.r's Avatar
Guys
What will be output of following code snippet
Code:
Int n=1;
while(n>0)
{
l++
}
Newbie Member
12Feb2011,12:57   #2
Stringx's Avatar
'Int'?
rami hassan likes this
Light Poster
12Feb2011,13:05   #3
rpbear's Avatar
is this your complete code?didn't the complier generate any error?
Go4Expert Founder
12Feb2011,16:00   #4
shabbir's Avatar
Output would be few errors.
Mentor
14Feb2011,01:14   #5
xpi0t0s's Avatar
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
Mentor
14Feb2011,01:16   #6
xpi0t0s's Avatar
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.