Skip to main content

5. Data Types in C

 

Data Types in C

A data type specifies the type of data that a variable can store such as integer, floating, character, etc.
There are the following data types in C language.

TypesData Types
Basic Data Typeint, char, float, double
Derived Data
Type
array, pointer,
structure, union
Enumeration
Data Type
enum
Void Data Typevoid

The basic data types are integer-based and floating-point based.The memory size of the basic data types may change according to 32 or 64-bit operating system.
C has a built-in sizeof operator that gives the memory requirements for a particular data type.

Program for displaying the size of various data types

#include <stdio.h>

int main()
{
   printf("int : %ld bytes\n", sizeof(int));
   printf("float : %ld bytes\n", sizeof(float));
   printf("double : %ld bytes\n", sizeof(double));
   printf("char : %ld bytes\n", sizeof(char));
   return 0;
}

Output according to 64-bit architecture :

int : 4 bytes
float : 4 bytes
double : 8 bytes
char : 1 bytes

Output according to 32-bit architecture :

int : 2 bytes
float : 4 bytes
double : 8 bytes
char : 1 bytes

The program output displays the corresponding size in bytes for each data type.

Comments