Hi everyone.........

Discussion in 'C' started by capsicum, Sep 10, 2010.

  1. capsicum

    capsicum New Member

    Joined:
    Sep 10, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Consider this code:

    main()
    {
    void postinc();
    postinc();
    postinc();
    postinc();
    }
    void postinc()
    {
    static int count=1;
    printf("%d", count);
    count++;
    }

    What will be the output?
    Make me clear of this static concept.........
    What happens to the variable count?
    I know that it actually retains its value between funcion calls. But when it is called again and again when the control is passed to the function postinc will the stmt "static int count =1" change the previous value contained by count to 1? or will it still hold the value incremented previously. If it is so, what's the reason behind it?
    Please reply me soon..................
     
  2. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    19
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    http://www.techgeek.in
    The output would be 1,2 and 3.. The static variable can retain the value after several function calls...
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice