What is the difference between defining and declaring a variable?

The basic types of variable in C are namely char, int, double and float. First the variables have to be declared. This is done as follows:

First any of the data type defined above must be mentioned and this is followed by the name of the variable. For instance if wants to declare a variable v1 of type char it is done as follows

char v1;

While declaring a variable what happens is the data type is described to the compiler and no space or memory allocation takes place. In other words just the data types are mentioned without any memory storage for the data types. While defining the variable the declaring the data type of the variable along with space allocation for the variable takes place.

Questions by GeekAdmin   answers by GeekAdmin

Showing Answers 1 - 3 of 3 Answers

Srinath

  • Jul 13th, 2007
 

When a variable is declared, a memory is allocated for that variable acoording to the type of variable..
And during a variable definition, a value is defined to that variable and the value gets stored in the corresponding memory location..

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions