top of page
Shuchi Vyas

Data Types in C

In this blog you will learn about the data types in C. The previous blog was about the variables and keywords C language, which you can find here.


As we have learned in the last blog, the data type of a variable determines the type of value the variable stores, the amount of memory that is allotted to the variable and the operations that can be performed on the variable. For instance, a variable that is declared as int can only contain integers, and mathematical, relational and logical operations can be easily performed on it; while a variable that is declared as char can store only characters and mathematical operations cannot be performed on it without error.


The data types in C can be broadly classified into two categories - primitive data types and derived data types.

  • Primitive Data Type - The primitive data types are the fundamental data types in C. They form the basis for the more complex data types. Primitive data types can not be broken down into simpler data types. Some examples of primitive data types are int, char and float.

  • Derived Data Types - The derived data types as the name suggests, are derived from the primitive data types. They can be created by grouping together one or more primitive data types. Some of the derived data types are array, struct and union.

The derived data types are used to achieve special requirements. You will learn more about the derived data types in later blogs.


All variables in a program must be declared with a data type as 'datatype var_name;'. For example:

int age;

float x;

char t;


The most common data types are the integer type, the floating point type and the character type. So let's study these in detail.


Integer Type

The integer data types is used to store integers.


Data type Size (bytes) Range

short signed int 2 -32768 to +32767

short unsigned int 2 0 to 65535

int (signed int) 2 -32768 to +32767

unsigned int 2 0 to 65535

long signed int 4 -2147483648 to +2147483647

long unsigned int 4 0 to 4294967295


Floating Point Type

The floating data types are used to store real numbers.


Data 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 1.7E-4932 to 1.7E+4932


Character Type

The character types are used to store character values.


Data type Size (bytes) Range

signed char 1 -128 to +127

unsigned char 1 0 to 255


The short, long, signed and unsigned keywords are that type modifiers that change the meaning of the base data type to give a new type.

Note: These figures are for 16-bit compilers.

 

Happy coding!

Follow us on Instagram @programmersdoor

Join us on Telegram @programmersdoor


Please leave comments if you find any inconsistency in the blog.

Follow Programmers Door for more.


2 views0 comments

Recent Posts

See All

Comentarios


bottom of page