C++ expression is not assignable when writing `&str_send[0] = &str_recv[c * 6];` Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of C++ expression is not assignable when writing `&str_send[0] = &str_recv[c * 6];` without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I’m trying to parse an array that receives a multiple of 8 bytes and sends back each array of 8 bytes one at a time.

I’m getting an expression is not assignable or lvalue required as left operand of assignment error when building

I’m trying to figure out why I cannot simply change the address of an array to the new position. At first I thought it was a C-style array issue, but the same error happened when I tried with std::vector<unsigned char>

Is there a preferable way of doing this without copying the bytes?


unsigned char str_send[8];
unsigned char str_recv[BUF_SIZE];

int n = receive(cport_nr, str_recv, (int)BUF_SIZE);

if (n > 0 && ( n % 8 == 0 ) )
    for (int c = 0; c < n / 8; c++) //Break up multiple 8-byte chunks
        &str_send[0] = &str_recv[c * 6]; //ERROR expression is not assignable
return (0);


You can’t change the address of a variable.

What you could do is create an array of pointers to the original array, but then you’re just copying addresses (probably 8 bytes each) instead of single byte values. Then you’ve have to dereference those pointers, which makes it non-trivial to send what they point to.

Copying the bytes is exactly what you want to do here. Then you have a buffer you can send as-is:

str_send[0] = str_recv[c * 6];
We are here to answer your question about C++ expression is not assignable when writing `&str_send[0] = &str_recv[c * 6];` - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji