what is the difference between declaring a static variable inside and outside of main

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ankur0921
    New Member
    • Apr 2012
    • 1

    what is the difference between declaring a static variable inside and outside of main

    I want to know

    prog1.c
    #include<stdio. c>
    static int c=6;
    int main()
    {
    /*code*/
    }


    prog2.c
    #include<stdio. h>
    int main()
    {
    static int c=10;
    }


    what would be the difference between these two program in the fuctioning of static keyword ?

    thx.

    ankur
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    The static variable inside main() will ve in scope from the point of definition to the end of the function.

    Outside of main() the variable will be in scope from the point of definition to the end of the file.

    Comment

    Working...