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

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Beginner
Nov 6, 2007

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


An Easy Way to Remember Constant Pointer Declarations

Consider the following declarations:

int * const bla;
int const * bla; 
const int * const bla;
As you can see, it can sometimes be hard to remember whether it's the pointer that is declared constant or whether the pointer points to a constant variable or both.

The trick to deciphering these is to read the declaration backwards from right to left. For instance:

  • int * const bla; reads as: bla is constant and points to an int.
  • Specifically, bla is a constant pointer that can't be changed and always points to the same int.

  • int const * bla; reads as: bla points to a const int. Specifically, bla can be changed but only points to integers that are const.
  • int const * const bla; reads as: bla is constant and points to a constant int. Specifically, bla is a constant pointer that can only point to a const int and neither can be changed.
Just remember: read backwards from right to left.

Jacob Lund Fisker
 
Comment and Contribute

 

 

 

 

 


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

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date