//  (C) Porkolab 2003
//
//  A.5.1.
//   
//  Storage classes in C++


// Const Data  
// value known at compile-time
const char *hello = "Hello world";

char *s = const_cast<char *>(hello);
s[3] = 'x';         // could be runtime error !



// Stack
// automatic life

void f()
{
    int i = 2;  // life starts here with initialization 
    ....
}               // life finished here



//  Free store
//  dynamic life

char *p = new char[1024];   // life starts here
...
delete [] p;                // life finished here



//  Heap  =?= Free store
//  dynamic life

char *p = malloc(1024);
...
free(p);



//  Global/Static
//  static life

date d(2003,3,13);  // life of "d", "i" starts here
static int i;

int main()
{                       // initialization/constr call happens here
    ...
    static int j = 6;   // initialization happens here
}                       // destr call happens here