Data types in C

21 September, 2018

Related Blogs

Data types in C language

  • Always data types will decides that what type of data need to be hold in a variable.
  • in ‘c’ programming language, there are 3 type of basic data types are available i.e int,float, char.
  • In implementation whenever the predefined data type is not supporting . User requirement then extend size and range of predefined data types i.e primitive data types are required
  • In ‘c’ programming language, there are ‘9’ types of predefined or primitive data types are available , those are
Type Type Range % Ex
Char 1 byte -128 to 127 %c ‘a’ ‘A’ ‘#’ ‘\n’
Unsigned char 1 byte 0 to 255
Int 2bytes -32,768 to 32767 %d -25 5 0   -5
Unsigned int 2 bytes 0 to 65,535 %u 327684
Longint 4 bytes -2,147,483,648 to+3147,483,647 %ld+51-51 400001
Unsigned long 4 bytes 0 to 4,294,967,295 100lu51lu
Float 4 bytes +or-3.4*10*+or-38 %lu -3.5 7.5f
Double 8 bytes +or- 1.1*10*+or- %f -3.5 7.5
Long double 10 bytes 308+or-3.4*10*+or-9932 %lf%Lf -3.5L 7.5L
  • The basic advantage of classifying this many types nothing but utilizing the memory more efficiently and increasing the performance.
  • In implementation, when we require character operators then recommended to go for unsigned cap data type.
  • In implementation, when we require the numeric values from the range of -128 to 128 then go for char data type in place of constructing an integer, in this case, we require to use %d format specifier
  • When we require the numeric values from the range of 0 to 255 then go for unsigned char data type in place of constructing unsigned integer, in this case we require to use %u format specifier.
  • For normal numeric operation, go for an int type, if there is no any negative representations are available like Employee salary then recommended to go for unsigned int type.
  • Signed , unsigned, short and long are called “Qualifiors”
  • signed, unsigned indicates sign specifications
  • short & long indicates size specifications.
  • This all qualifiers we require to use for an integer data type only. i.e we can’t use for float, double and long double.
  • By default , any type of integral variable type sign is signed type, size is short type.
  • void main()

{ int i; long int l; float f; i=32767+1; l=32767+1; f=32767+1; printf(“%d%ld  %f”,i,l,f); } o/p: 32768                   -32768       -32768.000000    

Arithmetic operations on data types:-

int , int   2  int int, char   2   int signed int, unsigned int   2   signed int signed , unsigned -  2  signed int, long int   2   long int int,float   2   float float, long int   2   float float, double  2  double double, long double   2   long double.
  • if both arguments are same type then return value is same, if both arguments are different then among those two, bigger one will be the return value.
  • When we are working with an integral values with the combination of float, then return value is float type only.
  • void main()

{ int i, long int l; float f; i=32767+1; l=32767l+1;                  // l=(long int) 32767+1; f=32767.0f+1;              // f=(float)32767+1; printf(“%d      %ld    %f  ”,i,l,f); } o/p : -32768       32768        32768.000000      
About Author


Author Bio

TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills .