The notes of Essential C++ —— the very book for the C++ beginners.
CH1 Basic C++ Programming
Define and Initialize a Data Object
Initialize
The data type determine the range of values the object can hold and the amount of the memory that must be allocated to hold the those values.
|
|
%
remainder oprerator
When might we actually use the remainder operator? Imagine that we want to print no more than eight strings on a line. If the number of words on the line is less than eight, we output a blank space following the word. If the string is the eighth word on the line, we output a newline. Here is our implementation:
|
|
Pointers Allow for Flexibility
To guard against dereferencing a null pointer, we test a pointer to see whether its address is zero.
|
|
The expression if (pi && ...)
evaluates to true only if pi contains an address other than 0.
To test whether a pointer is null, we typically use the logical NOT operator:
|
|
CH2 Procedural Programming
What should we do if the user requests an invalid position? The most extreme thing we can do is terminate the program. The standard libraty exit()
function does just that. We pass it a value, and that value becomes the exit status of the program:
|
|
To use exit()
, we must include the cstdlib
header file:
|