Saturday, September 3, 2011

Dynamic Memory

- catch bad_alloc exception

- check the returned address, ie, if it's 0

Friday, September 2, 2011

Array and Pointer

- an array can be considered as a constant pointer; eg,

int *p;
int a[5];

we could do p = a, but not a = p;

another example,

int a[5];
int *p;

p=a; *p=10;
p++; *p=20;
p=&a[2]; *p=30;
p=a+3; *p=40;
p=a; *(p+4)=50;

- void pointer

- null pointer

- pointers to function: usually being used as a parameter

static in C++

- use static inside a function (or a loop)

- use static in a class (static member, and static member function)

- use static as a global variable inside a file