storage class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yogeshchindejain
    New Member
    • Apr 2007
    • 1

    storage class

    hi ,


    What is the region that , local variables store garbage value and global variables store 0 value
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Originally posted by yogeshchindejai n
    What is the region that , local variables store garbage value and global variables store 0 value
    I assume you mean "What is the reason that ..."?

    In a word Speed.

    Global variables are initialised once at startup and the performance hit of iniitialising them is quite low.

    Local variables used shared memory from the stack so would need to be initialised every time the function was called, this would cause quite a performance hit and given that in many cases the program would then change the value to something else before using it it just isn't worth doing.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      I do confess that in the old days when the world was just VAXen I did things
      similar to this:
      Code:
      void foo() {
         char* p= "gotcha!";
      }
      void bar() {
         char* q;
         puts(q);
      }
      int main() {
         foo();
         bar();
         return 0;
      }
      I don't do that anymore, I grew older too ... ;-)

      kind regards,

      Jos

      Comment

      • rahulgupta4u
        New Member
        • Dec 2014
        • 3

        #4
        I have found a good resource on google https://www.tutorialcup.com/cplusplu...ge-classes.htm

        Comment

        Working...