␡
- What Is a Variable?
- Defining a Variable
- Creating More Than One Variable at a Time
- Assigning Values to Your Variables
- typedef
- When to Use short and When to Use long
- Characters
- Constants
- Enumerated Constants
- Summary
- Q&A
- Workshop
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 int area, width, length; // three long integers
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.