Saturday, 3 November 2012

What is the difference between declaration and initialization of Variable?

The difference between declaration and initialization is very minor but this keeps lot much meaning.In some languages and in some terms the both words use as same meaning.

Declaration:

Declaration mean giving a memory block to a specific meaning. Declaration is used when we get value from user on run time. Such as

num=raw_input('Enter a number:')

In this example program is declaring a variable num and taking value at run time using raw_input.

Initialization:

Initialization gives us concept of declaring and assigning a value to a variable at same time. Which means you are sure about the value of variable from beginning of the program and that value will remain same till to end. Such as

num= 10

In this example this program will declare a variable with the name of num and at the spot assign a value to it, this is called initialization.

No comments:

Post a Comment