Reputation: 99428
A string literal is an lvalue.
An lvalue can be used:
as the operand of the address-of operator (except if the lvalue designates a bit field or was declared register).
as the operand of the pre/post increment and decrement operators.
as the left-hand operand of the member access (dot) operator.
as the left-hand operand of the assignment and compound assignment operators.
as ... (anything which a value can be used as but I miss to list)
I was wondering how a string literal can be used as operands of the above operators in a C program?
Thanks.
Upvotes: 0
Views: 75
Reputation: 141618
Your bullets 2 and 4 require a modifiable lvalue , which excludes arrays. String literals are arrays, so they are not modifiable lvalues.
The first one is OK, &"hello"
is allowed, although this would be an uncommon usage.
The third one, the left-hand side of .
must have struct type, which a string literal doesn't. However, note that the left-hand operand of .
does not actually need to be an lvalue.
Upvotes: 2