- What is a Variable?
- Defining a Variable
- Creating More Than One Variable at a Time
- Assigning Values to Your Variables
- When to Use short and When to Use long
- Enumerated Constants
This chapter is from the book
Creating More Than One Variable at a Time
You can create more than one variable of the same type in one statement by writing the type and then the variable names, separated by commas. For example:
unsigned int myAge, myWeight; // two unsigned int variables long area, width, length; // three longs
As you can see, myAge and myWeight are each declared as unsigned integer variables. The second line declares three individual long variables named area, width, and length. The type (long) is assigned to all the variables, so you cannot mix types in one definition statement.