11/11/2019
1.Primary declaration:-
In primary type declaration, A declaration statement begins with the type, end by the name of one or more variables. A declaration statement must end be with a semicolon.
Syntax of declaration sentences.
Syntax: data_type variable_1, variable_2, .....,variable_n;
Declaration of multiple variables of the same data types can be done in one statement.
For Example,
int a;
int b;
int c;
can be also written as
int a, b, c;
When variables are declared inside a function, they are called local variables. When the variables are declared in the definition of function parameters, these variables are called formal parameters. when the variables are declared outside all functions, they are called global variables.
2. User-Defined declaration:-
C language supports a feature known as "type definition" which allows defining an identifier that would represent an existing data type. the user-defined data type identifier can later be used to declare a variable.
Syntax of user-defined type declaration is,
Syntax: typedef type identifier;
Where type refers to existing data types and identifiers refers to the new name given to the data type. typedef cannot create a new type.
Some Examples,
typedef int marks;
typedef float sum;
Here, marks symbolize int and float symbolize float. they can be used to declare variable later. as follows,
marks batch1, batch2;
sum sum1, sum2;
where marks and sum represent integer type and float type value.
we don't have to declare their datatype again.
Another user-defined data type is the enumerated data type provided by ANSI.
Syntax: enum identifier{v1, v2, v3, ...vn};