SlideShare a Scribd company logo
Variables and Data Types
Session 2
Presented by: Sanjiv Kumar Sharma
Elementary Programming with C/Session 2/ 2 of 22
Objectives
 Discuss variables
 Differentiate between variables and constants
 List the different data types and make use of
them in C programs
 Discuss arithmetic operators
Elementary Programming with C/Session 2/ 3 of 22
Variables
Data
Memory
Each location in the memory is unique
Variables allow to provide a meaningful name for the location in memory
15
Data in memory
15
Elementary Programming with C/Session 2/ 4 of 22
Example
A, B and C are variables in the pseudocode
BEGIN
DISPlAY ‘Enter 2 numbers’
INPUT A, B
C = A + B
DISPLAY C
END
Variable names takes away the need for a programmer to access memory locations
using their address
The operating system takes care of allocating space for the variables
To refer to the value in the memory space, we need to only use the variable name
Elementary Programming with C/Session 2/ 5 of 22
 The names of variables, functions, labels, and various other user
defined objects are called identifiers
 Some correct identifier names
 arena
 s_count
 marks40
 class_one
 Examples of erroneous identifiers
 1sttest
 oh!god
 start... end
 Identifiers can be of any convenient length, but the number of
characters in a variable that are recognized by a compiler varies from
compiler to compiler
 Identifiers in C are case sensitive
Identifier Names
! is invalid
Elementary Programming with C/Session 2/ 6 of 22
Keywords
 Keywords : All languages reserve certain
words for their internal use
 Keywords hold a special meaning within the
context of the particular language
 No problem of conflict as long as the keyword
and the variable name can be distinguished.
For example, having integer as a variable
name is perfectly valid even though it
contains the keyword int
Elementary Programming with C/Session 2/ 7 of 22
Elementary Programming with C/Session 2/ 8 of 22
void
char
double
Basic Data Types
The basic data types are
float
int
Elementary Programming with C/Session 2/ 9 of 22
Type float
 Stores values containing decimal places
float num;
 Precision of upto 6 digits
 32 bits (4 bytes) of memory
 Examples: 23.05, 56.5, 32
Elementary Programming with C/Session 2/ 10 of 22
Type char
 Stores a single character of information
char gender;
gender='M';
 8 bits (1 byte) of memory
 Examples: ‘a’, ‘m’, ‘$’ ‘%’ , ‘1’, ’5’
Elementary Programming with C/Session 2/ 11 of 22
Type void
 Stores nothing
 Indicates the compiler that there is nothing to
expect
Elementary Programming with C/Session 2/ 12 of 22
Derived Data Types
int
short short int
(Occupies less
memory
space than int)
Derived data type
Basic Data
types
Data type
Modifiers
int
unsigned int
(Permits only
positive numbers)
unsigned
int/double
Long int /longdouble
(Occupies more
space than
int/double)
long
Elementary Programming with C/Session 2/ 13 of 22
long and short Types
 short int occupies 8 bits (1 byte)
 allows numbers in the range -128 to 127
 long int occupies 32 bits (4 bytes)
 2,147,483,647 and 2,147,483,647
 long double occupies 128 bits (16 bytes)
Elementary Programming with C/Session 2/ 14 of 22
Data Types and their
range-2
Type Approximate
Size in Bits
Minimal Range
signed short int 8 Same as short int
signed short int 8 Same as short int
long int 32 -2,147,483,647 to 2,147,483,647
signed long int 32 0 to 4,294,967,295
unsigned long int 32 0 to 4,294,967,295
float 32 Six digits of precision
double 64 Ten digits of precision
long double 128 Ten digits of precision
Thank You
Elementary Programming with C/Session 2/ 15 of 22

More Related Content

PPTX
C programming Tutorial Session 2
PPTX
COM1407: Variables and Data Types
PPTX
Data Type in C Programming
PPTX
Lecture 2
PPTX
Module 1:Introduction
PPTX
C PROGRAMMING LANGUAGE
PPTX
Lec 02 Introduction to C Programming.pptx
PPTX
structured Programming Unit-2-Basic-Elements-of-C.pptx
C programming Tutorial Session 2
COM1407: Variables and Data Types
Data Type in C Programming
Lecture 2
Module 1:Introduction
C PROGRAMMING LANGUAGE
Lec 02 Introduction to C Programming.pptx
structured Programming Unit-2-Basic-Elements-of-C.pptx

Similar to work.ppt it describes about programming fundamentals (20)

PDF
C programming_MSBTE_Diploma_Pranoti Doke
PPT
Data Handling
PPT
5-Lec - Datatypes.ppt
PPTX
C Programming Lecture 3 - Elements of C.pptx
PDF
Mit6 087 iap10_lec02
PPTX
PPS_unit_2_gtu_sem_2_year_2023_GTUU.pptx
PPT
C++ data types
PPTX
data types in C programming
PDF
cassignmentii-170424105623.pdf
PPTX
Lecture 02 Programming C for Beginners 001
PPTX
Variables and Datatypes : Building Blocks of Programming
DOCX
c++ best code.docxhsdsdcvcdcdvdvdvdvdcdv
ODP
CProgrammingTutorial
PDF
array 2 (1)_merged.pdf
PPT
CHAPTER-2.ppt
PPTX
2. Variables and Data Types in C++ proramming.pptx
PDF
Scope, binding, papameter passing techniques
PPTX
TAPASH kumar das its my college pptasjhk
DOCX
PPSX
Programming in C [Module One]
C programming_MSBTE_Diploma_Pranoti Doke
Data Handling
5-Lec - Datatypes.ppt
C Programming Lecture 3 - Elements of C.pptx
Mit6 087 iap10_lec02
PPS_unit_2_gtu_sem_2_year_2023_GTUU.pptx
C++ data types
data types in C programming
cassignmentii-170424105623.pdf
Lecture 02 Programming C for Beginners 001
Variables and Datatypes : Building Blocks of Programming
c++ best code.docxhsdsdcvcdcdvdvdvdvdcdv
CProgrammingTutorial
array 2 (1)_merged.pdf
CHAPTER-2.ppt
2. Variables and Data Types in C++ proramming.pptx
Scope, binding, papameter passing techniques
TAPASH kumar das its my college pptasjhk
Programming in C [Module One]
Ad

