Text books say that & (addressof) operator doesn't apply to cannot be applied to expressions,
constants, or register variables.
Does constants mean only literals like 'A', '7' etc or variables declared with const keyword as well?
I think this mean only literals since following code compiles:-
int main()
{
const int i=10;
const int *ip;
ip = &i;
}
Unary operator &
in C can be applied to any lvalue. A const-qualified object is an lvalue, which means that unary &
can be applied to it.
The term "constant" in C indeed means only literal constants, like 2
, for example. A const-qualified object is not a "constant" in C terminology.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With