CSC 126 Chapter 2 PART 1
CSC 126 Chapter 2 PART 1
• For example
• NUM1, num1, Num1 are three different identifiers.
More examples:
VALID INVALID REASON INVALID
data_type variable_name;
int nombor;
VARIABLE
int num; reserving a memory location called num to
hold an integer value
float value; reserving a memory location called value to
hold a floating-point number
double total; reserving a memory location called total to
hold a double-precision number
char grade; reserving a memory location called grade to
hold a character
char name[20]; reserving a memory location called name to
hold 20 characters
long datnum; reserving a memory location datnum to hold a
long integer
VARIABLE
VARIABLE DECLARATION
• Another example to assign values to the variable num1, num2 and sum with the initial
10, 20, 0 respectively, the C++ statement can be written as:
int num1 = 10, num2 = 20, total = 0;