What are Data Types in C and Explain their Types?


DATA TYPES IN C


In this article, you will learn about Data Types in C programming, Types of Data Types in C, Size, range and Format specifier of Data Types in C and its examples.

After learning this article you can completely able to define and understand about Data Types.



    data types in C programming
    Data Types in C
    Data types is a special term in C language which is related to the type and size of variables and functions. Variable in C language has an associated data types which tells the compiler that what type of data to be stored into variable. Each data types requires different size of memory and has some specific characteristics. C language has primitive data types to store various kind of data that we can use it in our program. 

    Data types is also associated to a functions in C language which denotes what type of value to be returned when function is called.


      Type of Data Types in C

       type of data types in C, data types in C programming
      Data Types in C


       *Fundamental Data Types


    Fundamental data types are the data types which is already defined in C language and also it is also called primitive data types, which are given below:-

    • Integer types
    • Floating types
    • Character types
    • Double types
    • Void types

    Read more about What are Operators in C?

    Now, explaining each Data Types one by one:-

    Integer Types


    Integer data type is a collection of numbers that includes all the whole numbers and their negatives values.

    In C programming, it is data a types used to represent the integer values. We use integer types for declaring a variable as an integer type or define the return type of function as integer type.

    A variable declared as an integer can store only integer values and occupies a certain memory space in computer. The amount of space taken by int variable is depend on the configuration of computer system.

    we declare integer type variable using ' int ' keyword as given below:

    int a=5;

    int x=100;

    Type Size (bytes) Range Format Specifier
    short signed int
    2
    -32768 to 32767
    %d
    short unsigned int
    2
    0 to 65535
    %u
    signed int 
    2
    -32768 to 32767
    %d
    unsigned int
    2
    0 to 65535
    %u
    long signed int 
    4
    -2147483648 to +2147483647
    %ld
    long unsigned int
    4
    0 to 4294967295
    %lu


    Float Types


    Floating data type contains the number having decimal points. In C programming we use it to declare a variable to store a point value number. It also contains exponential numbers. Floating point numbers are stored in 32 bits with 6 digit of precision. 

    we declare float type variable using ' float ' keyword as given below:


    float x= 1.2;

    float y= 1.001;


    TypeSize (bytes)RangeFormat Specifier
    float
    4
    -3.4e38 to +3.4e38
    %f


    Character Types


    Character data type Character is a symbol in C programming that has special meaning. A character can be any numbers, letters, special symbols. We use it to declare a variable as char type. A char type variable declare in a single quotes.

    We declare char type variable using ' char ' keyword as given below:

    char x='5';

    char first='a'


    TypeSize (bytes)RangeFormat Specifier
    signed char
    1
    -128 to +127
    %c
    unsigned char
    1
    0 to 255
    %c


    Double Types


    Double type It also contain number having decimal points. In C programming we use it to declare a variable to store a point value number like floating types but its range and size is more than the size of floating types. Double data types numbers are stored in 64 bits with 14 digits of precision.

    We declare double type variable using ' double ' keyword as given below:


    double x= 9.632541987563;

    double y=2.000000000000;

    TypeSize (bytes)RangeFormat Specifier
    double
    8
    -1.7e308 to +1.7e308
    %lf
    long double
    10
    -1.7e4932 to +1.7e4932
    %Lf


    Void Types


    Void data type is an empty data type having no values. It is generally used with functions and pointers. If function is declared with void types then it means that function does not return any value. And it is also used as argument in function which means that it does not take any parameter. 

    It is used with pointers which denotes the address of an object but not of its types. When a pointer variable declared using void keyword then it becomes a general purpose variable, it means that address of any variable of any data type like int, char, float etc can be assigned to a void pointer variable.

    We declare void type variable using ' void ' keyword as given below:

    void sum() //means that function sum() has no return type.

    void *p //means that it is a general purpose pointer variable.

    Example:
    int main()
    {
        int a, b, c; // * here value of a, b and c are stored int type
        a= 60;
        b= 90;
        c= 85;
    
        float avg; // * value of avg is stored in float type
    
        avg= (a+b+c)/3;
    
        printf("Average of a, b and c is %f", avg); // * Format specifier of float is %f
    
        return 0;
    }
    
    Average of a, b and c is 78.000000


       *Derived Data Types


      Derived data types are the data types which is derived from fundamental or primitive data types. It simply add some new functionality to a fundamental data types and create a new customized data type as user choice. 

      For example array, structure, union etc are derived data types.

      Example:
      #include <stdio.h>
      #include <string.h>
      int main()
      {
        struct student // * here new data type is created as student type
        {
          int class;
          int roll_no;
          char name[30];
        };
        // p1 and p2 are of student type
        struct student p1 = {1,10,"Rajeev"};
        struct student p2;
        p2 = p1;
        printf("Class\t : %d\n", p2.class);
        printf("Roll_no\t : %d\n", p2.roll_no);
        printf("Name\t : %s\n", p2.name);
        return 0;
      }
      
      Class    : 1
      Roll_no  : 10
      Name     : Rajeev


      Conclusion:-

      In this article, we have thoroughly read about Data Types in C language and its different types. As you  have learn the types of  Data Types in C are of two types:-
      1. Fundamental Data Type
      2. Derived Data Type
      If you are interested then also read:


      If you find this article helpful then please share!


      Tags: Data TypesData Types in C programmingTypes of Data Types in C, Example of Data Types in C



      No comments:

      Powered by Blogger.