Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Intermediate
Nov 15, 2002

Pointer to a Constant vs. Constant Pointer


The const keyword in C++ provides a type-safe way to replace some of those #define preprocessor statements that you're used to writing from C. Whenever you have a value that you do not wish to have changed, you should declare it as const. For example:
 
const int i = 12; // any further attempt to alter i will cause an error.

However, when pointers are involved, what is actually constant depends on where you place the const keyword. Also, the syntax can be slightly confusing.
  • Pointer to a constant: A pointer to a constant is just that
Mike Cote
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date