Thursday, October 7, 2010

can you answer in the following program how long will the for loop get exxecuted?

#include<stdio.h>
int main()
{
int i;
for(;scanf("%d",&i);printf("%d\n",i));
return 0;
}

4 comments:

  1. guys pls try........dis was a ques. asked in written test of tcs....for placement..

    ReplyDelete
  2. ITS ANSWER IS.....THE FOR LOOP WOULD GET EXECUTED INFINITE TIMES........BCOZ RETURN VALUE OF THE FUNCTION SCANF() WOULD ACT AS RESULT OF THE CONDITION.THIS VALUE WILL ALWAYS B NON-ZERO,HENCE TRUE..................PLS SHARE YOUR VIEWS N COMMENTS UPON DIS POST.............

    ReplyDelete
  3. SUMIT BHAI PROGRAMM TRACE KARKE EXPLAIN KIJIYE...

    ReplyDelete
  4. when u'll give 10 as input,d scanf statement will b executed,and again it'll b printed.mean in both d cases statement are true.for loop executes untill and unless the main cond(middle one) is false.so,it'll execute infinite times.

    ReplyDelete