In the introductory lecture, we summarized that programming is centered around two distinct aspects: data and instructions. We will begin our in-depth study focussing on the aspect of data.
We will use the term "object" to denote a piece of data. Objects can represent various "types" of data. Some of these are fundamental built-in types supported by the language, for representing integers, floating-point numbers, characters, strings and so on. Later in the course we will see how we can make use of a richer set of object types defined by other programmers or our own programs.
Though we will often gloss over the lowest-level details of precisely how the computer system uses bits to represents a particular data type, it is most important that we recognize that each object must be stored somewhere in the computer's memory system! Furthermore, once the system sets aside some portion of memory to store a particular object, we must denote it in a way so that we can discuss it syntactically.
We will explore a typical "declaration" statement in C++ (aka "definition" as per Ch. 2.9). Such a statement designates:
What type of object is being defined.
What identifier (aka "name") will we use to denote the declared object.
(Optionally) What initial value should the object be given.
There are many data types, some of which are built-in, some of which are predefined in standard C++ libraries, and some can be newly defined by the programmer. We will start by discussing some common data types: short, int, long, float, double, long double, char, string.
For each of these, we will also look at how some initial declarations can be made using appropriate "constants" (aka "literals") for that type. Examples include:
int:
23
-5
long:
123456789L
double:
3.14
29.00
0.32
.23
1.23E10
float:
3.14F
char:
'M'
'm'
';'
'\''
'\n'
string:
"Hello"
"How are you?"
"How are you?\n"
"I said \"How are you?\"\n"
""
When discuss the above, we may look at portions of the following simple program (fund.cpp) as examples of variable declarations and initial assignments. The examples given here are correctly types, though we may explore some additional (incorrect) modifications.