Page 9 - Touchcode_C7_Flipbook
P. 9
1 VARIABLES IN REAL LIFE
Learning Outcomes
Introduction What is Variable Initialization?
Data Types in Programming How do we Validate User Input in Programming?
Math Operations in Programming
INTRODUCTION
In your previous class, you had learned that a variable is a packet to store data which can
be named, referenced. In this class, you are going to learn more about variables and how
they are used in a program.
WHAT IS VARIABLE INITIALIZATION?
To use variables in programming, first we need to create
the variables and assign them a reference in the computer
memory.
Variable is a storage area which the programs can
manipulate by changing the values stored in it.
Create/declare a variable
Syntax is a rule which must be followed while performing a task.
In most of the programming languages, you can declare a variable by using the following syntax:
Datatype VariableName=Value;
Example 1: Declaring a variable. Subject Enrichment
int x=20;
int y=30;
int x, int y will create two variables ‘x’ and ‘y’ and it reserve two memory locations with names
‘x’ and ‘y’. Variables are created by using the ‘int’ keyword. ‘int’ specify the data type which
means that the declared variable will store integer values ‘20’ and ‘30’ in these two variables.
Once the variable is created, you need to assign it a value before using it. This process of
assigning a value to a variable is called initialization.
Variables in Real Life 7

