What will be the output

unni krishnan.r's Avatar, Join Date: Apr 2010
Skilled contributor
Guys
What will be output of following code snippet
Code:
Int n=1;
while(n>0)
{
l++
}
0
Stringx's Avatar, Join Date: Feb 2011
Newbie Member
'Int'?
rami hassan like this
0
rpbear's Avatar, Join Date: Feb 2011
Light Poster
is this your complete code?didn't the complier generate any error?
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Output would be few errors.
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
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 like this
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
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.