User Defined Data Types in C Language

aimtocode

Data type Definition

The data type supported in a language dictates the type of values which can be processed by the language.

C supports several different types of data, each of which may be represented differently within the computers memory.

Data types are means to identify the type of data and associated operations for handling it. Every variable in C has a data types.

Data types in C ?


Since we have already studied Primitive and Derived data types, we will be studying User defined datatypes in this chapter. however you can reread them.

User defined data types

Sometimes, the basic set of data types defined in the C language such as int, float etc. may be insufficient for your application. In such circumstances, we can create our own data types which are based on the standard ones.

  • Structure
  • Union
  • Enumerator and
  • Type of

C allows the feature called type definition which allows programmers to define their own identifiers that would represent an existing data type. There are three such types:

Data TypesDescription
StructureIt is a package of variables of different types under a single name. This is done to handle data efficiently. "struct" keyword is used to define a structure.
UnionThese allow storing various data types in the same memory location. Programmers can define a union with different members, but only a single member can contain a value at a given time.
EnumEnumeration is a special data type that consists of integral constants, and each of them is assigned with a specific name. "enum" keyword is used to define the enumerated data type.

Example:



Read also

aimtocode