A constant pointer is a pointer that cannot change the address which it stores. Syntax: datatype *const pointer_name; Example: int a=10,b=20; int *const ptr; ptr=&a; ptr=&b; //here the address in ptr cannot be changed so not allowed . Pointer to constant Address in the pointer can be changed but the value of the data element which the pointer points cannot be changed. Syntax: const datatype * pointer_name; Example: int a=10,b=20; const int *ptr=&a; *ptr=100; //here the value which ptr points to cannot changed so not allowed ptr=&b; //allowed Pointers and Const The previous two can be combined to form a constant pointer to constant Syntax: const datatype *const pointer_name; Example: const int * const ptr; int a=10,b=20; const int * const ptr=&a; *ptr=100; //not allowed ptr=&b;//not allowed Here the value which ptr points to cannot be changed an...
Engage with tech Interactives in fun way, Learn while having fun

Comments
Post a Comment
Please give us feedback through comments