Declaration Variables in C
Variables in C Language Program need to be declared before using it. Variables can be declared with Data type and name of the Variable or identifier
Variables Declared in Two Ways:
i. Primary Type Declaration:
Primary type declaration is used to declare a variable with primitive data types, which are also called as built-in data types.
Most commonly used primary data types are int, float, char, boolean, double, long ,bool etc.
a. Single primary type declaration
Eg:- char Grade = 'A';
b.Multiple primary type declarations in the same line
When multiple variables are declared in the same line, we need to use a comma to separate the variables, as shown below.
Eg:- int Length= 12, Width = 13, Depth = 14;
ii. User-Defined Type Declaration:
User-Defined Type Declaration is a type of declaration where the data type is defined by the user.User or programmer has the flexibility to declare his own data type by using inbuilt data type.
Some of the most commonly used data types are struct, Union, enum, typedef etc.
1.Structure: Structures are used to group data items of different types into a single user-defined data type variable. Or we can group different data type using single variable. In Structure member or attributes does not share the memory location. Every member in structure occupy separate memory location.
2. Union: Unions are user-defined data types in which different type of members share a common memory location, so any one of them is accessible at a time. When we want to access only one member, then we use Union.
3. Typedef : is a keyword in C programming that is used to give new name to existing type. typedef keyword gives the meaningful name to existing type so that user will understand more friendly. We need to use the keyword typedef to define the data type. Now we can use those new data types in our program, as shown below.
typedef unsigned int unit;
here we have declared the unit variable of type unsigned int by using typedef keyword.