Summary: Qualifiers

I l @ ve RuBoard

Summary: Qualifiers

Keywords

Use the following keywords to qualify variables :

 const, volatile 

General Comments

A qualifier constrains a variable's ability to be modified. A const variable, after it's initialized , can't be altered . The compiler can't assume that a volatile variable hasn't been changed by some outside agency, such as a hardware update.

Properties

Note

The declaration

 const int joy = 101; 

establishes that the value of joy is fixed at 101 .

The declaration

 volatile unsigned int incoming; 

establishes that the value of incoming might change between one occurrence of incoming in a program and its next occurrence.

The declaration

 const int * ptr = &joy; 

establishes that the pointer ptr can't be used to alter the value of the variable joy . The pointer can, however, be made to point to another location. The declaration

 int * const ptr = &joy; 

establishes that the pointer ptr can't have its value changed; that is, it can point only to joy . However, it can be used to alter joy .

The prototype

 void simple (const char * s); 

establishes that after the formal argument s is initialized to whatever value is passed to simple() in a function call, sample() may not alter the value to which s points.


I l @ ve RuBoard


C++ Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 314
Authors: Stephen Prata

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net