pointers - lvalue required as left operand of assignment error when using C -


int main() {     int x[3]={4,5,6};    int *p=x;    p +1=p;/*compiler shows error saying              lvalue required left               operand of assignment*/    cout<<p 1;    getch(); } 

when have assignment operator in statement, lhs of operator must language calls lvalue. if lhs of operator not evaluate lvalue, value rhs cannot assigned lhs.

you cannot use:

10 = 20; 

since 10 not evaluate lvalue.

you can use:

int i; = 20; 

since i evaluate lvalue.

you cannot use:

int i; + 1 = 20; 

since i + 1 not evaluate lvalue.

in case, p + 1 not evaluate lavalue. hence, cannot use

p + 1 = p; 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -