In our examples, we frequently simplify variable names to reflect their data type (e.g., myInt or myNum for integers, myChar for characters, etc.).
This simplification is employed to prevent confusion.
For a practical demonstration of variable usage, consider the following program.
It stores various data related to a college student:
// Student data int studentID = 15; int studentAge = 23; float studentFee = 75.25; char studentGrade = ‘B’; // Print variables |
In this practical example, we develop a program to compute the area of a rectangle by multiplying its length and width:
// Create integer variables int length = 4; int width = 6; int area; // Calculate the area of a rectangle // Print the variables |