Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
What is the difference between the "Declaration" and "Definition" of variables in terms of different storage class?
Posted

1 solution

For explanation, look here:
http://en.wikipedia.org/wiki/External_variable[^].

For a sample, locate the section "Example (C programming language)"; file1 — definition; file2 — declaration. Usually declaration is used in *.h file, so there are many repetitions of the text of the same declaration in the same project, but the definition should be only one (otherwise the symbolic linker won't be able to resolve which one to use), so the definition is placed only once in some *.C file.

—SA
 
Share this answer
 
Comments
vishal_kapoor 28-Apr-11 2:29am    
extern variable is "declaration without definition". What about the other storage class variables like auto, register, static? Others are declaration and definition both at the same time?
Sergey Alexandrovich Kryukov 28-Apr-11 2:38am    
Everything else is unrelated to this dilemma, only extern. Learn them separately.
With functions -- declaration is a function without body.
--SA
Albin Abel 28-Apr-11 23:44pm    
My 5.
Sergey Alexandrovich Kryukov 28-Apr-11 23:57pm    
Thank you, Albin.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900