Subscribe Us

C programming : Data Type in C - smartduniya


In this post I’ll be talking about   Data type in C programming  .

    data type in C

    What are data types in C ?

    The answer to this question is that data type is a type of data and its definition is so simple. Let me explain this to you with an example.
    For example: What if I give you a number "5" and ask you what kind of data it is? You can say "this is an integer" and yes, you are absolutely right. 5 is an integer and an integer is a type of data "5".
    Similarly if I ask you what kind of data is associated with the letter "M"? .
    It may appear to you as a character. So now you understand what data type is. It refers only to the type of data and has three classes: primary data type which is also called basic data type/ fundamental data type,
    derived data type and user defined data type. The data type that I am going to talk about in this tutorial is the primary data type. I will talk about user-defined data types later in upcoming posts, especially after enabling you enough to declare variables and operate on them, and as far as data types are concerned, I will talk about that and when to confront them.

    Data types example in C :

    However, for now I will give you   examples for derived data type. Array, pointer, structure are some examples of derived data type.   Now let's proceed to talk about primary data type which is also called fundamental data type. The primary data types is divided into four types: integer type, float type, character type   and void type. So now let's move to talk about integer type. The keyword used for integer is int and it refers to a digit or sequence of digit and the space it   occupies is machine dependent.

    So in general it occupies one word of storage. What it means is   if you have 16-bit machine then it will occupy 16 bits and the size of integer is limited to   the range zero to 65535. Actually you don't have to remember the range. All you need to remember is   space it occupies and that is one word of internal storage. If you are using 32-bit word length, it   occupies 32 bits of internal memory and the range of integer it allows can be calculated by 0 to   2^n - (1), where n is word length or total bit used to store an integer and for signed integer   the range of integer permitted can be calculated as -2^(n-1) to +2^(n-1) - 1.It   is because one bit is used for sign and rest of the bits for magnitude.

    Look, in decimal   number system we generally prefix number by plus or negative sign to represent positive   or negative value respectively but we don't have such privilege in binary number system which is   the only language that computer understands so one bit is used for sign and rest of the bits for magnitude  So if you use 16-bit machine, the size of integer ranges from  -32768 to +32767. Now the next data type which we are going to talk about is floating point data type. The keyword   used for float is float itself but in lower case and the all real number which consists of both   integer and fractional part are stored in 32 bit irrespective of the word length of the machine and with precision with six digits of precision.

    Here precision refers to the   number of digits to the right of decimal point. So 6 digit of precision means that   maximum 6 number of digits to the right of decimal point can be stored and if the accuracy provided   by it is not enough then a type double can be used and double uses 64 bits and provides   the precision of 14 digits.

    C has various data types :

    Basic data type includes standard and extended integer types

    Enumerated data types contains real and complex floating-point types

    Derived data types include pointer types, array types, structure types, union types and function types.

    Next data type is  void Data type

    It is important to notice that function type depicts the interface to a function. It specifies all types of function’s parameters and function's return value type.

    Sometimes you may find different types such as:

    Arithmetic = Basic + Enumerated  Data types

    Scalar = Arithmetic + pointer  Data types

    Aggregate = Array + structure types.

    You can see below discuses all the above data type in details

    Integer  Data Types :

    Integer data types in C with their specification so you can use them effectively in you program.

    ex. int a = 10; // it means 'a' store integer value of 10 

    Float Data Types:

    Floating-point data types are use  to represent non-integer number with a decimal point at any position.

    ex. float a = 10.255; // it means 'a' store floating value of 10.255

    Character  Data Type :

    Character data type is use to print a character variable in C.

    Enumerated Data types :

    In this tutorial, you will learn about C enumeration types to make your code more readable and easier to maintain.

    void Data types in C :

    Now let's move to another fundamental data type which is   character and the keyword used for character is char and character type data refers to a   single character and it uses a one byte of internal storage which is equals to 8 bit   and the unsigned characters have value between 0 to 255 and the sign characters have from -128   to +127 and the last fundamental data type left to be discussed is void.  

    Actually void has no value and it is especially used to specify the type of the function and as   I have made this post keeping beginners in mind I will be talking about this void while explaining function but for now all you should know about it is void has no value   and now I am going to end this post here.

     If you like this post keep your thumb up, share it as much as possible and yeah don't forget to Subscribe smartduniya just put your email on subscribe box and press subscribe to stay updated.

    Post a Comment