简体   繁体   中英

What's meaning of these volatile with pointers in C ?

volatile void * ptr;

Whether ptr is volatile or it points to the volatile location .

So the actual doubt is : Is the same thing applied to the above declaration as it applied with const qualifier ?

Little explanation will help me a lot.

It's a pointer to volatile data. If the pointer itself should be volatile but not the data it points at, you'd use:

void * volatile ptr;

So yes, it works the same way as the const modifier.

A Microsoft explanation :

The volatile keyword specifies that the value associated with the name that follows can be modified by actions other than those in the user application.

The volatile keyword is useful for declaring objects in shared memory that can be accessed by multiple processes.

Both const and volatile are type qualifiers (they're the only type qualifiers in C, in fact). The syntax for using them is identical.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM