the site here says that: http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/index.jsp?topic=%2Fcom.ibm.vacpp6m.doc%2Flanguage%2Fref%2Fclrc05lvalue.htm
If an lvalue appears in a situation in which the compiler expects an rvalue,
the compiler converts the lvalue to an rvalue.
An lvalue e of a type T can be converted to an rvalue if T is not a function or
array type. The type of e after conversion will be T.
Exceptions to this is:
Situation before conversion Resulting behavior
1) T is an incomplete type compile-time error
2) e refers to an uninitialized object undefined behavior
3) e refers to an object not of type T undefined behavior
Ques.1:
Consider following program,
int main()
{
char p[100]={0}; // p is lvalue
const int c=34; // c non modifiable lvalue
&p; &c; // no error fine beacuse & expects l-value
p++; // error lvalue required
return 0;
}
My question is that why in expression (p++)
++(postfix)
expects l-values
and arrays are l-value
then why this error occurs?
gcc error: lvalue required as increment operand|
Ques.2:
Plzz explain the exception 3
with an example
?
Arrays are indeed lvalues, but they are not modifiable. The standard says: