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