• admin@embedclogic.com

User-defined Datatypes

When a programmer-defined its own data type for any specific purpose then it is known as a user-defined-datatypes.Since these self-defined data types are not standard data types so compiler needs to know about these User-defined data types at the time of compilation.

There are two keywords defined in the standard library through which programmer must aware to the compiler about the self-constructed data type in his programme.These two keywords are-

enum

typedef

 enum in C

enum is basically used for the integers to give a name which increases the readability of the program.

Syntax
Example

you can see in above code

 status = is a data type to store constants FAIL and OK

 FAIL ,OK = Constants and values are their indexes(0 and 1).

By default, enum constants take their index value but we can change their indexes by assigning them different value.

See in below code enum_Const4 has index 41 because of previous index change to 40.

enum constants must have values in defined range for integer.

Multiple enum constants can have same values

Since enum represent constants so the size of enum will be the size of an int.

enum constants may have alphabets.

 typedef in C:

‘typedef’ is used to replace standard data type name with some alias name.

Syntax:
Example:

so in above examples int8_t,uint32_t,int16_t and empdetail are the user-defined-datatypes.

Let us see a program to be more clear –

See more about the typedef in C.

Subscribe and stay updated with our latest articles.

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

Embedclogic will use the information you provide on this form to be in touch with you and to provide updates and marketing.