002 # puzzle on c

@dholey (1383)
India
January 20, 2007 12:53pm CST
/* WHAT WILL BE THE OUTPUT */ void main() { int i=1; for( ; i++ ; ) printf(" %d",i); }
6 responses
• India
22 Jan 07
Again a tricky program... and i have a different view from others here. It is not a infinite loop... (seems to be strange here.. but let me explain) first line: int i = 1; it means, it is actually 'signed int' which has a limit. quit condition: i++; so... printing will start from '2' and will go till 2^31 - 1 in positive direction... and then will switch in negative numbers with value '- 2^32' and after that it slowely tends to 'zero' after every increment.... In last it becomes 'zero' and will quit from the loop. Hope... explanation is clear... but any query is most welcome..
@dholey (1383)
• India
22 Jan 07
absolutely correct .... i mentioned it as a c program .. and i am using ansi standers so it will be 2^16-1 can you exactly tell the result
@dholey (1383)
• India
24 Jan 07
i am thankful to mylot that i came across with nice people like you, i cant express how much i admire you , your posts, your discussion, WE ALL ARE LOVER OF THE GREAT C LANGUAGE , so always be in the c club and pleas in daily routine start some discussion regarding c/c++...... thanks to yo too, to be my friend ....
• India
23 Jan 07
Hi Dholey, Actually either it is C or C++, a size of 'int' depends on either compiler is targeting the EXE for 16-bit operating system or 32-bit operating system. For example, if u run the same program on TurboC or TurboC++ or any compiler which is DOS base then the output will be... 2 3 4 .... 2^15 -1 ... (- 2^15) (- 2^15 + 1) .... -3 -2 -1 0 but if the compiler is targeted for 32 or 64 bit operating system like VC6 or VC7 then... output would be... 2 3 4 .... 2^31 -1 ... (- 2^31) (- 2^31 + 1) .... -3 -2 -1 0 i hope... .this time i m geting ur best response :) isn't it?
2 people like this
• India
24 Jan 07
hey dude i learnt it long back but still i try it the output would be only 2
@dholey (1383)
• India
29 Jan 07
no .. the correct answer has selected as best response , you check it ....
• India
21 Jan 07
Since no argument is given for the test condition in the for loop, this will lead to an indefinite loop of integers from 0-9 of different order. Is that correct?
@dholey (1383)
• India
22 Jan 07
no its not correct ....
• India
22 Jan 07
Well I think it's an infinite loop starting with 2 and so on.
• India
22 Jan 07
Here the output will be an unended loop printing 1 2 3 4 as here you have not told where to end the loop. Am i right?? please tell me.
@dholey (1383)
• India
22 Jan 07
wrong its not an infinite loop
@hobohobo (678)
• Indonesia
22 Jan 07
i think's it will became 1,2,3,.... because it's dont have argument limit, so it will be an infinitive loop, am i right ?
@dholey (1383)
• India
24 Jan 07
nop, if only variable name is mentioned in conditional area then you can assume it as variable != 0 OK now try again ,