lvalue required as left operand of assignment error when using C++

前端 未结 5 653
耶瑟儿~
耶瑟儿~ 2020-12-28 23:59
int main()
{

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


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-29 00:51

    To assign, you should use p=p+1; instead of p+1=p;

    int main()
    {
    
       int x[3]={4,5,6};
       int *p=x;
       p=p+1; /*You just needed to switch the terms around*/
       cout<

提交回复
热议问题