&运算符不能应用于C中的常量

Aqu*_*irl 5 c pointers constants

根据Kernighan和Ritchie的C编程语言,第94页

&运算符不能应用于常量

const int u = 9;
printf ("\nHello World! %u ", &u);
Run Code Online (Sandbox Code Playgroud)

那么,为什么这样呢?

msc*_*msc 6

constant和之间的误解const.两者在C语言中都是不同的东西.

&运算符不能应用于常量

在C编程中,它意味着你不能使用&(address operator)文字常量来获取文字常量的地址.

举些例子 :

&10 
Run Code Online (Sandbox Code Playgroud)

要么

&('a')
Run Code Online (Sandbox Code Playgroud)

如果使用&operator而不是文字常量,编译器将给出错误,因为常量实体没有相应的地址.