Recently uploaded (20)

PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Machine learning based COVID-19 study performance prediction
PPT
Teaching material agriculture food technology
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Empathic Computing: Creating Shared Understanding
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Unlocking AI with Model Context Protocol (MCP)
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Spectral efficient network and resource selection model in 5G networks
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Spectroscopy.pptx food analysis technology
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Building Integrated photovoltaic BIPV_UPV.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Machine learning based COVID-19 study performance prediction
Teaching material agriculture food technology
Chapter 3 Spatial Domain Image Processing.pdf
Review of recent advances in non-invasive hemoglobin estimation
MYSQL Presentation for SQL database connectivity
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Empathic Computing: Creating Shared Understanding
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Reach Out and Touch Someone: Haptics and Empathic Computing
The AUB Centre for AI in Media Proposal.docx
Unlocking AI with Model Context Protocol (MCP)
“AI and Expert System Decision Support & Business Intelligence Systems”
Spectral efficient network and resource selection model in 5G networks
Ad

work.ppt it describes about programming fundamentals

  • 1. Variables and Data Types Session 2 Presented by: Sanjiv Kumar Sharma
  • 2. Elementary Programming with C/Session 2/ 2 of 22 Objectives  Discuss variables  Differentiate between variables and constants  List the different data types and make use of them in C programs  Discuss arithmetic operators
  • 3. Elementary Programming with C/Session 2/ 3 of 22 Variables Data Memory Each location in the memory is unique Variables allow to provide a meaningful name for the location in memory 15 Data in memory 15
  • 4. Elementary Programming with C/Session 2/ 4 of 22 Example A, B and C are variables in the pseudocode BEGIN DISPlAY ‘Enter 2 numbers’ INPUT A, B C = A + B DISPLAY C END Variable names takes away the need for a programmer to access memory locations using their address The operating system takes care of allocating space for the variables To refer to the value in the memory space, we need to only use the variable name
  • 5. Elementary Programming with C/Session 2/ 5 of 22  The names of variables, functions, labels, and various other user defined objects are called identifiers  Some correct identifier names  arena  s_count  marks40  class_one  Examples of erroneous identifiers  1sttest  oh!god  start... end  Identifiers can be of any convenient length, but the number of characters in a variable that are recognized by a compiler varies from compiler to compiler  Identifiers in C are case sensitive Identifier Names ! is invalid
  • 6. Elementary Programming with C/Session 2/ 6 of 22 Keywords  Keywords : All languages reserve certain words for their internal use  Keywords hold a special meaning within the context of the particular language  No problem of conflict as long as the keyword and the variable name can be distinguished. For example, having integer as a variable name is perfectly valid even though it contains the keyword int
  • 7. Elementary Programming with C/Session 2/ 7 of 22
  • 8. Elementary Programming with C/Session 2/ 8 of 22 void char double Basic Data Types The basic data types are float int
  • 9. Elementary Programming with C/Session 2/ 9 of 22 Type float  Stores values containing decimal places float num;  Precision of upto 6 digits  32 bits (4 bytes) of memory  Examples: 23.05, 56.5, 32
  • 10. Elementary Programming with C/Session 2/ 10 of 22 Type char  Stores a single character of information char gender; gender='M';  8 bits (1 byte) of memory  Examples: ‘a’, ‘m’, ‘$’ ‘%’ , ‘1’, ’5’
  • 11. Elementary Programming with C/Session 2/ 11 of 22 Type void  Stores nothing  Indicates the compiler that there is nothing to expect
  • 12. Elementary Programming with C/Session 2/ 12 of 22 Derived Data Types int short short int (Occupies less memory space than int) Derived data type Basic Data types Data type Modifiers int unsigned int (Permits only positive numbers) unsigned int/double Long int /longdouble (Occupies more space than int/double) long
  • 13. Elementary Programming with C/Session 2/ 13 of 22 long and short Types  short int occupies 8 bits (1 byte)  allows numbers in the range -128 to 127  long int occupies 32 bits (4 bytes)  2,147,483,647 and 2,147,483,647  long double occupies 128 bits (16 bytes)
  • 14. Elementary Programming with C/Session 2/ 14 of 22 Data Types and their range-2 Type Approximate Size in Bits Minimal Range signed short int 8 Same as short int signed short int 8 Same as short int long int 32 -2,147,483,647 to 2,147,483,647 signed long int 32 0 to 4,294,967,295 unsigned long int 32 0 to 4,294,967,295 float 32 Six digits of precision double 64 Ten digits of precision long double 128 Ten digits of precision
  • 15. Thank You Elementary Programming with C/Session 2/ 15 of 22