In this tutorial, we will learn about C variable initialization with some examples. We can initialize a C variable at the same time when we declare it. We can declare and initialize a variable using a single programming statement in C.
Storing the first valve in the variable(i.e into the memory location) is called variable initialization. The first value is called the initializer. Note that the variable can change its value during the course of the program.
The general syntax to initialize a variable is as follows:
<data_type> <variable_name> = <value> ;
The = symbol is the assignment operator.
int number = 20;
In this example, we have declared an integer variable number and initialized the variable with the value 20.
Let’s look at another example. In this example, we have declared a double precision floating point number variable interestRate and initialized the variable with the value 0.15
double interestRate = 0.15;
When a variable is defined, it usually contains the default value or it
may contain a garbage value. It is important to initialize the variable and store data before accessing the variable value. This is a safe programming technique to avoid unexpected program results.
C Tutorials on this website can be found at: