When you have an assignment operator in a statement, the LHS of the operator must be something the language calls an lvalue. If the LHS of the operator does not evaluate to an lvalue, the value from the RHS cannot be assigned to the LHS.
You cannot use:
10 = 20;
since 10
does not evaluate to an lvalue.
You can use:
int i; i = 20;
since i
does evaluate to an lvalue.
You cannot use:
int i; i + 1 = 20;
since i + 1
does not evaluate to an lvalue.
In your case, p + 1
does not evaluate to an lavalue. Hence, you cannot use
p + 1 = p;
Related Posts:
- Are the C++ & and * operators inverses in all contexts?
- how does the ampersand(&) sign work in c++?
- What’s the difference between char and char* in C++?
- When should I use the new keyword in C++?
- What does ‘return *this’ mean in C++?
- Meaning of *& and **& in C++
- What are the differences between a pointer variable and a reference variable in C++?
- Arrow operator (->) usage in C
- Return array in a function
- What does “dereferencing” a pointer mean?
- Regular cast vs. static_cast vs. dynamic_cast
- What is a smart pointer and when should I use one?
- What does “dereferencing” a pointer mean?
- What is a char*?
- What exactly is nullptr?
- How to fix a “invalid operands to binary expression” error?
- What is a dangling pointer?
- What does `*&` in a function declaration mean?
- (->) arrow operator and (.) dot operator , class pointer
- What is uintptr_t data type
- What is the difference between const int*, const int * const, and int const *?
- C++ – No matching member function for call to ‘push_back’
- What is uintptr_t data type
- What does int & mean
- What is the difference between const int*, const int * const, and int const *?
- Pointer to incomplete class type is not allowed
- Passing by reference in C
- Why does the arrow (->) operator in C exist?
- Passing a 2D array to a C++ function
- Can’t resolve Error: indirection requires pointer operand (‘int’ invalid)
- How to create a dynamically-allocated array of const objects, but have values assigned to them?
- How to access the contents of a vector from a pointer to the vector in C++?
- How to make an array with a dynamic size? General usage of dynamic arrays (maybe pointers too)?
- expression must have integral type
- What does int & mean
- C++: Expression must have a constant value when declaring array inside function
- Sorting Linked List C++ with pointers
- Delete 2D array C++
- Is the sizeof(some pointer) always equal to four?
- C++ Expression must have pointer-to-object type
- C++ strings and pointers
- initial value of reference to non-const must be an lvalue
- Typedef function pointer?
- How to initialize a vector of pointers
- How to printf a memory address in C
- What is the use of intptr_t?
- C++ – Assigning null to a std::string
- How to convert const char* to char* in C?
- error: invalid initialization of non-const reference of type ‘int&’ from an rvalue of type ‘int’
- Using C-string gives Warning: “Address of stack memory associated with local variable returned”
- Reference to non-static member function must be called
- Why use pointers?
- What’s the difference between * and & in C?
- Invalid type argument of -> C structs
- What does ** mean in C?
- C++ pass an array by reference
- Get size of pointer in C
- C: pointer to array of pointers to structures (allocation/deallocation issues)
- Function stoi not declared
- Casting a pointer to an int
- C++ Array of pointers: delete or delete []?
- Why should I use a pointer rather than the object itself?
- Function stoi not declared
- C++ correct way to return pointer to array from function
- Warning: comparison of distinct pointer types
- Initializing pointers in C++
- Difference between function arguments declared with & and * in C++
- Is C++ Array passed by reference or by pointer?
- Difference between the int * i and int** i
- set head to NULL (‘NULL’ : undeclared identifier)
- What is a `char*`?
- clearing a vector of pointers [duplicate]
- C – Error is “free(): invalid next size (normal) “
- C++ Swapping Pointers
- Initialization makes pointer from integer without a cast – C
- Array of Linked Lists C++
- Differences between unique_ptr and shared_ptr
- C++ Error: “Expression must have integral or enum type” [duplicate]
- c++ compile error: ISO C++ forbids comparison between pointer and integer
- How do I declare a 2d array in C++ using new?
- What does “#include
” do? - Compiling C++11 with g++
- Setting an int to Infinity in C++
- dynamic_cast and static_cast in C++
- What exactly is std::atomic?
- Separating class code into a header and cpp file
- How to write C++ getters and setters
- std::out_of_range error?
- Understanding glm::lookAt()
- How to get current timestamp in milliseconds since 1970 just the way Java gets
- Cannot open output file, permission denied
- Strange error C2131: expression did not evaluate to a constant in VC 2015
- What is wrong with using goto?
- Double pointer array in c++
- error: ISO C++ forbids in-class initialization of non-const static member
- Function call missing argument list to create pointer
- cannot specify explicit initializer for arrays
- What does ** mean in C++?
- Incomplete type is not allowed: stringstream
- Evaluate a string with a switch in C++ [duplicate]