Home > Articles > Programming > C/C++

  • Print
  • + Share This
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.

  • + Share This
  • 🔖 Save To Your Account