Professional Documents
Culture Documents
CPP Fundamentals
CPP Fundamentals
Overview
A Couple Notes
Displaying Pointers
Freeing memory
Standard Libraries
Types
Conversion
Casting
Bitwise Operations
Constants
Assertions
Declaration versus Definition
Header Files
Static initialization
Compilation Process (Overview)
Displaying Pointers
The output of this code is garbage why?
char c = c;
char* pc = &c;
cout << pc << endl; //Want pointers value
C strings are null-terminated character arrays
char* cString = Hello!;
cout << cString << endl;
//We expect to see Hello
So the first example prints bytes from &c to the first null.
To get what we want
char c = c;
char* pc = &c;
cout << static_cast<void*>(pc) << endl;
//Pointers value printed
Not normally necessary with non-character pointers.
Freeing Memory
Remember:
Use scalar delete if you used scalar new.
Use array delete if you used array new.
Using the wrong one results in undefined
behavior!
int* scalar = new int(5);
int* arr = new int[30];
delete arr; //NO! Use delete[]
delete [] scalar; //NO! Use delete
Overview
A Couple Notes
Displaying Pointers
Freeing memory
Standard Libraries
Types
Conversion
Casting
Bitwise Operations
Constants
Assertions
Header Files
Static initialization
Compilation Process (Overview)
Standard Libraries
bool
Values of true or false only.
enum
Named values
Integral
char, short, int, long
signed and unsigned
Floating-point
float, double, long double
Integral Types
For integral types, the following maximum value
hierarchy holds:
signed char unsigned char
[signed] short [int] unsigned short [int]
[signed] int unsigned int
[signed] long [int] unsigned long [int]
int is usually either a short or long.
The C++ standard defines the minimum range of each
type.
Arithmetic operators apply only to types int and long
(or their unsigned variants).
Operands smaller are promoted to the appropriate type
Integral Types (cont.)
#endif /* FILENAME_H */
Header Implementation (.cpp)
Linker .exe
.obj