This Blog is for New Computer Prgrammers

Saturday, 10 December 2016

Data Types in C - Language

What is Data Type?

There are some predefined keywords in C - Language that defines what kind of data would be stored in a variable, what operations can be applied on this data, how much memory will be occupied, and what will be the value range +ve and -ve to store in variable.

Common Data types in C - Language.
There are three main data types
  • Integral 
  • Floating Point
  • Character
Integral Data types.
  • int 
  • long
Floating Point Data types.
  • float
  • double
Character Data types.
  • char
Attributes of Integral data types.
  • signed
  • unsigned
When we use "unsigned" keyword with data type it blocks the input of -ve numbers and doubles the value range for this variable.

When we use "singed" or don't use this, -ve and +ve both type of values can be stored in the variable.

Integral Data Types in C.

TypeStorage sizeValue range
char1 byte-128 to 127 or 0 to 255
unsigned char1 byte0 to 255
signed char1 byte-128 to 127
int2  bytes-32,768 to 32,767 
unsigned int2  bytes0 to 65,535
short2 bytes-32,768 to 32,767
unsigned short2 bytes0 to 65,535
long4 bytes-2,147,483,648 to 2,147,483,647
unsigned long4 bytes0 to 4,294,967,295
#include <stdio.h>
#include <conio.h>

int main() {

   printf("Storage size for int : %d \n", sizeof(int));
   
   return 0;
}
Here above is a code snippet to check the actual size of any Data type, use have to replace required data type with (int).

Note: in char type we can store any one character using single quots around it.


Floating Point Data Types

TypeStorage sizeValue rangePrecision
float4 byte1.2E-38 to 3.4E+386 decimal places
double8 byte2.3E-308 to 1.7E+30815 decimal places
long double10 byte3.4E-4932 to 1.1E+493219 decimal places
Note: we cannot use "signed" and "unsigned" attributes with Floating Point Type of values.







Share:

2 comments:

Total Pageviews