Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   What will be the output (http://www.go4expert.com/forums/output-t24950/)

unni krishnan.r 12Feb2011 12:19

What will be the output
What will be output of following code snippet

Int n=1;


Stringx 12Feb2011 12:57

Re: What will be the output

rpbear 12Feb2011 13:05

Re: What will be the output
is this your complete code?didn't the complier generate any error?

shabbir 12Feb2011 16:00

Re: What will be the output
Output would be few errors.

xpi0t0s 14Feb2011 01:14

Re: What will be the output
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.

xpi0t0s 14Feb2011 01:16

Re: What will be the output
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.

All times are GMT +5.5. The time now is 22:35.