2.2. Values

A value is one of the fundamental things—like a letter or a number—that a program manipulates. The only values we have manipulated so far are the string values we have been outputting, like “Hello, world.”. You (and the compiler) can identify string values because they are enclosed in quotation marks.

There many different kinds of values, called types. This includes integers and characters. An integer is a whole number like 1 or 17. You can output integer values the same way you output strings:

cout << 17 << endl;

A character value is a letter or digit or punctuation mark enclosed in single quotes, like ’a’ or ’5’. You can output character values the same way:

cout << '}' << endl;

This example outputs a single close squiggly-brace on a line by itself.

It is easy to confuse different types of values, like “5”, ’5’ and 5, but if you pay attention to the punctuation, it should be clear that the first is a string, the second is a character and the third is an integer. The reason this distinction is important should become clear soon.

You have attempted of activities on this page