We are able to modify the value of constant integer pointer by b, how can we make sure/restrict accidentally modification of the value ?
#include <stdio.h>
/**
* Snippet to under working of "pointer to integer(any) constant"
*
* We are able to modify the value of constant integer pointer by b, how
* can we make sure/restrict accidentally modification of the value .
*
*/
void modify_value(const int *m, const int *n) {
//*m = 50; // expected error, assignment of read-only location
*((int*)n) = 100; // value of pointed by pointer gets updated !!
}
int main() {
int a=5,b=10;
printf("a : %d , b : %d \n", a,b);
modify_value(&a,&b);
printf("a : %d , b : %d \n", a,b);
return 0;
}