Data Types in C programming

In this tutorial we will learn about data types of C programming.

data types in c programmin

Data types are sets (ranges) of values that have similar characteristics.

Data Types are charaterized by :

Name – for example, int;
Size (how much memory they use) – for example, 4 bytes;
Default value – for example 0.

Primitive Type

C language supports four pre-defined primitive types – charintfloatvoid

Data type SizeRange
char1 byte-128 to +127
int2 or 4 byte-32,768 to 32,767 or
-2,147,483,648 to +2,147,483,647
float4 byte1.2E-38 to 3.4E+38
void1 byte

Syntax

int variable_name;     // int is used for integer datatypes
float variable_name;    // float is used for integer datatypes
char variable_name;     // char is used for integer datatypes

Derived Type

A derived data type is defined using combination of qualifiers along with the primitive data type.

Qualifiers are optional add-on to the basic data types. They are used to alter the behavior and property of basic data types yielding new type with new property and behavior. Types of qualifier: size and sign.

[qualifier] <basic-data-type>

OR

<basic-data-type> [qualifier]

OR

[sign-qualifier] [size-qualifier] <basic-data-type>


Parts in the square brackets [] are optional and parts in angle bracket < > are mandatory.

Example : 

unsigned short int

How size qualifier alter the behavior

Data TypeDescription
short intDefines min 2 bytes integer
long intDefines a min 4 bytes integer
long doubleDefines a min 12 bytes double precision floating point number

User Defined Type

These data types are custom type created based on our need.

User defined type include array, pointer, structures, unions, enumeration types etc.

For example, let’s define a structure

struct student
 {
  char name[100];
  int roll;
  float marks;
 }

Here,  we can create our own defined data type using structure student:

struct student std;

In above example, student  is uer-defined where std  is variable that hols name, roll and marks of as student.