Agenda
What Are Datatypes in C
Basic Datatypes in C
Modifiers in C
Datatypes Classification
User-Defined Datatypes
Derived Datatypes
What Are Datatypes in C
What Are Datatypes in C
General syntax is:
Datatype var1,var2,…,varn;
Datatypes are used to notify the type of value assigned to a variables. Four basic
datatypes in C are as follows:
int, char, float, and double
Data Types Classification
Datatypes Classification
Datatypes
Basic datatypes
Derived datatypes
User-defined datatypes
int
char
float
double
array
Structures
pointers
unions
enum
Basic Datatypes in C
Basic Datatypes in C
For example :
int a, b, sum;
Initialization of int data type
int a =10, b=5;
The variables of type int hold the integer values and occupy 2 bytes of space in memory.
Range
-32768 +32767
Basic Datatypes in C
For example :
char ch, arr;
Initialization of char data type
char ch=‘c’, arr=‘2’;
The variables of type char hold a single ASCII character enclosed within two single quotes
and occupy one bytes of space in memory.
Range
-128 +127
Basic Datatypes in C
Example:
float x, age;
Initialization of float data type
float pi = 3.14;
float age = 2.5;
The variables of type float hold the values with decimal points and occupy four bytes of
memory space.
Range
3.4E-38 3.4E+38
Basic Datatypes in C
For Example:
double a;
Initialization of double datatype
double a = 2.3214526;
The double datatype variables occupy 8 bytes of memory space that holds values with
decimal points.
Range
1.7E-308 1.7E+308
Modifiers in C
Modifiers in C
Modifiers also known as qualifiers are used to modify the basic data types in c
signed
unsigned
short
long
The general syntax of handling modifier is
<modifier> <basic data type> <variable-list>;
For example:
unsigned int a = 345
Size and Format Specifier of Datatypes
Datatype Size in bytes Format specifier
char 1 %c
signed char 1 %c
unsigned char 1 %c
short int or int 2 %hd, %d
unsigned int 2 %u
long int 4 %ld
unsigned long int 4 %lu
Float 4 %f
Double 8 %lf
long double 10 %Lf
Derived Datatypes in C
Derived Datatypes
Array is a homogenous collection of elements of same datatype.
Derived Datatypes
Pointer is a variable that holds the address of another variable
User-Defined Datatypes in C
User-Defined Datatypes
enum is an enumeration data type that holds constant integer values defined by the user.
Syntax:
enum enum_name{const1,const2,…const_n};
Example:
enum furniture{chair, table, bookrack};
User-Defined Datatypes
The structure is a collection of elements having the same or different data types
Syntax:
struct structure_name
{
datatype member_1;
datatype member_2;
datatype member_n;
}
Example:
struct add
{
int a;
float b;
};
User-Defined Datatypes
Union datatype allows holding a collection of different data types in the same memory location.
Syntax:
union union_name
{
datatype member_1;
datatype member_2;
datatype member_n;
}
Example:
union sample
{
int age;
float year;
};
Data Types In C

Data Types In C

  • 2.
    Agenda What Are Datatypesin C Basic Datatypes in C Modifiers in C Datatypes Classification User-Defined Datatypes Derived Datatypes
  • 3.
  • 4.
    What Are Datatypesin C General syntax is: Datatype var1,var2,…,varn; Datatypes are used to notify the type of value assigned to a variables. Four basic datatypes in C are as follows: int, char, float, and double
  • 5.
  • 6.
    Datatypes Classification Datatypes Basic datatypes Deriveddatatypes User-defined datatypes int char float double array Structures pointers unions enum
  • 7.
  • 8.
    Basic Datatypes inC For example : int a, b, sum; Initialization of int data type int a =10, b=5; The variables of type int hold the integer values and occupy 2 bytes of space in memory. Range -32768 +32767
  • 9.
    Basic Datatypes inC For example : char ch, arr; Initialization of char data type char ch=‘c’, arr=‘2’; The variables of type char hold a single ASCII character enclosed within two single quotes and occupy one bytes of space in memory. Range -128 +127
  • 10.
    Basic Datatypes inC Example: float x, age; Initialization of float data type float pi = 3.14; float age = 2.5; The variables of type float hold the values with decimal points and occupy four bytes of memory space. Range 3.4E-38 3.4E+38
  • 11.
    Basic Datatypes inC For Example: double a; Initialization of double datatype double a = 2.3214526; The double datatype variables occupy 8 bytes of memory space that holds values with decimal points. Range 1.7E-308 1.7E+308
  • 12.
  • 13.
    Modifiers in C Modifiersalso known as qualifiers are used to modify the basic data types in c signed unsigned short long The general syntax of handling modifier is <modifier> <basic data type> <variable-list>; For example: unsigned int a = 345
  • 14.
    Size and FormatSpecifier of Datatypes Datatype Size in bytes Format specifier char 1 %c signed char 1 %c unsigned char 1 %c short int or int 2 %hd, %d unsigned int 2 %u long int 4 %ld unsigned long int 4 %lu Float 4 %f Double 8 %lf long double 10 %Lf
  • 15.
  • 16.
    Derived Datatypes Array isa homogenous collection of elements of same datatype.
  • 17.
    Derived Datatypes Pointer isa variable that holds the address of another variable
  • 18.
  • 19.
    User-Defined Datatypes enum isan enumeration data type that holds constant integer values defined by the user. Syntax: enum enum_name{const1,const2,…const_n}; Example: enum furniture{chair, table, bookrack};
  • 20.
    User-Defined Datatypes The structureis a collection of elements having the same or different data types Syntax: struct structure_name { datatype member_1; datatype member_2; datatype member_n; } Example: struct add { int a; float b; };
  • 21.
    User-Defined Datatypes Union datatypeallows holding a collection of different data types in the same memory location. Syntax: union union_name { datatype member_1; datatype member_2; datatype member_n; } Example: union sample { int age; float year; };