Variable Declarations

Lines 9–11

int number1 = 0; // first integer to add (initialized to 0)int number2 = 0; // second integer to add (initialized to 0)int sum = 0; // sum of number1 and number2 (initialized to 0)

are declarations. The identifiers number1, number2 and sum are the names of variables. These declarations specify that the variables number1, number2 and sum are data of type int, meaning that these variables will hold integer values. The declarations also initialize each of these variables to 0.

Image Error-Prevention Tip 2.1

Although it’s not always necessary to initialize every variable explicitly, doing ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

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