SlideShare a Scribd company logo
1 of 11
Programming
Variables & Constants
Objectives
• Distinguish between variables and constants
• Understand data types
Variables and Constants
• Results of processing must be stored somewhere in order to
access it later.
• Let’s make lemon juice:
– Squeeze the lemon in a juicer
– Add lemon juice to jug
– Make syrup in a pan
– add water and syrup to jug
– Pour juice in a glass
• Just as we need containers to hold or store ingredients,
likewise we need something to store and hold the values we
manipulate.
Variable
• Variable is a container that stores data. You can refer and
you can modify data in variables at any time during
processing.
• Variable is usually located on RAM.
• You can name variables as you like. Name of variables is called
identifier. Identifier should be clarified so that they are always
meaningful.
Variables
• Variable names:
– Should disclose what it does
– Contain letters, numbers, underscores
– Should start with a letter
– Should not contain any spaces
Data
Assignment
Variable
Reference
Variables
• Example of variable names
• If you want to find the sum to two numbers 5
and 8.
sum
num2
num1
store
Read num1,
num2
Variables
• Example of variable names
• If you want to find the sum to two numbers 5
and 8.
sum
store
reference
store
Variables
num1
num2
Sum ← num1 + num2
Variables
• Example of variable names
• If you want to find the sum to two numbers 5
and 8.
store
store
Variables
num1
num2
sumPrint sum
Constants
• Constant is container with fixed data. Data that does not
change but remains the same during the execution of the
program.
• You can refer the data but you CAN’T modify data in
constant.
• Constant is located on ROM.
• You can name constants as you like. Name of variables is
called identifier. Identifier should be clarified so that they are
always meaningful.
constant
Reference
Constants
• Examples:
Number of days in a week represents a
constant.
PI = 3.1415927
Data Types
• Determines the type of data that a variable can store.
• Data has any of following types :
• Integers: positive and negative whole numbers. e.g. 15, -60, 3
• Floating point or real: positive and negative numbers with decimal
values. e.g. 0.36, 4.6, -9.4
• Characters: anything that you can key in from a key board. This
includes letter, numbers and special characters. e.g. @, k, j, *
• Boolean: data that is either true or false. e.g. whether the light is on or
off
• String: hold groups of characters, like a word or a phrase.

More Related Content

Similar to Variables

CSC111-Chap_02.pdf
CSC111-Chap_02.pdfCSC111-Chap_02.pdf
CSC111-Chap_02.pdf2b75fd3051
 
powerpoint 1-19.pdf
powerpoint 1-19.pdfpowerpoint 1-19.pdf
powerpoint 1-19.pdfJuanPicasso7
 
C Programming Lecture 3 - Elements of C.pptx
C Programming Lecture 3 - Elements of C.pptxC Programming Lecture 3 - Elements of C.pptx
C Programming Lecture 3 - Elements of C.pptxMurali M
 
1. chapter i(pasw)
1. chapter i(pasw)1. chapter i(pasw)
1. chapter i(pasw)Chhom Karath
 
Data types and Attributes1 (1).pptx
Data types and Attributes1 (1).pptxData types and Attributes1 (1).pptx
Data types and Attributes1 (1).pptxRupaRaj6
 
Visual Basic Fundamentals
Visual Basic FundamentalsVisual Basic Fundamentals
Visual Basic FundamentalsDivyaR219113
 
General Programming Concept
General Programming ConceptGeneral Programming Concept
General Programming ConceptHaris Bin Zahid
 
codingtechniques1.ppt
codingtechniques1.pptcodingtechniques1.ppt
codingtechniques1.pptazida3
 
Lecture 4 variables data types and operators
Lecture 4  variables data types and operatorsLecture 4  variables data types and operators
Lecture 4 variables data types and operatorsalvin567
 
Storage in programming
Storage in programmingStorage in programming
Storage in programmingCodewizacademy
 
Versatile Variables
Versatile VariablesVersatile Variables
Versatile Variablestarzan_1644
 
spss_beginners.pptx
spss_beginners.pptxspss_beginners.pptx
spss_beginners.pptxfar_927
 

Similar to Variables (20)

Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
CSC111-Chap_02.pdf
CSC111-Chap_02.pdfCSC111-Chap_02.pdf
CSC111-Chap_02.pdf
 
powerpoint 1-19.pdf
powerpoint 1-19.pdfpowerpoint 1-19.pdf
powerpoint 1-19.pdf
 
C Programming Lecture 3 - Elements of C.pptx
C Programming Lecture 3 - Elements of C.pptxC Programming Lecture 3 - Elements of C.pptx
C Programming Lecture 3 - Elements of C.pptx
 
Csc240 -lecture_4
Csc240  -lecture_4Csc240  -lecture_4
Csc240 -lecture_4
 
1. chapter i(pasw)
1. chapter i(pasw)1. chapter i(pasw)
1. chapter i(pasw)
 
Spss beginners
Spss beginnersSpss beginners
Spss beginners
 
Data types and Attributes1 (1).pptx
Data types and Attributes1 (1).pptxData types and Attributes1 (1).pptx
Data types and Attributes1 (1).pptx
 
Visual Basic Fundamentals
Visual Basic FundamentalsVisual Basic Fundamentals
Visual Basic Fundamentals
 
