Declaring variables
All applications process data. Data comes in, data is processed, and data goes out.
Data usually comes into our program from files, databases, or user input. Data can be put temporarily in variables that will be stored in the memory of the running program. When the program ends, the data in memory is lost. Data is usually output to files and databases, or to the screen or a printer.
When using variables, you should think about, first, how much space it takes in memory, and, second, how fast it can be processed.
We control this by picking an appropriate type. You can think of simple common types such as int
and double
as being different size storage boxes. A smaller box would take less memory but may not be as fast at being processed. Some of these boxes may be stacked close by, and some may be thrown into a big heap further away.
Naming variables
There are naming conventions for variables, and it is good practice to follow them, as shown in the following table:
Naming convention... |