What is the difference between declaring a variable and defining a variable?

Declaring a variable means describing its type to the compiler but not allocating any space for it. Defining a variable means declaring it and also allocating space to hold the variable. You can also initialize a variable at the time it is defined.

Showing Answers 1 - 6 of 6 Answers

Deepak Bhandari

  • Mar 30th, 2007
 

When we declare a variable we give only the name and data type for that variable but when we define a variable we give the name, datatype for that variable and also give a particular value to that variable. For exemple in C language:
int num (this is declaration of variable)
int num=2 (this is defining of variable)

shiva

  • Apr 9th, 2007
 

Declaration announces only properties of varaibles and a definition also causes storage to that variable...

  Was this answer useful?  Yes

Prakash

  • Apr 29th, 2007
 

As per view int a = 2 is a declaring a variable. But it is called as dynamic intialization.
Can you expalin?

  Was this answer useful?  Yes

prabhu

  • May 5th, 2007
 

int num;

This statement is declaration and also defination since it also allocates memory for variable num.

But when you use following statement

extern int num;

It is only declaration since you are not allocating memory here.

As far as declaration of variable is concerned it only shows the properties of variable and we declare the data type which are to be used by that variable but when it comes to the definition of variable then we alocate a perticular space in the memory

int a(it's the declaration and definition of variables)
extern a(this is the actual definition of the variable)

  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.

Answer Question

Click here to Login / Register your free account


 
Send   Reset

 

Related Answered Questions

 

Related Open Questions