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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM