SlideShare a Scribd company logo
Data Types in C
In C programming,
Data types are declarations for variables.
Variables on the other hand are memory allocations in a programming language.
Example :
int age;
Here, age is a variable of int (integer) type.
The size of int is 4 bytes.
Basic Data types in C
Type Size (bytes) Format Specifier
int 2 %d , %i
char 1 %c
float 4 %f
double 8 %lf
short int 2 %hd
unsigned int 2 %u
long int 4 %ld , %li
Long long int Atleast 8 %lld, %lli
Basic Data types in C
Type Size (bytes) Format Specifier
Unsigned long int Atleast 4 %lu
Unsigned long long int Atleast 8 %llu
Signed char 1 %c
Unsigned char 1 %c
Long double Atleast 10 %Lf
1. int

Integers are whole numbers that can have both zero, positive and negative values but
no decimal values.
For example, 0, -5, 10.

The size of int is usually 4 bytes (32 bits).

We can use int for declaring an integer variable.
e.g. “ int id; ”

Here, id is a variable of type integer.
NB : You can declare multiple variables at once in C programming.
For example;
“ int id, age; ”
2. float and double

float and double are used to hold real numbers.
For example ;
float salary;
double price;
NB : In C, floating-point numbers can also be represented in exponential.
For example,
float normalizationFactor = 22.442e2;
 Question:
What's the difference between float and double?
 The size of float (single precision float data type) is 4 bytes.
 And the size of double (double precision float data type) is 8 bytes.
3. char

Keyword char is used for declaring character type
variables.
For example,
char test = 'h';

The size of the character variable is 1 byte.
4. void

void is an incomplete type.

It means "nothing" or "no type". You can think of void as
absent.

For example,
if a function is not returning anything, its return type
should be void.

Note that, you cannot create variables of void type.
5. short and long

If you need to use a large number, you can use a type specifier long.
Here's how:
long a;
long long b;
long double c;

Here variables a and b can store integer values. And, c can store a floating-point number.

If you are sure, only a small integer ([−32,767, +32,767] range) will be used, you can use
short.
Here’s how:
short d;
HOW TO CHECK THE SIZE OF A VARIABLE

You can always check the size of a variable using the sizeof() operator.
#include <stdio.h>
int main() {
short a;
long b;
long long c;
long double d;
printf("size of short = %d bytesn", sizeof(a));
printf("size of long = %d bytesn", sizeof(b));
printf("size of long long = %d bytesn", sizeof(c));
printf("size of long double= %d bytesn", sizeof(d));
return 0;
}
Resources for more Learning
Data Types in C Programming
DataTypes In C | What Are DataTypes In C and Their Types | C Programming for Be
ginners

More Related Content

Similar to Structured Programming with C - Data Types.ppt (20)

DOC
Data type
Isha Aggarwal
 
PPTX
Module 1:Introduction
nikshaikh786
 
PPTX
PPS_unit_2_gtu_sem_2_year_2023_GTUU.pptx
ZwecklosSe
 
PDF
variablesfinal-170820055428 data type results
atifmugheesv
 
PPTX
Variables in C++, data types in c++
Neeru Mittal
 
PPTX
A Closer Look at Data Types, Variables and Expressions
Inan Mashrur
 
PPTX
C Programming Language Step by Step Part 3
Rumman Ansari
 
PPTX
2. Variables and Data Types in C++ proramming.pptx
Ahmad177077
 
PPTX
What are variables and keywords in c++
Abdul Hafeez
 
PDF
Constants Variables Datatypes by Mrs. Sowmya Jyothi
SowmyaJyothi3
 
PPTX
Constant, variables, data types
Pratik Devmurari
 
PDF
C Programming Assignment
Vijayananda Mohire
 
PPTX
datatypes-200723165518 (1).pptx
NaniBhai3
 
PPTX
Data types slides by Faixan
ٖFaiXy :)
 
PPTX
Topic-5_-Programming-Fundamentals-Part-2.pptx
HaroldOmega1
 
PPTX
basic C PROGRAMMING for first years .pptx
divyasindhu040
 
PPTX
2. introduction of a c program
Alamgir Hossain
 
PDF
POLITEKNIK MALAYSIA
Aiman Hud
 
PPTX
Lesson 4 Basic Programming Constructs.pptx
John Burca
 
PDF
Zaridah lecture2
Aziz Sahat
 
Data type
Isha Aggarwal
 
Module 1:Introduction
nikshaikh786
 
PPS_unit_2_gtu_sem_2_year_2023_GTUU.pptx
ZwecklosSe
 
variablesfinal-170820055428 data type results
atifmugheesv
 
Variables in C++, data types in c++
Neeru Mittal
 
A Closer Look at Data Types, Variables and Expressions
Inan Mashrur
 
C Programming Language Step by Step Part 3
Rumman Ansari
 
2. Variables and Data Types in C++ proramming.pptx
Ahmad177077
 
What are variables and keywords in c++
Abdul Hafeez
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
SowmyaJyothi3
 
Constant, variables, data types
Pratik Devmurari
 
C Programming Assignment
Vijayananda Mohire
 
datatypes-200723165518 (1).pptx
NaniBhai3
 
Data types slides by Faixan
ٖFaiXy :)
 
Topic-5_-Programming-Fundamentals-Part-2.pptx
HaroldOmega1
 
basic C PROGRAMMING for first years .pptx
divyasindhu040
 
2. introduction of a c program
Alamgir Hossain
 
POLITEKNIK MALAYSIA
Aiman Hud
 
Lesson 4 Basic Programming Constructs.pptx
John Burca
 
Zaridah lecture2
Aziz Sahat
 

Recently uploaded (20)

PDF
DIGESTION OF CARBOHYDRATES ,PROTEINS AND LIPIDS
raviralanaresh2
 
PDF
Genomics Proteomics and Vaccines 1st Edition Guido Grandi (Editor)
kboqcyuw976
 
PPTX
How to Configure Taxes in Company Currency in Odoo 18 Accounting
Celine George
 
PPTX
Urban Hierarchy and Service Provisions.pptx
Islamic University of Bangladesh
 
PPTX
Comparing Translational and Rotational Motion.pptx
AngeliqueTolentinoDe
 
DOCX
Lesson 1 - Nature and Inquiry of Research
marvinnbustamante1
 
PDF
Cooperative wireless communications 1st Edition Yan Zhang
jsphyftmkb123
 
PPTX
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
PDF
Nanotechnology and Functional Foods Effective Delivery of Bioactive Ingredien...
rmswlwcxai8321
 
PPTX
Matatag Curriculum English 8-Week 1 Day 1-5.pptx
KirbieJaneGasta1
 
PPTX
PLANNING FOR EMERGENCY AND DISASTER MANAGEMENT ppt.pptx
PRADEEP ABOTHU
 
PDF
Quiz Night Live May 2025 - Intra Pragya Online General Quiz
Pragya - UEM Kolkata Quiz Club
 
PDF
Rapid Mathematics Assessment Score sheet for all Grade levels
DessaCletSantos
 
PDF
COM and NET Component Services 1st Edition Juval Löwy
kboqcyuw976
 
PDF
Learning Styles Inventory for Senior High School Students
Thelma Villaflores
 
PPTX
The Gift of the Magi by O Henry-A Story of True Love, Sacrifice, and Selfless...
Beena E S
 
PPTX
How Physics Enhances Our Quality of Life.pptx
AngeliqueTolentinoDe
 
PDF
Lesson 1 - Nature of Inquiry and Research.pdf
marvinnbustamante1
 
PPTX
Practice Gardens and Polytechnic Education: Utilizing Nature in 1950s’ Hu...
Lajos Somogyvári
 
PDF
Free eBook ~100 Common English Proverbs (ebook) pdf.pdf
OH TEIK BIN
 
DIGESTION OF CARBOHYDRATES ,PROTEINS AND LIPIDS
raviralanaresh2
 
Genomics Proteomics and Vaccines 1st Edition Guido Grandi (Editor)
kboqcyuw976
 
How to Configure Taxes in Company Currency in Odoo 18 Accounting
Celine George
 
Urban Hierarchy and Service Provisions.pptx
Islamic University of Bangladesh
 
Comparing Translational and Rotational Motion.pptx
AngeliqueTolentinoDe
 
