yellowcorn
yellowcorn

Reputation: 19

C Structure initialization (Array of integers and an integer value)

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

how should I initialize the elements in the structure?

Upvotes: 0

Views: 390

Answers (1)

Vlad from Moscow
Vlad from Moscow

Reputation: 311058

For example

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

Or

struct setArray s;

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

Or

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

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

Upvotes: 2

Related Questions