C supports the idea of programmers creating their own data types.
Ordinal Data Types :
Ordinal data types have the following characteristics:
1. There exists a smallest value in the set of values.
2. There exists the largest value in the set of values.
3. There exists an order of values from the smallest to the largest.
Example:
The “char” data type is an ordinal data type. Each character value has an integer value associated with it. There are 256 characters.
1. The smallest character value has the ASCII value of 0.
2. The largest character value has the ASCII value of 255.
3. The sequence of ASCII values is 0, 1, 2,......., 253, 254, 255.
‘A’ == 65 ‘B’ == 66 ‘C’ == 67 etc....
The data types that are defined by the user are called user-defined derived data types.
1. Enumeration(enum)
2. Typedef defined DataType(typedef)
1. Enumeration: Enumeration (or enum) is a user-defined data type in C. It is mainly used to assign names to integral constants, the names make a program easy to read and maintain.
Syntax: enum State {Working = 1, Failed = 0};
Eg:
#include
enum week { Mon, Tue, Wed,Thur, Fri, Sat, Sun };
int main()
{
enum week day;
day = Wed;
printf(“%d”,day);
return 0;
}
2. Typedef defined DataType (typedef):
Using typedef does not actually create a new data class, rather it defines a name for an existing type.
This can increase the portability(the ability of a program to be used across different types of machines. i.e., mini, mainframe, micro, etc without much changes into the code)of a program as only the typedef statements would have to be changed.
Syntax: typedef type name;
Recommended Questions
Useful Files
Users Joined
C supports the idea of programmers creating their own data types.
Ordinal Data Types :
Ordinal data types have the following characteristics:
1. There exists a smallest value in the set of values.
2. There exists the largest value in the set of values.
3. There exists an order of values from the smallest to the largest.
Example:
The “char” data type is an ordinal data type. Each character value has an integer value associated with it. There are 256 characters.
1. The smallest character value has the ASCII value of 0.
2. The largest character value has the ASCII value of 255.
3. The sequence of ASCII values is 0, 1, 2,......., 253, 254, 255.
‘A’ == 65 ‘B’ == 66 ‘C’ == 67 etc....
The data types that are defined by the user are called user-defined derived data types.
1. Enumeration(enum)
2. Typedef defined DataType(typedef)
1. Enumeration: Enumeration (or enum) is a user-defined data type in C. It is mainly used to assign names to integral constants, the names make a program easy to read and maintain.
Syntax: enum State {Working = 1, Failed = 0};
Eg:
#include
enum week { Mon, Tue, Wed,Thur, Fri, Sat, Sun };
int main()
{
enum week day;
day = Wed;
printf(“%d”,day);
return 0;
}
2. Typedef defined DataType (typedef):
Using typedef does not actually create a new data class, rather it defines a name for an existing type.
This can increase the portability(the ability of a program to be used across different types of machines. i.e., mini, mainframe, micro, etc without much changes into the code)of a program as only the typedef statements would have to be changed.
Syntax: typedef type name;