what are data types in c

   

  • Literal:This is nothing but a Constant Value or fixed value which is not change by the program during its execution.This type of value are useful when we don't want to change the value throught the program. 
           
    Eg:
        printf("BirthYear:%d",2003);
         Output:BirthYear:2003 
 
In above Eg we Can see that We are printing BirthYear.Here we have used 2003 as literal.Important to note here is We have used literal because the BirthYear will Never Change for Particular Person.  

  • Variable:In Programming,Variable is nothing but a Container in which we can put Some Value.As the name suggest variable which mean varying,So we Can say Variable is used to store temporary value which is going to be vary(change) in future.For eg We have to use Age as value and if we use Age as literal then it would be tedious because Age does not remain constant So after every 1 year we have to manually change the age in program which would be very difficult,to overcome this we use variables.
 
      Eg:
          int age=43;
          printf("Age:%d",age);
          output:Age:43
 
    In above if we have to change the value we can simply increment it,By using (++) increment operator.Don't Worry if don't know about  increment operator we will discuss it in further lecture.
 
        Variable Declaration Syntax:
            
        data_type_name variable_name;
        
         Eg:
 
              int a;
 
    Data Types:It is type of data of which the value is going to be stored in variable.
 
    Eg:
        int b=5;
 
 In above Eg,We have Created a variable of  type int,So we can say that In variable b we can store integer value.In C there are several data types which are used for different purposes.

        

  • Character:It is most basic data type of C.It is use to store single character.It require single byte of  memory to store value.%c format specifier is used for character data type.When we declare character type variable
     we use char keyword.To store character type value in variable we use '  ' (Single inverted comma).
         Eg: 
           char bloodgroup='A';
           printf("Bloodgroup:%c",bloodgroup);

    
       output:
Bloodgroup:A
  •  Integer:It is also most basic data type in C.It is used  to store integer type value.It require two byte  of  memory to store value.%d format specifier is used for integer data type.When we declare integer type variable we use int keyword.int is guaranteed to be able to hold -32767 to 32767.    
 
        Eg: 
             int rollno=9;
             printf("Rollno:%d",rollno);
 
             output:Rollno:9
 
  • Float:It is used to store decimal value.It is used Whenever there is mathematical calculation.for eg divison.%f format specifier is used for float data type.When we declare float type variable we use float  keyword.It require four byte of memory to store value.Float range is 1.2E-38 to 3.4E+38
       Eg:
           float a=5;
           float b=2;
           float c=a/b;
           printf("Divison of a & b:%f",c);
 
          Output:Divison of a & b:2.500000
 
 In above eg if we would used int data type of c variable instead of float  then it would given Divison of a&b as 4 because it truncate(discard) the value after decimal.        
  • Double:It is  mostly similar to float but  there is only difference between float and double which is nothing but in precision. Precision refers to no of values after decimal.double has higher precision than float.double is used when the numbers are greater.Whenever we declare double type variable we use double  keyword. %lf format specifier is used for double data type.double range is 2.3E-308 to 1.7E+308l.It require eight byte of memory to store value.
    Eg:
       double a=59499949499.59;
       double b=2504004004.5;     
       double c;
       printf("Divison of a & b:%lf",c);
 
       Output:Divison of a & b:23.754848
 
     We will discuss derived data types in further lectures.



If you any have doubt,suggestion regarding this post or website then feel free to share with us.
 
If you have learned something new from this post then share this post with your family and
friends.
 
Happy Learning :)😎   
 
Previous Next

5 Comments

  1. Well my passion started with football or as its referred to as soccer in US, yes i actually mean it, i exploit to spend most of my time in the field playing football and therefore the dream.






    That I had at that point is to become a player in Manchester united and for years i used to be hooked in to it.





    Defiantly i used to be shy to inform to people aboutit because i assumed they might ridicule of me,

    https://oocto.blogspot.com

    ReplyDelete
Previous Post Next Post