• USA : +1 973 910 5725
  • INDIA: +91 905 291 3388
  • info@tekslate.com
  • Login

Data types in C

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

 

 

TypeTypeRange%Ex
Char1 byte-128 to 127%c‘a’ ‘A’ ‘#’ ‘\n’
Unsigned char1 byte0 to 255
Int2bytes-32,768 to 32767%d-25 5 0   -5
Unsigned int2 bytes0 to 65,535%u327684
Longint4 bytes-2,147,483,648 to+3147,483,647%ld+51-51400001
Unsigned long4 bytes0 to 4,294,967,295100lu51lu
Float4 bytes+or-3.4*10*+or-38%lu-3.5 7.5f
Double8 bytes+or- 1.1*10*+or-%f-3.5 7.5
Long double10 bytes308+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.

 

 

4

 

 

  • 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

 

 

 

Summary
Review Date
Reviewed Item
Data types in C
Author Rating
5

“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at info@tekslate.com, we will update the article in 24 hours.”

0 Responses on Data types in C"

    Leave a Message

    Your email address will not be published. Required fields are marked *

    Site Disclaimer, Copyright © 2016 - All Rights Reserved.

    Support


    Please leave a message and we'll get back to you soon.

    I agree to be contacted via e-mail.