Thursday, January 12, 2012

C Definition vs C Declaration

What is the diffference between declaration and definition in relation to memory.

Objects in C must have only one definition but can have multiple external declarations

A Definition is the special kind of declaration that creates[specifies the type of an object; reserves storage for it] an object;  
int my_array[100];


The Declaration of an external object tells the compiler the type and name of the object, and that
memory allocation is done somewhere else.. Since you aren't allocating memory for the array at this
point, you don't need to provide information on how big it is in total. You do have to provide the size
of all array dimensions except the leftmost one—this gives the compiler enough information to
generate indexing code.

extern int my_array[]; 

No comments:

Post a Comment