# c++ expression must be a modifiable value

1 vote
69 views

## Problem:

I have a sample c++ code below that throws me back an error: “c++ expression must be a modifiable value” What could be the reason?

``````int A = 3;
int B = 5;
int match = 3;
for ( int k =0; k < B; k ++ )
{
match --;
if ( match == 0 && k = A )
{
std::cout << " equals" << std::endl;
}
}``````

Thanks for your help.

1 vote

## Solution:

You need to remember, the assignment operator has lower precedence than `&&`, so your condition is comparable as:

``if ((match == 0 && k) = a)``

But the left-hand side of this is an rvalue, namely the boolean resulting from the evaluation of the sub­expression `match == 0 && k`, so you cannot assign to it.

On the contrary, the comparison has higher precedence, so `match == 0 && k == a` is comparable to:

``if ((match == 0) && (k == a))``

I hope you get the point now.

## Related questions

0 votes
1 answer 23 views
23 views
Problem: I have this following code: int M = 3; int C = 5; int match = 3; for ( int k =0; k < C; k ++ ) { match --; if ( match == 0 && k = M ) { std::cout << " equals" << std::endl; } } But it gives out an error saying: Error: expression must be a ... trying to modify "match" or "k" value here, but why this error? if I only write it like: if ( match == 0 ) it is ok. Could someone explain it to me?
0 votes
1 answer 6 views
0 votes
1 answer 51 views
51 views
Problem: c++ expression must be a modifiable lvalue Could someone explain it to me?
0 votes
1 answer 4 views
4 views
Problem: loop through a vector c++
0 votes
1 answer 211 views
211 views
Problem : Looking for solution of following doubt if one for loop is nested within another, then the counter variables for the two loops should be
1 vote
2 answers 484 views
484 views
Problem: Hello all, How to declare an array properly in c/c++? I am a new student of c++ and I am trying to declare two-dimensional arrays in my program. Unfortunately, my arrays are not working. Here is my sample code int row = 5; int col= 5; int [row][col]; The above codes throw an error expression must have a constant value c++. What&rsquo;s wrong with it?
0 votes
1 answer 51 views
51 views
Problem: My programming teacher gave us an assignment in which we have to tell which of the three loops in C++ does not have an entry condition? As far as my guess is concerned, the 'for' loop does not need an entry condition. I want you to guide me if I am wrong and tell me the correct answer to this question. Thanks!
0 votes
1 answer 8 views
8 views
Problem: Attention reader! Det hold of all the important Java and Collections concepts with theat a student-friendly price and become industry ready.Please write relevant answer if you find anything correct, or you want to share more information about the topic discussed above.
0 votes
1 answer 506 views
506 views
Problem: I am working with loops. My query is that can I increment a foor loop by 2? If yes, then how? Please explain in detail and with syntax and examples because I am a newbie and have no experience in programming. Thanks
0 votes
1 answer 6 views
6 views
Problem: Can anyone help me about this? If anyone know about loop to print each contact and contact email. Then please read my question carefully and answer me.