Simple C array declaration / assignment question

后端 未结 9 1965
醉话见心
醉话见心 2021-01-05 06:13

In higher level languages I would be able something similar to this example in C and it would be fine. However, when I compile this C example it complains bitterly. How can

9条回答
  •  青春惊慌失措
    2021-01-05 06:53

    I would post this as a comment, but I don't have enough reputation. Another (perhaps dirty) way of initializing an array is to wrap it in a struct.

    #include 
    
    struct wrapper { int array[3]; };
    
    int main(){
        struct wrapper a;
        struct wrapper b = {{1, 2, 3}};
    
        a = b;
    
        printf("%i %i %i", a.array[0], a.array[1], a.array[2]);
    
        return 0;
    }
    

提交回复
热议问题