What is datatype in C language - Code Is Interest

Datatypes is a data storage format that can contain a specific type or range of values. The kind of data that variables may hold in a programming language are called as data types.

There are three data types in C language. They are,

  • Primary Data Type
  • Enumeration Data Type
  • Derived Data Type

Character Data Type

  • Character data type allows a variable to store only one character.
  • Storage size of character data type is 1. We can store only one character using character data type.
  • “char” keyword is used to refer character data type.
  • Character data type  is a special integer type designed for storing single characters. The integer value of a char corresponds to an ASCII character. E.g., a value of 65 corresponds to the letter A, 66 corresponds to B, 67 to C, and so on.
  • As in the table below, unsigned char permits values from 0 to 255, and signed char permits values from -128 to 127. The char type is signed by default on some computers, but unsigned on others. The sizes of the char types are as follows.

Size and range of Char data type

Type   

Bytes 

Minimal range

char  

1

-128 to 127

unsigned char             

1

0 to 255

signed char                  

1

-128 to 127


Integer Data Type

  • An integer is a whole number (a number without a fractional part). It can be  positive or negative numbers like 1, -2, 3, etc., or zero. The sizes of the integer variables depend on the hardware and operating system of the computer.
  • Integer data type allows a variable to store numeric values.
  • “int” keyword is used to refer integer data type.
  • The storage size of int data type is 2 or 4 or 8 byte.

Size and range of Int data type

Type   

Size(bytes)

Range

int or signed int

4

-32,768 to 32767

unsigned int

4

0 to 65535

short int or signed short int

2

-32768 to 32767

unsigned short int

2

0 to 65535

long int or signed long int

4

-2,147,483,648 to 2,147,483,647

unsigned long int

4

0 to 4,294,967,295


Float Data Type

  • Floating point data type consists of 2 types. They are,
float
double
  • Float data type allows a variable to store decimal values.
  • Storage size of float data type is 4. This also varies depend upon the processor in the CPU as “int” data type.
  • We can use up-to 6 digits after decimal using float data type.
  • For example, 10.456789 can be stored in a variable using float data type.
  • Double data type is also same as float data type which allows up-to 10 digits after decimal.
  • “float” or “double” keyword is used to refer floating data type

Size and range of Float data type

Type   

Size(bytes)

Range

Float

4

3.4E-38 to 3.4E+38

double

8

1.7E-308 to 1.7E+308

long double

10

3.4E-4932 to 1.1E+4932


Void Data Type

  • void type means no value. This is usually used to specify the type of functions which returns nothing. We will get acquainted to this datatype as we start learning more advanced topics in C language, like functions, pointers etc.

Post a Comment

0 Comments