if we declare a variable in C memory is allocated for that variable Or not .My assumption is if we declare variable memory is allocated for that variable but i studied in some sites today Memory is not allocated for variable when we declare. Can any Helping to me Clarifying this doubt.
-
What sites? And what did they say exactly? – StoryTeller - Unslander Monica Apr 18 '17 at 08:13
2 Answers
A variable declaration only tells the compiler that the variable exist, what type it has and its name.
A variable definition on the other hand actually causes the compiler to allocate space for the variable.
Often though, a variable declaration and definition happens at the same time, which is why there is often some confusion about the two, and why both are often called just "declaration".
As a footnote, the above is not really the full story, there's also things like tentative definitions which can be either a declaration or a definition. This is the usual for global variables without initialization.

- 400,186
- 35
- 402
- 621
A declaration never allocates memory for a variable, it is generally to let the compiler know about the "type" (requirements).
In contrast, a definition is where the actual memory is allocated.
That is why, the same variable can be declared multiple times (as long as they don't conflict with previous types) but cannot be defined more than once.

- 133,132
- 16
- 183
- 261