当前位置:网站首页>Fundamentals of C language -- 2-2 const keywords and pointers

Fundamentals of C language -- 2-2 const keywords and pointers

2022-07-19 09:21:00 Bazinga bingo

const keyword , stay C It's used to modify variables in languages , Indicates that the variable is a constant .

const Used to decorate pointers , Yes 4 Ways of planting :
The first one is ,const int *p
p Not in itself const,p The variable that points to is const

The second kind ,int const *p
p Not in itself const,p The variable that points to is const

The third kind of ,int * const p
p Itself is const,p The variable pointed to is not const

A fourth ,const int * const p
p Itself is const,p The variable that you point to is also const

const The modified variable is in GCC In the environment , Variables can be changed . because const yes gcc Used to check to ensure implementation (const A variable of type cannot be changed. It is a compilation error , Not a running error . As long as you cheat the compiler, you can change , No error will be reported during operation ).GGC In distribution const Modify the variable memory space , Put it in the same modifiable space as ordinary variables .

const Mainly used to tell the compiler , This is const Modified variables do not have to be changed . It is more like passing information into the function in the future , Tell compilers and programmers that there is no need to change the value of variables .

原网站

版权声明
本文为[Bazinga bingo]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/200/202207170955490652.html