A variable in C is a named piece of memory which is used to store data and
access it whenever required. It allows us to use the memory without having
to memorize the exact memory address.
To create a variable in C, we have to specify a name and the type of data it is
going to store in the syntax.
data_type name;
For example, int, char, float, double, etc.
int num;
char letter;
float decimal;
C Variable Initialization
Once the variable is declared, we can store useful values in it. The first value
we store is called initial value and the process is called Initialization. It is
done using assignment operator (=).
int num;
num = 3;
It is important to initialize a variable because a C variable only contains
garbage value when it is declared. We can also initialize a variable along
with declaration.
int num = 3;
Accessing Variables
The data stored inside a C variable can be easily accessed by using the
variable's name.
Example:
#include <stdio.h>
int main() {
// Create integer variable
int num = 3;
// Access the value stored in
// variable
printf("%d", num);
return 0;
}
Output
3

Variable with Example in C Programming Language

  • 1.
    A variable inC is a named piece of memory which is used to store data and access it whenever required. It allows us to use the memory without having to memorize the exact memory address. To create a variable in C, we have to specify a name and the type of data it is going to store in the syntax. data_type name; For example, int, char, float, double, etc. int num; char letter; float decimal; C Variable Initialization Once the variable is declared, we can store useful values in it. The first value we store is called initial value and the process is called Initialization. It is done using assignment operator (=). int num; num = 3; It is important to initialize a variable because a C variable only contains garbage value when it is declared. We can also initialize a variable along with declaration. int num = 3; Accessing Variables The data stored inside a C variable can be easily accessed by using the variable's name. Example: #include <stdio.h> int main() {
  • 2.
    // Create integervariable int num = 3; // Access the value stored in // variable printf("%d", num); return 0; } Output 3