Lesson 1 - Nature and Inquiry of Research
marvinnbustamante1
 
Cooperative wireless communications 1st Edition Yan Zhang
jsphyftmkb123
 
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
Nanotechnology and Functional Foods Effective Delivery of Bioactive Ingredien...
rmswlwcxai8321
 
Matatag Curriculum English 8-Week 1 Day 1-5.pptx
KirbieJaneGasta1
 
PLANNING FOR EMERGENCY AND DISASTER MANAGEMENT ppt.pptx
PRADEEP ABOTHU
 
Quiz Night Live May 2025 - Intra Pragya Online General Quiz
Pragya - UEM Kolkata Quiz Club
 
Rapid Mathematics Assessment Score sheet for all Grade levels
DessaCletSantos
 
COM and NET Component Services 1st Edition Juval Löwy
kboqcyuw976
 
Learning Styles Inventory for Senior High School Students
Thelma Villaflores
 
The Gift of the Magi by O Henry-A Story of True Love, Sacrifice, and Selfless...
Beena E S
 
How Physics Enhances Our Quality of Life.pptx
AngeliqueTolentinoDe
 
Lesson 1 - Nature of Inquiry and Research.pdf
marvinnbustamante1
 
Practice Gardens and Polytechnic Education: Utilizing Nature in 1950s’ Hu...
Lajos Somogyvári
 
Free eBook ~100 Common English Proverbs (ebook) pdf.pdf
OH TEIK BIN
 
Ad

Structured Programming with C - Data Types.ppt

  • 1. Data Types in C In C programming, Data types are declarations for variables. Variables on the other hand are memory allocations in a programming language. Example : int age; Here, age is a variable of int (integer) type. The size of int is 4 bytes.
  • 2. Basic Data types in C Type Size (bytes) Format Specifier int 2 %d , %i char 1 %c float 4 %f double 8 %lf short int 2 %hd unsigned int 2 %u long int 4 %ld , %li Long long int Atleast 8 %lld, %lli
  • 3. Basic Data types in C Type Size (bytes) Format Specifier Unsigned long int Atleast 4 %lu Unsigned long long int Atleast 8 %llu Signed char 1 %c Unsigned char 1 %c Long double Atleast 10 %Lf
  • 4. 1. int  Integers are whole numbers that can have both zero, positive and negative values but no decimal values. For example, 0, -5, 10.  The size of int is usually 4 bytes (32 bits).  We can use int for declaring an integer variable. e.g. “ int id; ”  Here, id is a variable of type integer. NB : You can declare multiple variables at once in C programming. For example; “ int id, age; ”
  • 5. 2. float and double  float and double are used to hold real numbers. For example ; float salary; double price; NB : In C, floating-point numbers can also be represented in exponential. For example, float normalizationFactor = 22.442e2;  Question: What's the difference between float and double?  The size of float (single precision float data type) is 4 bytes.  And the size of double (double precision float data type) is 8 bytes.
  • 6. 3. char  Keyword char is used for declaring character type variables. For example, char test = 'h';  The size of the character variable is 1 byte.
  • 7. 4. void  void is an incomplete type.  It means "nothing" or "no type". You can think of void as absent.  For example, if a function is not returning anything, its return type should be void.  Note that, you cannot create variables of void type.
  • 8. 5. short and long  If you need to use a large number, you can use a type specifier long. Here's how: long a; long long b; long double c;  Here variables a and b can store integer values. And, c can store a floating-point number.  If you are sure, only a small integer ([−32,767, +32,767] range) will be used, you can use short. Here’s how: short d;
  • 9. HOW TO CHECK THE SIZE OF A VARIABLE  You can always check the size of a variable using the sizeof() operator. #include <stdio.h> int main() { short a; long b; long long c; long double d; printf("size of short = %d bytesn", sizeof(a)); printf("size of long = %d bytesn", sizeof(b)); printf("size of long long = %d bytesn", sizeof(c)); printf("size of long double= %d bytesn", sizeof(d)); return 0; }
  • 10. Resources for more Learning Data Types in C Programming DataTypes In C | What Are DataTypes In C and Their Types | C Programming for Be ginners