Initialization and Declaration in Programming languages.

INITIALIZATION AND DECLARATION OF VARIABLES IN PROGRAMMING.

As we know in programming, we can’t do without creating variables.

Variables are containers that are used for storing values which could change at any time.

Let’s define the two keywords we are discussing today according to the Dictionary to get the lame man definition before we get the in-depth definition as Programmers.

According to the Oxford Learner’s Dictionary:

DECLARATION: an official or formal statement, especially about the plans of a government or an organization.

INITIALIZATION: the act of making a computer program or system ready for use.

Let’s now talk about these two distinct concepts in terms of programming and as programmers.

Declaration in programming simply involves stating the data type and name of a variable without assigning a value to it.

In languages like C++, At the point of declaration of a variable, a memory location is assigned to the variable and the variable might have garbage values when it has not been assigned a value(Initialization).

This simply means when you declare a variable and it has not been assigned a value, the compiler would automatically generate a garbage value for it. Variables can only be used once it has been declared.

INITIALIZATION: Initialization is the process of assigning value to a variable. It involves assigning a value to a variable as it is declared(static) or later in the program probably by the user(dynamic).

When you assign a value to a variable, it is known as INITIALIZATION.

It should be noted that our discussion on initialization and declaration is for statically/strongly typed languages like C++, Java, and C but this concept varies for dynamically typed languages like Python and JavaScript.

In dynamically typed languages, Declaration is not needed i.e. We don’t need to state the data type of the variable, all we need to do is assign a name and a value and the compiler automatically knows what data type it fits into, this is known as Implicit declaration as opposed to explicit declaration in statically typed languages where we state explicitly the data type of the variable we are declaring.

All we need to do is initialize a value to the variable name.

Let’s give an example of python:

As opposed to saying int x=5, we just say x=5 and allow the compiler to store the value as the data type internally.

SUMMARILY,

The declaration consists of data type, a variable name without value while initialization is assigning a value to the variable