Table of Contents
- 1. C++ Basics
- 2. GETTING STARTED
- 3. SETTING OUT TO C++
- 4. DEALING WITH DATA
- 5. COMPOUND TYPES
- 6. LOOPS AND RELATIONAL EXPRESSIONS
- 7. BRANCHING STATEMENTS AND LOGICAL OPERATORS
- 8. FUNCTIONS: C++âS PROGRAMMING MODULES
- 9. ADVENTURES IN FUNCTIONS
- 10. MEMORY MODELS AND NAMESPACES
- 11. OBJECTS AND CLASSES
- 12. WORKING WITH CLASSES
- 13. CLASSES AND DYNAMIC MEMORY ALLOCATION
- 14. CLASS INHERITANCE
- 15. REUSING CODE IN C++
- 16. FRIENDS, EXCEPTIONS, AND MORE
- 17. THE string CLASS AND THE STANDARD TEMPLATE LIBRARY
- 18. INPUT, OUTPUT, AND FILES
C++ Premier Plus
1 C++ Basics
2 GETTING STARTED
2.1 Learning C++: What Lies Before You
2.2 The Origins of C++: A Little History
2.3 Portability and Standards
2.4 The Mechanics of Creating a Program
3 SETTING OUT TO C++
3.1 C++ Initiation
3.3 More C++ Statements
3.4 Functions
4 DEALING WITH DATA
4.1 Simple Variables
- Variables:
- common variables names
int price_count_reader; // No abbreviation. int num_errors; // "num" is a widespread convention. int num_dns_connections; // Most people know what "DNS" stands for.
- Class Data Members
Data members of classes, both static and non-static, are named like ordinary nonmember variables, but with a trailing underscore.
class TableInfo { ... private: string table_name_; // OK - underscore at end. string tablename_; // OK. static Pool<TableInfo>* pool_; // OK. };
- common variables names
- Constant Names
Variables declared constexpr or const, and whose value is fixed for the duration of the program, are named with a leading "k" followed by mixed case. For example:
const int kDaysInAWeek = 7;
- Function Names
AddTableEntry() DeleteUrl() OpenFileOrDie()
- File Names
- my_useful_class.cc
- my-useful-class.cc
- myusefulclass.cc
- myusefulclass_test.cc // _unittest and _regtest are deprecated.
4.2 The const Qualifier
4.3 Floating-Point Numbers
4.4 C++ Arithmetic Operators
5 COMPOUND TYPES
5.1 Introducing Arrays
5.2 Strings
5.3 Introducing the string Class
5.4 Introducing Structures
5.5 Unions
5.6 Enumerations
5.7 Pointers and the Free Store
5.8 Pointers, Arrays, and Pointer Arithmetic
- swap value of two variables using pointers
#include <stdio.h> void Swap(int* a, int* b) { int temp; //use the variable temp to store one value. temp = (*b); //temp equals to content of pointer b (*b) = (*a); //pointer b equals to content of pointer a (*a) = temp; //content of pointer a equals to temp } int main() { int i = 123, j = 456; int* x = &i; //x points to i int* y = &j; //y points to j printf("Before swapping: i = %d, j = %d\n",i , j); Swap(x, y); printf("After swapping: i = %d, j = %d\n",i , j); return 0; }