Discussion in 'C' started by unni krishnan.r, Feb 12, 2011.
What will be output of following code snippet
is this your complete code?didn't the complier generate any error?
Output would be few errors.
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.
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.
Separate names with a comma.