Tuesday, October 5, 2010

Constant and pointers

Recently, I reviewed some basic C++ knowledge. one is qualifier CONSTANT, and another one is POINTER.

CONSTANT is a useful qualifier in team project because it will reduce the mistakes when using another’s methods, but I seldom used it in my project. I should use CONSTANT more often because it makes reuse them easier.

Using “constant” and “pointer” together make it more complicated.

1.Constant variable
2.A pointer points to a constant varaible
3.A constant pointer points to variable.
4.A constant pointer points to a contant variable

Confused? Follow is an example:

const double pi = 3.14159;
const double *const pi_ptr = π

In this case, pi_ptr is a const pointer and points to a const object.

No comments:

Post a Comment