CHAPTER 5
SECTION 5.1-5.12
1. % operator can be applied only to operands of the integral types: bool, char, short, int, long, and their associated unsigned types.
2. When only one operand is negative, the sign and value of the result for the modulus operator can follow either the sign of the numerator or of the denominator.
3. The logical AND and OR operators always evaluate their left operand before the right. The right operand is evaluated only if the left operand does not determine the result. This evaluation strategy is often referred to as "short-circuit evaluation."(短路求值)
4. A valuable use of the logical AND operator is to have expr1 evaluate to false in the presence of a boundary condition that would make the evaluation of expr2 dangerous.
5. Because there are no guarantees for how the sign bit is handled, we strongly recommend using an unsigned type when using an integral value with the bitwise operators.
6. Assignment is Right Associative. As such, we can perform multiple assignments in a single expression.
7. assignment has lower precedence than inequality.
8. The prefix decrement operators similarly, except that it decrements its operand. The postfix versionsof these operators increment (or decrement) the operand but yield a copy of the original, unchanged value as its result.
9. USE POSTFIX OPERATORS ONLY WHEN NECESSARY. The prefix version does less work. It increments the value and returns the incremented version.
10. The dot operator fetches an element from an object of class type.The language defines the arrow operator as a synonym for a dereference followed by the dot operator.
(*p).foo;
p->foo;
11. Evaluating sizeof expr does not evaluate the expression.
12. The expressions are evaluated from left to right. The result of a comma expression is the value of the rightmost expression. The result is an lvalue if the rightmost operand is an lvalue.
13. If you change the value of an operand, don't use that operand elsewhere in the same statement. If you need to use the changed value, the break the expression up into separate statements in which the operand is changed in one statement and then used in a subsequent statement.
14. Do not use an increment or decrement operator on the same objects in more than two subexpressions of the same expression.
15. When we dynamically allocate an object, we specify a type but do not name the object.
16. Just as we always initialize the objects we define as variables, it is always a good idea to initialize dynamically allocated objects.
17. It is illegal to apply delete to a pointer that addresses memory that was not allocated by new.
18. It is legal to delete a pointer whose value is zero.
19. After deleting a pointer, the pointer becomes what is referred to as a dangling pointer, Setting the pointer to 0 after the object it refers to has been deleted makes it clear that the pointer points to no object.
20. three common program errors are associated with dynamic memory allocation:
1) Failing to delete a pointer to dynamically allocated memory. "memory leak".
2) Reading or writing to the object after it has been deleted.
3) Applying a delete expression to the same memory location twice.
21. The exceptions when an array is not converted to a pointer are: as the operand of the address-of(&) operator or of sizeof, or when using the array to initialize a reference to the array.
22. A pointer to any data type can be converted to a void*, and a constant integral value of 0 can be converted to any pointer type.
23. A nonconst object can be converted to a const object, which happens when we use a nonconst object to initialize a reference to const object.
int i;
const int &j = i;
24. A const_cast, as its name implies, casts away the constness of its expression. Only a const_cast can be used to cast away constness.
25. we can use a static_cast to retrieve a pointer value that was stored in a void* pointer.
26. Although the old-style cast notation is supported by Standard C++, we recommend it be used only when writing code to be compiled either under the C language or pre-Standard C++.
CHAPTER 6
SECTION 6.1-6.14
1. A null statement is useful where the language requires a statement but the program's logic does not.
2. A null statement should be commented, so that anyone reading the code can see that the statement was omitted intentionally.
3. the IO types can be used in a condition, but the vector and string types may not be used as a condition.
4. Although it is not strictly necessary to specify a break statement after the last label of a switch, the safest course is to provide a break after every label, even the last. If an additional case label is added later, then the break is already in place.
5. It can be useful always to define a default label even if there is no processing to be done in the default case. Defining the label indicates to subsequent readers that the case was considered but that there is no work to be done.
6. A label may not stand alone, it must precede a statement.
7. Variables can be defined following only the last case or default label inside a switch.
8. Variables defined in the condition are created and destroyed on each trip through the loop.
9. Unlike a while statement, a do-while statement always ends with a semicolon.
10. Had we defined rsp inside the do, then rsp would go out of scope at the close curly brace before the while. Any variable referenced inside the condition must exist before the do statement itself.
11. A break statement terminates the nearest enclosing while, do while, for, or switch statement.
12. A continue statement causes the current iteration of the nearest enclosing loop to terminate.
13. A continue can appear only inside a for, while, or do while loop.
14. A goto statement provides an unconditional jump from the goto to a labeled statement in the same function. The goto and the labeled statement to which it transfers control must be in the same function.
15. In C++ exception handling involves: throw expressions, we say that a throw raises an exceptional condition. try blocks, A set of exception classes defined by the library.
16. Once the catch clause finishes, execution continues with the statement immediately following the last catch clause of the try block.
17. The search for an exception handler reverses the call chain.
18. C++ programmers sometimes use a technique similar to header guards to conditionally execute debugging code.
19. _ _FILE_ _ name of the file _ _LINE_ _ current line number _ _TIME_ _ time the file was compiled _ _DATE_ _ date the file was compiled
20. if the result is false, then assert writes a message and terminates the program. If the expression has a nonzero value, then assert does nothing.
21. assert should be used only to verify things that truly should not be possible. It can be useful as an aid in getting a program debugged but should not be used to substitute for run-time logic checks or error checking that the program should be doing.