Primitive Data Type In C Language.

Primitive Data Type In C Language.


Hello Programmer,

In the last blog, we were read about Data Type but in this blog, we will discuss the first part of data type which is Primitive data type or we call that Basic data type.

In the last time we discuss that primitive data type is a divide in 5 part now we will discuss each part one by one.


1) Int Data Type:


We already know that what is an integer so like that integer is a data type which defines that variable hold integer type value and in future variable make space in memory for the integer value. 

In C language (int) keyword is used for declaring the "int data type". As you know integer is a whole number for example 4,22,-4,0,-222 etc.

Integer data type never holds fractional value and you can declare an identifier with int keyword so it becomes int data type and hold an only whole number. 

How We Declare Int Data Type?

    int sum;
    int num=45;
    int a,b,c;

As you see above example that how you declare int data type in above example int is a keyword which you used for declaring int data type and the "sum" is variable which hold only int type value. 

In second example int is a keyword which is used before num identifier and "num" is a variable which has a hold value 45.

In the third example "a,b,c" these are variable which is declared with int keyword and they will hold only integer type value.



2) Char Data Type:


As a programmer, we know that what is char. A single character which is enclosed in single quotes is known as character. If you declare an identifier as char becomes a character variable.

You can not assign more than one character to one char variable in the c programming language. 


How We Declare Char Data Type In C Programming Language:

    char sex='M'
    char a,b,x;
    char z;

As you have seen in the above example that how you declare any variable as char data type variable. One thing you remember that whenever you declare a char variable it makes space in memory for a character which he will hold.

In the above example sex a variable for char type which is assigned a character.

In the second example "a,b,c" these are variable of char type which will hold a character in future.




3) Float Data Type:


As you know what is floating value. Whenever you declare an identifier as float it becomes a floating-point variable and it will hold float value.

What is a floating-point number? A number which has fractional part is known as a floating-point number.

For Example 6.54,345.33 these both are a floating-point number.

An Identifier which is used "float" keyword before identifier name it becomes float data type variable and it will only hold a floating number.

How We Declare Float Variable With Float Data Type?

    float average;
    float length=6.5;
    float side=10.5;

These examples clearly define how you declare a variable with a float data type.



4) Double Data Type:


Recently we studied that float hold floating value and now we discuss double it is also used to hold floating value.

It is treated as a dusting data type because it occupies twice as much memory as type float and store floating-point number with much large range.

How We Declare Variable With Double Data Type:

    double length;
    double average;
    double side=9939439.5;

In the above example, we declare some variable as a double data type variable.


5) Void Data Type:


Void data type represents an empty set of values. It is generally used to specify the type of functions. The type of the function is void when it does not return any value to the calling function.





Sharing Is Caring...

Comments :

Post a Comment