| | | | | |

Scope of Dynamic Variables

  • Static variables - usual rules apply
  • Dynamic variables have global scope
  • int* nptr;         // compile time binding
                       // static memory allocation of type int*
    nptr = new int;    // run time binding
                       // dynamic memory allocation of type int
    ...
    delete nptr;       // run time unbinding
    
  • Usual scope rules apply to nptr
  • Variable allocated at *nptr has global scope
  • This variable remains in scope even after nptr goes out of scope

| | Top of Page | 5. C/C++ Pointers, Arrays, and Pointer Arithmetic - 14 of 17