I'm trying to understand the difference between variable definition, variable declaration, function definition, and function declaration. For example, site A would say that:
int var=10; /* declare and initialize */
while site B would say:
int y=20; /* global variable definition and initialization */
One is called a declarative and the other is called a definition. Why? Which one is the right one? And does initializing the variables make it a declaration or definition? Same thing with functions. There seems to be different rules for both functions vs variables and it's confusing me big time.
Asked
Active
Viewed 24 times
0

notevention
- 13
- 1
-
A simple search result contains acceptable answers to your question: https://www.google.com/search?q=c+function+declarations+vs+definition – jwdonahue Sep 16 '20 at 17:55
-
3Does this answer your question? [What is the difference between a definition and a declaration?](https://stackoverflow.com/questions/1410563/what-is-the-difference-between-a-definition-and-a-declaration) – Sep 16 '20 at 17:55
-
Welcome to stack overflow. You should search for your problem before you ask. Otherwise your question will be flagged as duplicate. – Sep 16 '20 at 17:57
-
Just one final thing that needs to be answered I'm confused about. If I used an identifier like int x = 10, would that automatically make it declared or defined? – notevention Sep 16 '20 at 17:57
-
2An important point to understand, which is not always brought out, is that declarations and definitions are not disjoint. In fact, every object or function definition expressed in C source code is also a declaration of the object or function it defines. And particularly relevant to this question, every object declaration that initializes the declared object *is* a definition of that object. – John Bollinger Sep 16 '20 at 18:01
-
and there is the tentative definition which is only a declaration if followef by an explicit definition... – Antti Haapala -- Слава Україні Sep 16 '20 at 21:24