Thursday, August 7, 2014

Initializing a Constant Pointer

A little off-road but still something was whispering in my head, "can you initialize constant pointer pointing to constant pointer pointing to constant pointer pointing to an integer constant?". Well why not.
Trick was just to send initialized pointers into initializer of previous pointers.
Normally you don't need this scenario. Though creating constant pointers and putting a lot `const` specifiers in a pointer declaration makes the pointer `safe` to be manipulated.

What if you need to initialize an array if you've the same pointer declared. It can be way more tacky and might result into `impossible`.
You can simply declare a pointer and pass it to the function where the parameter is accomplishing all that safety you require from some critical section you want your pointer to stay safe in.
For example,

No comments :

Post a Comment