Professional Documents
Culture Documents
Constants
Identifiers are:
Variable
Constant
others
Example: int x;
int entry_time, charge;
•Escape Character
char thiIsTab;
thisIsTab=‘/t‘;
example of declarations
float CGPA;
double diameter;
Example 2:
float matric;
matric is a ??? variable
Example:
Calculate and display the price of a number of apples if
the quantity in kg and price per kg are given.
Example:
int quantity; Why do we
declare it as int?
float price_per_kg;
float price;
Why do we
declare them as
float?
TMK 3102-Chap 5: Variables & 18
Constant
Variable - Value Assignment
Example:
int number1, number2;
number1 = 25;
number1 25
23
?
number2 = 23;
number1 = number2; number2 23
?
…
…
TMK 3102-Chap 5: Variables & 19
Constant
Variable - Value Assignment
Example:
int quantity;
float price_per_kg, price;
quantity = 2;
price_per_kg = 4.50;
price = quantity * price_per_kg;
…
TMK 3102-Chap 5: Variables & 20
Constant
Variable - Value Assignment
Example:
int quantity; quantity 2?
float price_per_kg, price; price_per_kg 4.50
?
price 9.00
?
quantity = 2;
price_per_kg = 4.50;
price = quantity * price_per_kg;
…
TMK 3102-Chap 5: Variables & 21
Constant
Variable - Value Assignment
int x = 1;
double d = 25.4;
char b = ‘b’;
int number1 = x;
Is this statement
correct???
byte byteVar;
int intVar = 129;
byteVar = intVar;