Wednesday, February 16, 2011

Find Output .


#include<stdio.h>
int fun()
{
  static int num = 40;
  return num--;
}

int main()
{
  for(fun(); fun(); fun())
  {
    printf("%d ", fun());
  }
  getchar();
  return 0;
}

3 comments:

  1. Loop is execute as following:

    for(40;39;37)
    print --> 38
    for(37;36;34)
    print --> 35
    for(34;33;31)
    print --> 32

    ........

    for(4,3,1)
    print --> 2
    for(1,0,_) and when 0 comes in condition part it will be considered as true and loop will be terminated
    so final output is

    38 to 2 by decrement of 3

    ReplyDelete