Showing posts with label pointers. Show all posts
Showing posts with label pointers. Show all posts

June 8, 2010

Tip of the Day #2 - pointers

Remember
int* ptr;
*ptr = 10;
#but
ptr = new int;
#without ampersand and dereference !!

June 7, 2010

Constant pointers, pointers to constants ?

What is the difference between:
float fVar = 3.14;
const float* ptr1 = &fVar;
and:
float fVar = 3.14;
float* const ptr2 = &fVar;
? The first one is pointer to constant value, so we can't change the value of variable the pointer points to :
*ptr1 = 10;
The second one in contrary is a constant pointer to a value, and because of that we can't readdress it to point at different variable :
float fVar2;
*ptr2 = &fVar2;
stat4u