General
- Include
- #include <iostream> // Notice no semicolon
- Namespace
- using namespace std;
Modifiers
- static
- Exist throughout application life time
sizeof
- Return number of bytes occupied by the object
- sizeof number;
- sizeof(long);
new
- Dynamically allocates heap memory
- Returns address of the space allocated (a pointer)
- Can only be de-allocated by delete
- Example
// Declare a pointer
double* pval = NULL;
// Test for out of memory
if (!(pval = new double)){
cout << "Out of memory...";
exit(1);
}
// Allocate a double and initialize it
pval = new double(999.0);
// Release memory pointed by pval
delete pval;
// Declar a char pointer
char* pstr = NULL;
// Allocate a string of 20 characters
pstr = new char[20];
// Delete array pointed to by pstr
delete [] pstr;
Debugging
- Go
- Stop at the first break point
- Step into
- Run one statement at a time
- Step over
- Run one statement in the main() function at a timeĀ
- Run to cursor
- Run to where you position the text cursor
- Attach
- Debug a program that’s already running