c - st ="hello";在 c 编译器中它显示错误 require Lvalue 这是什么意思为什么这个错误似乎会出现

标签 c

<分区>

代码

#include<stdio.h>
int main()
{
    char st[10],*sr[10];
    st="hiiii";
    sr="gdfsdfsd";
    printf("%s  %s",st,sr);

    return 0;
}

此程序将错误显示为需要左值。

有没有人可以详细解释或分享我可以了解更多信息的链接提前谢谢?

最佳答案

来自 What are rvalues, lvalues, xvalues, glvalues, and prvalues? :

An lvalue (so-called, historically, because lvalues could appear on the left-hand side of an assignment expression) designates a function or an object.

您正在尝试将某些内容分配给数组(声明为 type x[dimension];)。

C 语言不允许这样做。因此,数组不能是左值,这解释了编译器错误消息。

关于c - st ="hello";在 c 编译器中它显示错误 require Lvalue 这是什么意思为什么这个错误似乎会出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46624693/

相关文章:

c - 如何在Digi Module Connect me 9210中实现Modbus RTU Master

c - 关于数组搜索

c - 将指向数组的指针作为参数传递给函数

c - X11 X图像处理

c - 构建 OpenWrt 包的链接器错误

C:将元素从一个列表移动到另一个列表

C 在函数中传递二维数组给我段错误

c - 将指针传递给函数不是在 C 中通过引用传递吗?

c - 文件可以打开但无法读取 QNX

c - 错误 : unknown type name ‘GtkObject’