const datatype

hi i want to know every thing about const & volatile i really need it every single information
Marking a variable const means that you can not change its assigned value.

Marking a variable volatile means that it may be changed by another thread or process so the compiler will always allocate it to addressable memory and never keep it in an internal register, nor optimise it away.
Hm, would that mean that a program would be generally slower and unsafer when volatile is used (although it CAN be good for multi-threaded applications)?
Last edited on
It would generally be the tiniest bit slower, yes.

But it wouldn't be any less safe.
yes but what about this syntax
const void *x;
and thank you
const void* x;

This creates a pointer named 'x'.

- it's a void pointer... meaning it can point to anything. There's no way to know what it points to. void pointers are type unsafe. They also need to be cast to some other pointer type before they can be dereferenced.

- it's a const pointer, therefore whatever data it points to cannot be modified via this 'x' pointer.
ye i nearly get it thanks
Topic archived. No new replies allowed.