What's the easiest way to create an array of structs?

前端 未结 5 1860
执念已碎
执念已碎 2021-01-30 18:06

What\'s the easiest way to create an array of structs in Cocoa?

5条回答
  •  独厮守ぢ
    2021-01-30 18:55

    Or dynamically allocating:

    struct foo {
        int bar;
    };
    
    int main (int argc, const char * argv[]) {
        struct foo *foobar = malloc(sizeof(struct foo) * 3);
        foobar[0].bar = 7; // or foobar->bar = 7;
    
        free(foobar);
    }
    

提交回复
热议问题