tailieunhanh - Absolute C++ (4th Edition) part 2

Absolute C++ (4th Edition) part 2. KEY BENEFIT: C++ programming concepts and techniques are presented in a straightforward style using understandable language and code. KEY TOPICS: C++ Basics; Flow of Control; Function Basics; Parameters and Overloading; Arrays; Structures and Classes; Constructors; Operator Overloading, Friends, and References; Strings; Pointers and Dynamic Arrays; Separate Compilation and Namespaces; Streams and File I/O; Recursion; Inheritance; Polymorphism and Virtual Functions; Templates; Linked Data Structures; Exception Handling; Standard Template Library; Patterns and UML. MARKET: Useful for both beginning and intermediate C++ programmers. . | Variables Expressions and Assignment Statements ii Assignment Statements In an assignment statement first the expression on the right-hand side of the equal sign is evaluated and then the variable on the left-hand side of the equal sign is set equal to this value. Syntax Variable Expression Examples distance rate time count count 2 In C assignment statements can be used as expressions. When used as an expression an assignment statement returns the value assigned to the variable. For example consider n m 2 The subexpression m 2 both changes the value of m to 2 and returns the value 2. Thus this sets both n and m equal to 2. As you will see when we discuss precedence of operators in detail in Chapter 2 you can omit the parentheses so the assignment statement under discussion can be written as n m 2 We advise you not to use an assignment statement as an expression but you should be aware of this behavior because it will help you understand certain kinds of coding errors. For one thing it will explain why you will not get an error message when you mistakenly write n m 2 when you meant to write n m 2 This is an easy mistake to make since and are on the same keyboard key. Lvalues and Rvalues Authors often refer to lvalue and rvalue in C books. An lvalue is anything that can appear on the left-hand side of an assignment operator which means any kind of variable. An rvalue is anything that can appear on the right-hand side of an assignment operator which means any expression that evaluates to a value. 12 C Basics Pitfall Uninitialized Variables uninitialized variable A variable has no meaningful value until a program gives it one. For example if the variable minimumNumber has not been given a value either as the left-hand side of an assignment statement or by some other means such as being given an input value with a cin statement then the following is an error desiredNumber minimumNumber 10 This is because minimumNumber has no meaningful value and so the entire expression

TỪ KHÓA LIÊN QUAN