Home > Back-end >  Linux under the c const usage problem.
Linux under the c const usage problem.

Time:11-10

Such as a const int xyz [2]={1, 0}; Xyz [0] + + not sure, I want to ask is, if it is a memory of crossing the line, just threw on here? This places value will change? Will throw an error or value has been changed, and no tips?

CodePudding user response:

Modify, const just compiler class immutable, real memory read and write access is the related system

CodePudding user response:

Give you a piece of code, run once know

 int main () {
Const int a []={1, 2};
Int * p=(int *) a;
//a [0]=2;
* p=2;
Printf (" % d \ n ", a [0]).
return 0;
}

CodePudding user response:

Will modify, not to give tips, because is xyz array of const modifiers, cannot pass xyz array to modify, but on the other variables (pointer) can be modified, not restricted, const modifiers are not read-only memory,
  • Related