Data types in C language | C Programs | C Language

Data types in c refer to an extensive system used for declaring variables or functions of different types. The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted.

Learn C from Youtube Free Tutorials  

 


Data types in C :-


    1.Fundamental Data Types

        Integer types
        Floating type
        Character type

   2.Derived Data Types

        Arrays
        Pointers
        Structures
        Enumeration

    

   1. Integer data types


    Integers are whole numbers that can have both positive and negative values, but no decimal values. Example: 0, -5, 10

    In C programming, keyword int is used for declaring integer variable. For example:

    int id;

    Here, id is a variable of type integer.

    You can declare multiple variable at once in C programming. For example:

    int id, age;

    The size of int is either 2 bytes(In older PC's) or 4 bytes. If you consider an integer having size of 4 byte( equal to 32 bits), it can take 232 distinct states as: -231,-231+1, ...,-2, -1, 0, 1, 2, ..., 231-2, 231-1

    Similarly, int of 2 bytes, it can take 216 distinct states from -215 to 215-1. If you try to store larger number than 231-1, i.e,+2147483647 and smaller number than -231, i.e, -2147483648, program will not run correctly.  

    Floating types


    Floating type variables can hold real numbers such as: 2.34, -9.382, 5.0 etc. You can declare a floating point variable in C by using either float or double keyword. For example:

    float accountBalance;
    double bookPrice;

    Here, both accountBalance and bookPrice are floating type variables.

    In C, floating values can be represented in exponential form as well. For example:

    float normalizationFactor = 22.482e2;

  

    Character types


    Keyword char is used for declaring character type variables. For example:
    char test = 'h'

    Here, test is a character variable. The value of test is 'h'.

    The size of character variable is 1 byte.

   2. Derived Data Types

     Arrays


    Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.

    Instead of declaring individual variables, such as number0, number1, ..., and number99, you declare one array variable such as numbers and use numbers[0], numbers[1], and ..., numbers[99] to represent individual variables. A specific element in an array is accessed by an index.

    All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element.
    Arrays in C

     Pointers


    Pointers in C are easy and fun to learn. Some C programming tasks are performed more easily with pointers, and other tasks, such as dynamic memory allocation, cannot be performed without using pointers. So it becomes necessary to learn pointers to become a perfect C programmer.

    Structures


    Arrays allow to define type of variables that can hold several data items of the same kind. Similarly structure is another user defined data type available in C that allows to combine data items of different kinds.

    Structures are used to represent a record. Suppose you want to keep track of your books in a library. You might want to track the following attributes about each book −

    Title
    Author
    Subject
    Book ID



Thanks for Reading Please Follow and Share and Comment if You Like it !!!
If this POST contains Any Wrong Information Feel free to comment it i will FIX the Problem !!! or You can contact me at given links below



Follow the Blog for more new post http://rajeevchaudhary-youtuber.blogspot.com/
 
 

Share:

No comments:

Post a Comment

Facebook

Popular

Recent Posts

Unordered List

  • Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
  • Aliquam tincidunt mauris eu risus.
  • Vestibulum auctor dapibus neque.

Contact Form

Name

Email *

Message *