Tuesday, March 15, 2016

Question for your concept.

What is the output of following code:
void main()
{
  int i;
  for(i=0;i<5;++i)
  {
      printf("%d",i);
   }
}
a. 0,1,2,3,4       b. 1,2,3,4,5
c. 1,2,3,4          d. error



3 comments:

  1. b.1,2,3,4,5

    output:
    During execution,when i=0,in for loop ++i i.e. ++0=1.
    hence,first output value is 1.
    when i=4,4<5 is satisfied,++i=++4=5
    so last output is 5.

    ReplyDelete
  2. Raj Kachare
    Answer is b)1,2,3,4,5

    ReplyDelete