I have two programs:
First program:
#include<stdio.h>
int main()
{
static const int a = 10;
int * b;
b = &a;
*b = 200;
printf("%d", a);
return 0;
}
Second program:
#include<stdio.h>
int main()
{
const int a = 10;
int * b;
b = &a;
*b = 200;
printf("%d", a);
return 0;
}
The first program has a runtime error: "Bus error: 10" but the second one works prefectly. Could you tell me what is the difference between const and static const in these two programs!
question from:https://stackoverflow.com/questions/65867877/change-the-values-of-const-variable-and-static-const-variable-in-c-language