2.2.1. Variable Definitions


A simple variable definition consists of a type specifier, followed by a list of one or more variable names separated by commas, and ends with a semicolon. Each name in the list has the type defined by the type specifier. A definition may (optionally) provide an initial value for one or more of the names it defines:

int sum = 0, value, // sum, value, and units_sold have type int    units_sold = 0; // sum and units_sold have initial value 0Sales_item item;    // item has type Sales_item (see § 1.5.1 (p. 20))// string is a library type, representing a variable-length sequence of charactersstd::string book("0-201-78345-X"); ...

Get C++ Primer, Fifth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.