Thursday, September 13, 2007

TECH QUES OF 13-9

main()
{
static int var = 5;
printf("%d ",var--);
if(var)
main();
}

4 comments:

  1. i think 5 will be continously printed and there will be no break

    ReplyDelete
  2. as the variable is declared as static then output will be
    1
    2
    3
    4
    5

    ReplyDelete
  3. Explanation:
    When static storage class is given, it is initialized once. The change
    in the value of a static variable is retained even between the function calls. Main
    is also treated like any other ordinary function, which can be called recursively.

    ReplyDelete