struct – initialization values

When you define a new struct(ure) and initialize it you can use the {} to define the internals of the values within for example

typedef struct
{
    int coding;
    int friends;
} newType;
 
newType nT = { 10, 20};

so coding = 10 and friends = 20

But if you try and over initialize the values that are not present, e.g.

newType nT = { 10, 20, 30 }; // there is not place to put the 30

then the compiler will compile with

error: too many initializers for 

Leave a Reply

Your email address will not be published. Required fields are marked *