![]() |
VOOZH | about |
Data Types are the types of data that can be stored in memory using a programming language. Basically, data types are used to indicate the type of data that a variable can store. These data types require different amounts of memory and there are particular operations that can be performed on them. These data types can be broadly classified into three types:
In this article, will discuss the User-Defined Data Type.
The data types defined by the user themself are referred to as user-defined data types. These data types are derived from the existing datatypes.
There are 4 types of user-defined data types in C. They are
As we know, C doesn't have built-in object-oriented features like C++ but structures can be used to achieve encapsulation to some level. Structures are used to group items of different types into a single type. The "struct" keyword is used to define a structure. The size of the structure is equal to or greater than the total size of all of its members.
struct structure_name {
data_type member_name1;
data_type member_name1;
....
....
};Name: GeeksforGeeks Age: 30
Unions are similar to structures in many ways. What makes a union different is that all the members in the union are stored in the same memory location resulting in only one member containing data at the same time. The size of the union is the size of its largest member. Union is declared using the "union" keyword.
union union_name {
datatype member1;
datatype member2;
...
};Data.i: 10 Data.f: 3.140000 Data.str: GeeksforGeeks, C
Enum is short for "Enumeration". It allows the user to create custom data types with a set of named integer constants. The "enum" keyword is used to declare an enumeration. Enum simplifies and makes the program more readable.
enum enum_name {const1, const2, ..., constN};
Here, the const1 will be assigned 0, const2 = 1, and so on in the sequence.
We can also assign a custom integer value such as:
enum enum_name {
const1 = 8;
const2 = 4;
}Today is 4
typedef is used to redefine the existing data type names. Basically, it is used to provide new names to the existing data types. The "typedef" keyword is used for this purpose;
typedef existing_name alias_name;
Best Tutorials on: GeeksforGeeks