click below
click below
Normal Size Small Size show me how
C++ Common Types
The most important types are int, char, bool, and double; also classes. "Quiz 1"
| Question | Answer |
|---|---|
| int x; | Fastest integer type (16-32 bits), also short, long, and unsigned |
| char x; | 8-bit character, '\0' to '\xFF' or -128 to 127 |
| double x; | 64 bit real + or - 1.8e308, 14 significant digits, also float |
| bool x; | true or false |
| const T x; | Non-modifiable object |
| T f(...) {...} | Defines f as a function returning T |
| T* p; | Pointer to T (*p is a T object) |
| T a[N]; | Array of N elements of T, a[0] to a[N-1] |
| static T x; | Place x in data segment |
| register T x; | (rare) Hint to optimize for speed |
| volatile T x; | (rare) x may be modified externally |
| t& y=x; | Reference, y is an alias for x, which both have type T |
| How do you include a standard library type and the beginning of the program? | #include <header> |
| What standard type must be included at the beginning of the program? | using namespace std; |
| istream / iostream | Standard input (cin) |
| ostream / iostream | Output (cout, cerr, clog) |
| ifstream / fstream | Input file |
| ofstream / fstream | Output file |
| string / string | Sequence of char |
| vector<T> / vector | Expandable array/stack of T |
| deque<T> / deque | Array/double ended queue |
| list<T> / list | List/stack/queue of T |
| map<T1,T2> / map | Associative mapping of T1 to T2 |
| set<T1> / set | A map with keys only |
| pair<T1,T2> / map or utility | Two objects of type T1 and T2 |
| priority_queue<T> / queue | Sorted queue |
| stack<T> / stack | Stack |
| bitset<N> / bitset | Array of N bool with logical operations |
| valarray<T> / valarray | Array with arithmetic operations |
| complex<T> / complex | Complex number |
| iterator / (Included with container) | Pointer into a container |
| const_iterator / (Included with container) | Pointer not allowing element assignment |
| exception / stdexcept, exception | Hierarchy of exception types |
| algorithm | min(), max(), swap(), sort(), copy(), equal() |
| numeric | accumulate(), inner_product() |
| iterator | back_inserter() |
| functional | equal_to(), less(), bind2nd() |
| new | set_new_handler() |
| cstdlib | atoi(), atof(), abs(), rand(), system(), exit() |
| cctype | isalpha(), isgigit(), tolower(), toupper() |
| cmath | sqrt(), log(), exp(), pow(), sin(), cos(), atan() |
| ctime | clock(), time() |
| cstring | strleng(), memset(), memmove(), memcmp() |
| cstdio | printf(), fopen(), getc(), perrer() |
| cassert (debugging) | assert() |
| What most important type does C++ allow you to create on your own? Define it. | A class is a abstract data structure and an associated set of member functions (methods) and related type declarations which can be associated with the class or instances (objects) of the class. A class is divided into public and private implementations. |
| Define inheritance in one sentence: | Inheritance is a hierarchy of classes, and it is used to write a specialized or enhanced version of another class; For example, an ofstream is a type of ostream. |
| Define polymorphism in one sentence: | Polymorphism is the technique of coding a common interface for a hierarchy of classes; For example, A child object is allowed wherever a parent object is expected. |
| class T {...}; | Defines T as a collection of types, objects, and member functions |
| template <class T> ... | Defines a set of functions or classes over all T |
| typedf T U; | Defines type U is a synonym for T |
| enum T {...}; | Defines T as an int, and set of int constants |
| struct T {...}; | Like a class, except default scope of members is public |
| union T {...}; | A struct with object members overlapping in memory |
| namespace N {...}; | Defines a scope for a collection of types, objects, and functions |