Data Types in C

Data Types in C are used to specify the type of value that a variable can store for example integer, character, floating numbers, etc.

  • We use variables to reserve memory block/location in computer’s memory.
  • We store value in those reserve memory block/location.
  • The value can be different type as well as different size.
  • Data Types defines the type of value that can be stored in reserve block/location.
  • The size of reserve space is also depends on Data Type, for example char reserve 1 byte and int reserve 2 byte space.

Types of Data Types in C

Based on type of value and size Data Types in C are categorized in 3 broad categories.

  1. Primary Data Types or Fundamental Data Types.
  2. Derived Data Types.
  3. User-Defined Data Types.

Let’s understand, what are these three categories of C data types? the scenario where we can use them in our C programs.

1. Primary / Fundamental Data Types in C

There are 5 fundamental data types in C language.

  1. Integer (int)
  2. Character (char)
  3. Floating point (float)
  4. Double precision floating point (double)
  5. Void (void)

Note - In below table we have listed all primary datatype with their representation, size, and value range. We use representation in C programing.

Data Type Name Representation Size (64 bit OS) Value Range
Integer int 4 byte -32768 to 32767
Character char 1 byte -128 to 127
floating point float 4 byte 3.4e-38 to 3.4e+e39
double precision floating point double 8 byte 1.7e – 308 to 1.7e+308
Void void -- none

Note : Fundamental data type are also offers extended data types for example long int, short int, long double etc. Complete knowledge about extended data types is very important for best utilization of storage memory.

a. Integer Type (int)

  • In C programming, Integers are used to represent whole numbers within a fix range of values.
  • Commonly inter reserve one word of storage.
  • A word size can vary from machine to machine for example some computer uses 16 bit size to store a word and some uses 32 bit size to store a word.
  • If we use 16 bit word length then the value range will be -32768 to +32767
  • If we use 32 bit word length then the value range will be -2,147,483,648 to +2,147,483,647

Use of int data type -

You can declaration and also assign the value of variable together or you can declare variable first and assign value later.

Integer type can be extended in 6 types, listed below in table.

Signed Type Unsigned Type
int unsigned int
short int unshined short int
long int unsigned long int

Note: Read more about int data type

b. Character (char)

Character (char) are used to define a single character.

  • To store a character it requires 8 bit of storage space.
  • There are two extended forms of char data type that are signed char and unsigned char.
  • unsigned char have value between 0 and 255.
  • signed char have value between -128 to 127.

Use of char data type -

Note: Read more about char data type

c. Floating Point (float)

Floating point ( float ) are used to define real numbers and stored in 32 bits with 6 digits of precision in both kind of i.e. 16 bit and 32 bit machines. Keyword float is used to define floating point number in C programming.

  • Floating point number is not a complete number for example 3.4, 453.453, .000372 etc.
  • To define complete number we use int data type.
  • To define incomplete numbers we use float data type.

Use of float data type:

Note: Read more about float data type

d. Double

Data type double is also used to define floating point number. In such condition where the 6 digits precision of float is not sufficient then we can use double it store real number in 64 bits with 14 digits of precision.

  • If double data type precision is not enough then we can use long double data type.
  • long double data type is an extended data type of double
  • Long double data type is used to define real number and stored in 80 bits with 19 digits of precision.
  • We use long double data type where we needs very higher accuracy in value.

Use of double data type:

Note - Read more about double data type

e. Void (void)

The void data type has no values. Basically void is used to define the type of function. If we are using a function type of void then that function will not return anything.

Use of void data type:

Data Type, Size and Range Value

Data Type Size in Bits Value Range
int or signed int 16 -32768 to 32767
unsigned int 16 0 to 65535
short int or signed short int 8 -128 to 127
unsigned short int 8 0 to 255
long int or signed long int 32 -2,147,483,648 to 2,147,483,647
unsigned long int 32 0 to 4,294,967,295
char or signed char 8 -128 to 127
unsigned char 8 0 to 255
float 32 3.4E-38 to 3.4E+38
double 64 1.7E-308 to 1.7E+308
long double 80 3.4E-4932 to 1.1E+4932

2. Derived Data Types

The data type which is derived from fundamental data type is called derived data type. There are three types of derived data types.

  • Function
  • Array
  • Pointer

Note: You will learn all above derived data types in very details in upcoming chapters.

3. User Defined Data Types

The data type which is defined by the user is called a user-defined datatype for example structure, union, and enumeration.

C Language have a special feature “ type definition “ which allows user to define an identifier which can represent an existing data type. This user defined identifier later can be used to declare variables. To define user defined data type, see below examples.

Syntax & Example

Syntax: typedef type identifier;
Example: typedef int counts;

In C programming, structure, union and enumeration widely used to create user define data type. See how to define user defined data type using struct, union and enum keywords.

Structure Example

struct student
  {
     char name[50];
     int roll_number;
     float marks;
  }

See the syntax and example of defining emum

Syntax & Example

Syntax: enum identifier { value1, value2,...valuen};
Example: enum month { jan, feb,...., dec};

Note: Later we will discus all user defined data type in depth and also we will learn the best use of user defined data types

Email Us: advertise@gdatamart.com

Donate Us: Support to GDATAMART

© 2023 GDATAMART.COM (All Rights Reserved)