5 – Data Types

It refers to an extensive system which is use to declare variables or functions of different types.
All Compilers accept the following fundamental Data types to be assigned to the variable:

Types in C

There are different Data types in C.

Sr.NoTypes & Description
1Basic Types
These are arithmetic types & are further classified into:
(a) Integer Types (b) Floating-point Types
2Enumerated Types
These are again arithmetic types & are use to define variables which can only assign certain discrete integer values throughout the program.
3The Type void
It indicates that no value is available.
4Derived Types
These includes:
(a) Pointer Types (b) Array Types (c) Structure Types (d) Union Types & (e) Function Types

The array types and structure types care collectively referred as the aggregate types.

We will study the basic Data Types in the below section, while other parts will be covered in the upcoming chapters.

  • Integer (int)
  • Floating point (float)
  • Character (char)

Integer Types

Integers are whole numbers with a machine independent range of values. C has (3) three classes of integers storage which are named by short, int & long.
The following table provides the detail of with their storage sizes & value ranges.

Integer Typesigned / unsignedNo. of Bytes / Storage SizeRange
intsigned2 or 4 bytes-32,768 to +32,767
intunsigned2 or 4 bytes0 to 65,535
shortsigned2 bytes-32,768 to 32,767
shortunsigned2 bytes0 to 65,535
longsigned8 bytes-9223372036854775808 to 9223372036854775807
longunsigned8 bytes0 to 18446744073709551615

To get the exact size on a particular platform of a type or variable, you can use the sizeof Operator. The expression sizeof(type) provides the storage size of the object or type in bytes.
Given below is an example:

After compiling & executing the above program, it produces the following result on Linux:

Floating Point

Floating Point number represents a real number with 7 digits precision & are denoted by the keyword float. When the accuracy of floating number is insufficient, then we can use the double & long double to define the number.

Floating TypeNo. of bytes / storage sizeRangePrecision
Float4 byte3.4E -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

The following example prints the storage space taken by a float type & its range values:

After compiling & executing the above program, it produces the following result on Linux:

The header file float.h defines macros which allow us to use the values & other details about the binary representation of real numbers in a program.

Void Type

It specifies that no value is available. It is used in three kind of situations.

Sr.NoTypes & Description
1Function return as void
The functions which do not return any value. A function with no return has the return type as void.
For Example: void exit (int status);
2Function arguments as void
These functions do not accept any parameter. A function with no parameter can accept void.
For Example: int rand(void);
3Pointers to void
It represents the address of an object but not its Type.
For Example: A memory allocation function void*malloc( size_t size); return a pointer to void which can be casted to any data type.

subscribe our channels:

Click Here For More Articles:

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.