- It is location in memory (RAM) to temporary store a value during execution of Program / Software.
- As the name suggests, the value of variable can change during execution of program.
- A variable is made of 3 things.
- Name
- Value (optional)
DataType :
- It means what type of value we can store in the variable.
- Numbers such 123, 10.50 etc
- Strings such as UK, Canada etc
- Data such 11/4/2020
Name :
- It identifies the variable. For example, firstName, lastName, age
- What actual value is stored in variable.
- Integer → Numbers such as 120, 345 etc
- Decimal → Number such as 3.5, 4.5 etc
- Char → Single character such as A,a,B,z
- Bool → True or False value
- String → More than one characters value such as John Smith, Mark Smith, Canada , Landon etc.
DataType variableName = value;
Naming Rules :
一 Names may consists of letters (A-Z or a-z), digits and underscores
- e.g firstName, firstNumber, _Age, firstNumber1 (correct)
- #FirstName, @Email (wrong)
- e.g. firstName or _firstName (correct)
- 1stName or 2ndNumber (wrong)
- e.g. first Name (wrong)
- firstName (correct)
Naming Conventions :
ー Names must be meaningful
- e.g. firstNameString, cnicString, studentldlnteger (correct)
- a,b, obj1 (wrong)
- e.g. firstNameString, cnicString, studentldlnteger (correct)
- FirstName, firstname, CNIC or Studentld (wrong)
- e.g. firstNameString, cnicString, studentldinteger (correct)
- FirstName, firstname, CNIC or StudentId (wrong)