Tuesday, July 14, 2009

Doubt in c program?

volatile constant. this a a datatype right?? eg. const int n=1 means the value of n is going to b constant for the whole program. ant volatile just opposite.but can these exist like i mentioned above???


help if yes means how??

Doubt in c program?
first of all volatile is a C++ key word and its not for what u said..





see Wikipedia:


http://en.wikipedia.org/wiki/Volatile_va...
Reply:Welcome the famous old question. volatile and const are not mutually exclusive to each other. That is to say, these keywords can be used together to qualify a type. Both fall under the 'type qualifier' category of keywords.





const %26lt;type%26gt; var; means var is read only type for the user. the user(in this case, programmer) may not edit a const type.





volatile %26lt;type var; means that everytime something non-trivial needs to be done with the var's value, it has to be read in at that point. Its value may change in unpredictable ways thanks to 'interrupts'(%26lt;--note: this is the keyword here).





volatile const %26lt;type%26gt; var; means, var's value can change in unpredictable ways thanks to 'interrupts' but the user(programmer, in this case) may not change it by hand.





wondering where this kind of thing would be used? look at some (Linux)OS or device drivers code. they use this kind of declarations in many places.
Reply:Yes.the volatile constant may exist given that there is a separate declaration of the number else where in the program.The local scope is of most priority,more than the public and the private scope.So when decl as a constant in public or private and when in the local it is re-declared.,these r caled volatile constant


To declare a costant:


const var_name = var_value;


to decl volatile const


data_type const var_name= var_value;

survey software

No comments:

Post a Comment