General Programming Concept
General Programming ConceptGeneral Programming Concept
General Programming Concept
 
codingtechniques1.ppt
codingtechniques1.pptcodingtechniques1.ppt
codingtechniques1.ppt
 
Lecture 4 variables data types and operators
Lecture 4  variables data types and operatorsLecture 4  variables data types and operators
Lecture 4 variables data types and operators
 
Storage in programming
Storage in programmingStorage in programming
Storage in programming
 
C Language Part 1
C Language Part 1C Language Part 1
C Language Part 1
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Versatile Variables
Versatile VariablesVersatile Variables
Versatile Variables
 
spss_beginners.pptx
spss_beginners.pptxspss_beginners.pptx
spss_beginners.pptx
 
Data structure Unit-I Part A
Data structure Unit-I Part AData structure Unit-I Part A
Data structure Unit-I Part A
 
Data structure
Data structureData structure
Data structure
 
12.6-12.9.pptx
12.6-12.9.pptx12.6-12.9.pptx
12.6-12.9.pptx
 

More from ContentAdministrator1 (20)

Algorithms examples
Algorithms examplesAlgorithms examples
Algorithms examples
 
Algorithms Examples
Algorithms ExamplesAlgorithms Examples
Algorithms Examples
 
Chemical Bonding
Chemical BondingChemical Bonding
Chemical Bonding
 
Concentration of Solutions and Volumetric Analysis
Concentration of Solutions and Volumetric AnalysisConcentration of Solutions and Volumetric Analysis
Concentration of Solutions and Volumetric Analysis
 
Elements and Compounds
Elements and CompoundsElements and Compounds
Elements and Compounds
 
Relative Masses of Atoms and Molecules
Relative Masses of Atoms and MoleculesRelative Masses of Atoms and Molecules
Relative Masses of Atoms and Molecules
 
Metals and their Reactivity
Metals and their ReactivityMetals and their Reactivity
Metals and their Reactivity
 
Qualitative Analysis
Qualitative AnalysisQualitative Analysis
Qualitative Analysis
 
Non metals
Non metalsNon metals
Non metals
 
Enthalpy Change
Enthalpy ChangeEnthalpy Change
Enthalpy Change
 
Polymers
PolymersPolymers
Polymers
 
Carbon Compounds
Carbon CompoundsCarbon Compounds
Carbon Compounds
 
Hydrocarbons
HydrocarbonsHydrocarbons
Hydrocarbons
 
Rates of Reactions
Rates of ReactionsRates of Reactions
Rates of Reactions
 
Electrochemistry
ElectrochemistryElectrochemistry
Electrochemistry
 
Acids, Bases and Salts
Acids, Bases and SaltsAcids, Bases and Salts
Acids, Bases and Salts
 
The Mole Moncept
The Mole MonceptThe Mole Moncept
The Mole Moncept
 
Chemical Bonding
Chemical BondingChemical Bonding
Chemical Bonding
 
Periodicity of Elements
Periodicity of ElementsPeriodicity of Elements
Periodicity of Elements
 
Atomic Structure
Atomic StructureAtomic Structure
Atomic Structure
 

Recently uploaded

Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 

Recently uploaded (20)

Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 

Variables

  • 2. Objectives • Distinguish between variables and constants • Understand data types
  • 3. Variables and Constants • Results of processing must be stored somewhere in order to access it later. • Let’s make lemon juice: – Squeeze the lemon in a juicer – Add lemon juice to jug – Make syrup in a pan – add water and syrup to jug – Pour juice in a glass • Just as we need containers to hold or store ingredients, likewise we need something to store and hold the values we manipulate.
  • 4. Variable • Variable is a container that stores data. You can refer and you can modify data in variables at any time during processing. • Variable is usually located on RAM. • You can name variables as you like. Name of variables is called identifier. Identifier should be clarified so that they are always meaningful.
  • 5. Variables • Variable names: – Should disclose what it does – Contain letters, numbers, underscores – Should start with a letter – Should not contain any spaces Data Assignment Variable Reference
  • 6. Variables • Example of variable names • If you want to find the sum to two numbers 5 and 8. sum num2 num1 store Read num1, num2
  • 7. Variables • Example of variable names • If you want to find the sum to two numbers 5 and 8. sum store reference store Variables num1 num2 Sum ← num1 + num2
  • 8. Variables • Example of variable names • If you want to find the sum to two numbers 5 and 8. store store Variables num1 num2 sumPrint sum
  • 9. Constants • Constant is container with fixed data. Data that does not change but remains the same during the execution of the program. • You can refer the data but you CAN’T modify data in constant. • Constant is located on ROM. • You can name constants as you like. Name of variables is called identifier. Identifier should be clarified so that they are always meaningful. constant Reference
  • 10. Constants • Examples: Number of days in a week represents a constant. PI = 3.1415927
  • 11. Data Types • Determines the type of data that a variable can store. • Data has any of following types : • Integers: positive and negative whole numbers. e.g. 15, -60, 3 • Floating point or real: positive and negative numbers with decimal values. e.g. 0.36, 4.6, -9.4 • Characters: anything that you can key in from a key board. This includes letter, numbers and special characters. e.g. @, k, j, * • Boolean: data that is either true or false. e.g. whether the light is on or off • String: hold groups of characters, like a word or a phrase.