c++中数组之间的赋值问题

c++ pp page61

c++ pp page76

不能将一个数组直接赋值给另一个数组,如

int cards[4] = {3,4,5,6};
int hands[4];
hands = cards; //not allowed

但是,可以使用赋值运算符(=)将结构体赋值给另一个同类型的结构体,即使成员是数组,如:

复制代码
struct inflatable
{
    char name[20];
    float volumn;
    double price;         
};
int main()
{
    inflatable bouquet =
    {
        "sunflowers",
        0.20,
        12.49
    };
    inflatable choice;
    choice = bouquet; //allowed, even though there is an array in struct
}    
复制代码

一篇解释如下:

https://www.zhihu.com/question/377249567

posted @   SanFranciscoo  阅读(1414)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示