Variables & Data Types
Programming-I C++ Programing
What is a variable
 Variables are used to store information to be referenced and
manipulated in a computer program.
 They also provide a way of labeling data with a descriptive name, so
our programs can be understood more clearly by the reader and
ourselves.
 It is helpful to think of variables as containers that hold information.
Data Types
Data Type Represents Examples
integer whole numbers -5 , 0 , 123
floating point (real) fractional numbers -87.5 , 0.0 , 3.14159
string A sequence of characters "Hello world!"
Boolean logical true or false true , false
Variables in C++
Memory Cell location
Variables Naming Rules
• Variable name must start with a letter
• May contain letters, numbers and the underscore character
• Emaple – Salary, name3, first_name, LastName
• Bad Example – 3name, first name
Variables Naming Rules
• No real limit to the length of variable name but that are too short
are’nt meaningful and variables that are too long aren’t practical
Practice Programms
1. Program that calculates the square of a number
2. Program to find your Day of Birth given Date of Birth
3. Area of a rectangle
4. Area of a circle
5. Find the speed of a car in a given distance and time

Variables & Data Types.pptx

  • 1.
    Variables & DataTypes Programming-I C++ Programing
  • 2.
    What is avariable  Variables are used to store information to be referenced and manipulated in a computer program.  They also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves.  It is helpful to think of variables as containers that hold information.
  • 3.
    Data Types Data TypeRepresents Examples integer whole numbers -5 , 0 , 123 floating point (real) fractional numbers -87.5 , 0.0 , 3.14159 string A sequence of characters "Hello world!" Boolean logical true or false true , false
  • 5.
  • 6.
  • 7.
    Variables Naming Rules •Variable name must start with a letter • May contain letters, numbers and the underscore character • Emaple – Salary, name3, first_name, LastName • Bad Example – 3name, first name
  • 8.
    Variables Naming Rules •No real limit to the length of variable name but that are too short are’nt meaningful and variables that are too long aren’t practical
  • 9.
    Practice Programms 1. Programthat calculates the square of a number 2. Program to find your Day of Birth given Date of Birth 3. Area of a rectangle 4. Area of a circle 5. Find the speed of a car in a given distance and time