const array and variable

i can protect data from being changed in compile time like this.

 
const int x=234;


but if i have to protect the data in runtime what i should do.
¿? The program will do as the code says.
I don't understand what you want
take a look at this code.

1
2
3
4
5
6
7
8
9
#include<stdio.h>

int main()
{
        const int pi=3.14;
        scanf("%d",&x);   
        printf("%d",x);
        return 0;
}


so in runtime if i give any input the value of pi will be changed but i don't want that to happen.
i want to make pi unchangable fully protected in runtime or compile time.
If you don't want to write in that variable, then don't write in that variable.

You can expect at most a warning from the compiler.
By instance gcc yields: warning: writing into constant object (argument 2) [-Wformat]
thanks
Topic archived. No new replies allowed.