top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What are the storage qualifiers in C++?

+1 vote
351 views
What are the storage qualifiers in C++?
posted Jan 27, 2015 by Anwar

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

They are const ,volatile,mutable,
Const keyword indicates that memory once initialized, should not be altered by a program. volatile keyword indicates that the value in the memory location can be altered even though nothing in the program code modifies the contents. for example if you have a pointer to hardware location that contains the time, where hardware changes the value of this pointer variable and not the program. The intent of this keyword to improve the optimization ability of the compiler. mutable keyword indicates that particular member of a structure or class can be altered even if a particular structure variable, class, or class member function is constant.

struct data 
{ 
char name[80]; 
mutable double salary; 
} 
const data MyStruct = { "Satish Shetty", 1000 }; //initlized by complier 
strcpy ( MyStruct.name, "Shilpa Shetty"); // compiler error 
MyStruct.salaray = 2000 ; // complier is happy allowed
answer Jan 29, 2015 by Mohammed Hussain
...