What is Data types and modifier?



fig:-     Datatype in C

Datatype defines what type of value is going to be store in which data type int(for number), float(for point value), string(for alphabets). if we need to write a program where users store user inputs values then we need to create a space in memory for that we will make variables, and to create a variable we have to use keywords that are defined by C which is shown here:- (int, float, string, etc 

Syntax 

Datatype variable_name; 

Int a;   


We can separate data type in 2 part  

  1. Primary datatype:-  it consists of integer, float, double, character, void. 

  2. Secondary datatype:- it consists of an array, Enum, pointer, structure, etc. 

 

  1. Primary data type:- they are also called an inbuild datatype,  

1. integer type:- for this we use int keyword it hold value like 10, 20, 1, 2, etc. its size is 2 byte(means it takes a 2-byte space in memory) 

 

2. character type:- for this we use the char keyword, its size is 1 byte. 

 

3.float type:-  for this we use the float keyword it holds the point value such as 10.5, 20.25, 50.687, etc. It takes a space of 4 bytes.  

 

4.double type:- it is the same as float, it also holds the point/fractions value, but the difference is it takes a space of 8 bytes in memory. For this, we use a double keyword.  

 

5.void type :- we use void in function, it is an empty datatype so we can't it's it for making variables. If a program or function is empty (doesn’t show any value) we use void data type. 

 

We can use a modifier to change the size, length, and range of data type. We have 2 types of modifier,  

  1. 1) Signed modifier:- it changes the value of the datatype. It is used for char and int. 

    1. Signed:- store positive and negative value.  

    Int a; 

     Signed int a; 

    Signed char ch; 

      

    1. Unsigned:- store only positive value. 

    Unsigned char ch; 

    Unsigned int b;  

     

  2. 2) Sized modifier:- it changes the size of the data type. we can use this for int, double, But can't use it for char, float.  let's be clear with the given example:- 


    1. Short  

    Int a; ----> it take 2 byte  

    Short int a; -----> it take 2 byte 


    1. Long  

    Long int a; ------> it take 4 byte   

    Long double b; -----> it take 10 byte.  



0 Comments