User-Defined Data Types in C Programming 

Data Types: It is a type of data which is used in the program. There are many predefined data types in the c library like int, char, float etc. As the name, a Data-type defines the type of data being used. 

When ever we define a variable or use any data in the C language program, we have to specify the type of the data, so that the compiler knows what type of data to expect.

Data types is a type of data which is used in the C program. There are many predefined data types in the C library.

Predefined data-types are integer (int), floating (float) and character (char) etc.

Learn Best User Defined Data Types in C Language
Learn Best User Defined Data Types in C Language

    Primary Data Types in C

    C Language provides has five basic primary data types

    1. Character Data-Types: Character data types is an ASCII character set of single alphabet values like 'a' and 'A' etc. 

    2. Integer Data Types: Integer data types are used to store the natural whole numbers. like 1,2,4,6,100,200 etc.

    3. Floating Data Types: Floating data types are store the decimal point or real numbers values store like 7.8,6.9,99.6 etc.

    4. Double Data Types: Double data types can be used in very large numeric values, which are not allowed in integer or floating point data types. 

    5. Void Data Types: Void data types is no value. Void data types are mostly used when defining main function in C language program.

    Data TypesKeywords
    Characterchar
    Integerint
    Floatingfloat
    Doubledouble
    voidvoid

    Explain Different Types of Data Types in C

    There are two types of Data-types

    1. Predefined Data Types

    2. User Defined Data Types

    Explain Basic Data Types in C Language

    Basic Data Types: A basic data types are integer based and floating based data types. C Language support s both signed and unsigned literals.

    The memory size of the basic data types may be changed according to 32-bit or 64-bit operating system. 

    Integer Data TypesFloating  Data Types Character  Data Types 
    (int)(float)(char)

    Integer Data Types in C Language

    Data TypesSize of ByteRange
    short2-32768 To +32768
    int2-32768  To +32768
    Unsigned int20 To 65536
    long4-214748 To +214748
    Unsigned long int40 To 4294967295

    Float Data Types in C Language

    Data TypesSize of BytesRange
    float43.4E-38 To 3.4E+38
    double81.7E-308 To 1.7e+308
    Long double103.4E-4932 To 1.1E+4932

    Character Data Types in Language
    Data TypesSize of BytesRange
    char1-128 To +127
    Signed char1-128 To +127
    Unsigned char1 0 To 255

    Derived Data-Types in C 

    Derived Data-Types: Derived data-types that are derived from the basic data types are called derived data types.

    Derived data types do not create new data types. Derived data types are derived from the primitive data types by adding some extra relational with the various elements of the primary data types.

    The derived data types can be used to represent a single value or multiple values.

    ArrayPointerStructure      Union


    1. Array Data Types: Array data types are an ordered sequence of finite data items of the same data types. Array is a collection of similar data or similar data types.

    #include<stdio.h>

    #include<conio.h>

    void main()

    {

    int a[100], n, i;

    printf("Enter array Size:");

    scanf("%d", &n);

    for(int i=0;i<n;i++)

    {

    printf("Enter Array Element[%d]:", i);

    scanf("%d", &a[i]);

    }

    printf("Enter New Array Element Insert:");

    scanf("%d", &i);

    a[n]=l;

    n++;

    for(int i=0;i<n;i++)

    printf("New Array[%d]:%d\n",i,a[i]);

    }

    }

    getch();

    }


    **********OUTPUT**********

    Enter array Size:5

    Enter Array Element[0]:5

    Enter Array Element[1]:8

    Enter Array Element[2]:7

    Enter Array Element[3]:4

    Enter Array Element[4]:5


    Enter New Array Element Insert:88

    New Array[0]:5

    New Array[1]:8

    New Array[2]:7

    New Array[3]:4

    New Array[4]:5

    New Array[5]:88

     

    2. Pointer Data Types: A pointer data types is a special data types of variables used to hold the address of another variables.

    #include<stdio.h>

    #include<conio.h>

    void main()

    {

      int a=100;

    int *p;

    p=&a;

    printf("Value of a:%d\n", a);

    printf("Address of a:%d\n", &a);

    printf("Value of p:%d\n", p);

    printf("Address of p:%d", &p);


    **********OUTPUT**********

    Value of a: 100

    Address of a: 828493

    Value of p: 100

    Address of a: 828493


    3. Function Data Types: Function is a collection of statements that performs a specific task. a function is a self-contained block of one more statements with the name.

    #include<stdio.h>

    #include<conio.h>

    void msg()

    {

      printf("Welcome to Learn Coding Website");

    }

    void main()

    {

      msg();

    getch();

    }


    **********OUTPUT**********

    Welcome to Learn Coding Website


    4. Structure Data Types: Structure data types, a collection of different data type values stored in a contiguous memory allocation.

    #include<stdio.h>

    #include<conio.h>

    #include<string.h>

    struct Employee

    {

    int id;

    char name[50];

    int salary;

    };

    void main()

    {   

        struct Employee e[10];

        int n;

    printf("Enter Employee Number:");

    scanf("%d",&n);

    for(int i=0;i<n;i++)

    {

    printf("Enter Employee Id:");

    scanf("%d",&e[i].id);

    printf("Enter Employee Name:");

        scanf("%s",e[i].name);

    printf("Enter Employee Salary:");

    scanf("%d",&e[i].salary);

    }

    printf("--------------------------------\n");

    for(int i=0;i<n;i++)

    {

    printf("Employee Id:%d\n",e[i].id);

    printf("Employee Name:%s\n",e[i].name);

    printf("Employee Salary:%d\n",e[i].salary);

        printf("--------------------------------\n");

    }

    getch();

    }


    **********OUTPUT**********

    Enter Employee Number:1

    Enter Employee Id:853

    Enter Employee Name:Learn

    Enter Employee Salary:67454.3

    --------------------------------

    Employee Id:853

    Employee Name:Learn

    Employee Salary:67454


    5. Union Data Types: Union data types is the same structure where the memory allocation to the largest data type is reused for other data types. 

    #include<stdio.h>

    #include<string.h>

    union Employee

    {

    int id;

    char name[50];

    int salary;

    };

    int main()

    {   

        union Employee e[10];

        int n;

    printf("Enter Employee Number:");

    scanf("%d",&n);

    for(int i=0;i<n;i++)

    {

    printf("Enter Employee Id:");

    scanf("%d",&e[i].id);

    printf("Enter Employee Name:");

        scanf("%s",e[i].name);

    printf("Enter Employee Salary:");

    scanf("%d",&e[i].salary);

    }

    printf("--------------------------------\n");

    for(int i=0;i<n;i++)

    {

    printf("Employee Id:%d\n",e[i].id);

    printf("Employee Name:%s\n",e[i].name);

    printf("Employee Salary:%d\n",e[i].salary);

        printf("--------------------------------\n");

    }

    }


    **********OUTPUT**********

    Enter Employee Number:1

    Enter Employee Id:654564

    Enter Employee Name:Learncoding

    Enter Employee Salary:67557

    --------------------------------

    Employee Id:67557

    Employee Name:s?

    Employee Salary:67557


    FAQ Question Data Types

    Q.1 What are data types in C?
    Ans: Data type is a type of data which is used in the c program. The data-types define the amount of memory area allocated to variables.
    data-types are integer (int) floating (float) and character (char).

    Q.1What is data type in C with example?
    Ans: 

    #include<stdio.h>

    #include<conio.h>

    void main()

    {

      int a=100;

      float b=897.67;

      char c='L';


    printf("Integer Data types:%d\n", a);

    printf("Floating Data types:%f\n", b);

    printf("Character Data types:%c\n", c);

    getch();

    }


    **********OUTPUT**********

    Integer Data types:100

    Floating Data types:897.67

    Character Data types:L


    Q.1What are the 5 data types?
    Ans: Five Types of data types 
    1. Integer Data Types
    2. Floating Data Types
    3. Character Data Types
    4. Array Data Types
    5. Pointer Data Types

    Q.1What are the 5 data types in C?
    Ans:  Five Types of data types 
    1. Integer Data Types
    2. Floating Data Types
    3. Character Data Types
    4. Array Data Types
    5. Pointer Data Types

    Q.1What is an array in C language?
    Ans: Array is a collection of data or same data types. It can be store data of same data types like integer data types can be hold integer value.
    floating data type can hold a float value. array value can be accessed through index point.

    Q.1What are the 7 data types?
    Ans: 
    1. Integer Data Types
    2. Floating Data Types
    3. Character Data Types
    4. Array Data Types
    5. Pointer Data Types
    6. Structure Data Types
    7. Union Data Types

    Conclusion: Hello C Programmer, welcome to learn to code website. in this post defined the C data types, all types or user defined data types defined.
    C Data types all points covered in this post.