1

I have a global array. The memory of this array will be allocated from data segment. I get confused what should I call this array. Is it array declaration or array definition? I think since the memory is allocated this should be array definition.

int array[4][5][2]; //  declaration or definition? 4*(4+5+2) bytes will be allocated
int main()
{
    return 0;
}

2 Answers 2

2

According to the C Standard (6.7 Declarations)

5 A declaration specifies the interpretation and attributes of a set of identifiers. A definition of an identifier is a declaration for that identifier that:

— for an object, causes storage to be reserved for that object;

As you noted yourself the memory for the array is reserved in data section then you have a declaration of an array that at the same time is a definition.

Sign up to request clarification or add additional context in comments.

Comments

0

In that case it's both: declaration + definition.

If you have in a separate file something like:

extern int array[4][5][2];

Then that's only declaring it, since definition occurs in other "external" file.

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.