C结构åˆå§‹åŒ–(整数数组和整数值)

时间:2014-08-17 22:41:47

标签: c arrays initialization structure

#define MAX 10
struct setArray
{
    int item[MAX];
    int count;
};
typedef struct setArray *BitSet;

我应该如何åˆå§‹åŒ–结构中的元素?

1 个答案:

答案 0 :(得分:2)

例如

struct setArray s = { { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, MAX };

或

struct setArray s;

for ( int i = 0; i < MAX; i++ ) s.item[i] = i;
s.count = MAX;

或者

BitSet p = malloc( sizeof( *p ) );

for ( int i = 0; i < MAX; i++ ) p->item[i] = i;
p->count = MAX;