我正试图将数组的每个值乘以一个整数,但当前遇到以下错误:“表达式必须是可修改的左值”。这段代码的目的是,当按下一个按钮时,矩形将被放大2个标量因子。如何解决此错误?

void Draw_Rectangle(unsigned int *rectangle1)
{
    // Call draw rectangle function to draw rectangle 1
    GraphicsFunction_drawRectangle (*rectangle1, *(rectangle1 + 1));

}

int main (void)
{
    unsigned int rectangleOne[4] = {85, 5, 130, 20};
    // Call function to draw the rectangle in initial position
    Draw_Rectangle(&rectangleOne[0]);

   while(1) {

       if(*(SWITCH_ptr) == 512) {
        int i = 0;
        for(i = 0; i < 4; i++){
            &rectangleOne[i] = rectangleOne[i] * 1.5;
        }
        Draw_Rectangle(&rectangleOne[0]);
    }
   }
}

最佳答案

&rectangleOne[i] = rectangleOne[i] * 1.5;=>rectangleOne[i] = rectangleOne[i] * 1.5;
it is enough also to Draw_Rectangle(rectangleOne);数组由指针传递时

关于c - 错误:表达式必须是可修改的l值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55581891/

10-11 15:39