You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
intprice_count_reader; // No abbreviation.intnum_errors; // "num" is a widespread convention.intnum_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.
classTableInfo {
...
private:
stringtable_name_; // OK - underscore at end.stringtablename_; // OK.staticPool<TableInfo>*pool_; // OK.
};
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:
constintkDaysInAWeek=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.
The const Qualifier
Floating-Point Numbers
C++ Arithmetic Operators
COMPOUND TYPES
Introducing Arrays
Strings
Introducing the string Class
Introducing Structures
Unions
Enumerations
Pointers and the Free Store
Pointers, Arrays, and Pointer Arithmetic
swap value of two variables using pointers
#include<stdio.h>voidSwap(int*a, int*b)
{
inttemp; //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
}
intmain()
{
inti=123, j=456;
int*x=&i; //x points to iint*y=&j; //y points to jprintf("Before swapping: i = %d, j = %d\n",i , j);
Swap(x, y);
printf("After swapping: i = %d, j = %d\n",i , j);
return0;
}
LOOPS AND RELATIONAL EXPRESSIONS
Introducing for Loops
Relational Expressions
The while Loop
The do while Loop
Loops and Text Input
Nested Loops and Two-Dimensional Arrays
BRANCHING STATEMENTS AND LOGICAL OPERATORS
The if Statement
Logical Expressions
The cctype Library of Character Functions
The ?: Operator
The switch Statement
The break and continue Statements
Number-Reading Loops
Simple File Input/Output
FUNCTIONS: C++’S PROGRAMMING MODULES
Function Review
Function Arguments and Passing by Value
Functions and Arrays
Functions and Two-Dimensional Arrays
Functions and C-Style Strings
Functions and Structures
Functions and string Class Objects
Recursion
Pointers to Functions
ADVENTURES IN FUNCTIONS
C++ Inline Functions
Reference Variables
Default Arguments
Function Overloading
Function Templates
MEMORY MODELS AND NAMESPACES
Separate Compilation
Storage Duration, Scope, and Linkage
The Placement new Operator
Namespaces
OBJECTS AND CLASSES
Procedural and Object-Oriented Programming
Abstraction and Classes
Class Constructors and Destructors
Knowing Your Objects: The this Pointer
An Array of Objects
The Interface and Implementation Revisited
Class Scope
Abstract Data Types
WORKING WITH CLASSES
Operator Overloading
Time on Our Hands: Developing an Operator Overloading Example
Introducing Friends
Overloaded Operators: Member Versus Nonmember Functions
More Overloading: A Vector Class
Automatic Conversions and Type Casts for Classes
CLASSES AND DYNAMIC MEMORY ALLOCATION
Dynamic Memory and Classes
A Queue Simulation
CLASS INHERITANCE
Beginning with a Simple Base Class
Inheritance: An Is-a Relationship
Polymorphic Public Inheritance
Access Control: protected
Abstract Base Classes
Inheritance and Dynamic Memory Allocation
Class Design Review
REUSING CODE IN C++
Classes with Object Members
Private Inheritance
Multiple Inheritance
Class Templates
FRIENDS, EXCEPTIONS, AND MORE
Friends
Nested Classes
Exceptions
RTTI
Type Cast Operators
THE string CLASS AND THE STANDARD TEMPLATE LIBRARY