0

When I initialize this array inside my struct. I get the error message - syntax error : '{'. Unexpected token(s) preceding '{'; skipping apparent function body.

int array[8][2] = {{3,6},{3,10},{3,14},{8,4}, {8,8},{8,12},{8,16},{12,2}};

I'm not sure what is wrong as I copied the syntax from my textbook.

Declaration is typedef struct _array *Array;

1
  • 1
    Please show you struct declaration because you can not initialize variables inside of struct. Commented May 8, 2012 at 1:39

1 Answer 1

4

You cannot initialize a variable inside a struct declaration, doesn't matter if an array or int. Yet, you can initialize the array in the struct initialization.

struct foo {
    int x;
    int array[8][2];
};

struct foo foovar = {1, {{3,6},{3,10},{3,14},{8,4}, {8,8},{8,12},{8,16},{12,2}}};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.