|
| |
Introduction
C++ is one of the most complex of languages ever created while, at the same
time, is based on the very basic 'C' language. This paradox means that C++
has all of the simplicity of C while allowing very complex and powerful
applications to be developed that take advantage of object oriented (OO)
programming techniques. These OO techniques enable the C++ development
environment to be extended to represent real-world and logical data structures
as objects.
Language Fundamentals
Program Structure and Organization
| //a demo program |
// starts a line of comment |
| #include <iostream> |
creates a reference to an standard or developed library |
| using namespace std; |
makes I/O facilities available to the program |
| void main () |
initial function, starts program execution (same as C) |
| { |
function bracket - opening |
| cout << "Hello World"; |
code for the main function, prints text in the standard
output |
| } |
closing function bracket |
 | Identifiers and keywords for C++ includes: |
| asm, auto, bool, break, case, catch, char, class, const,
const_cast, continue, default, delete, do, double, dynamic_cast, else,
enum, explicit, extern, false, float, for, friend, goto, if, inline, int,
long, mutable, namespace, new, operator, private, protected, public,
register, reinterpret_cast, return, short, signed, sizeof, static,
static_cast, struct, switch, template, this, throw, true, try, typedef,
typeid, typename, union, unsigned, using, virtual, void, volatile, wchar_t |
 | Source code management (files, etc.)
 | Code is written in ASCII (or native environment) text. |
 | Vendor specific tools such as those by Intel and Microsoft have powerful
development environments that assist in building and managing code, access
database development tools, and generating complex user interfaces. |
|
 | C++ programs are compiled to executables often requiring library support
for a variety of object-based tools for database access, web server and client
support, etc. |

Data Types
| Name |
Bytes* |
Description |
Range* |
| char |
1 |
character or integer 8 bits length. |
signed: -128 to 127
unsigned: 0 to 255 |
| short |
2 |
integer 16 bits length. |
signed: -32768 to 32767
unsigned: 0 to 65535 |
| long |
4 |
integer 32 bits length. |
signed:-2147483648 to 2147483647
unsigned: 0 to 4294967295 |
| int |
* |
Integer. Its length traditionally depends on the length of the
system's Word type. |
See short, long |
| float |
4 |
floating point number. |
3.4e + / - 38 (7 digits) |
| double |
8 |
double precision floating point number. |
1.7e + / - 308 (15 digits) |
| long double |
10 |
long double precision floating point number. |
1.2e + / - 4932 (19 digits) |
| bool |
1 |
Boolean value. It can take one of two values: true or
false NOTE: recently added by the ANSI-C++ standard, not all
compilers support it. |
true or false |
| wchar_t |
2 |
Wide character. It is designed as a type to store international
characters of a two-byte character set. NOTE: recently added by the
ANSI-C++ standard; not all compilers support it. |
wide characters |
 | Declaring variables:
 | int i; - initializes a variable of type integer called i |
 | int i = 3; - initializes and i and sets it equal to 3 |
 | int i1, i2; - initializes two variables: i1, and i2 |
|
 | Variables are case sensitive. |
 | Arrays:
 | All data types support array declarations. |
 | Example: char line[81]; - declares a character array with 81
positions |
 | Filling an array: line[2] = 'A' |
 | Multidimensional arrays are possible: e.g., short
array_name[50][20][10] creates an array with 10,000 elements. |
|
 | Variable scope:
 | Variables declared in functions live within the function. |
 | static int i; - creates a variable scoped within the file. |
 | extern int i; - creates a variable scoped within an application. |
|

Expressions and Operators
Similar to C with additional features to handle objects.
Operators
(in order of priority) |
Description |
| :: |
Scope access / resolution |
| () [ ] -> . sizeof |
Function calls, array subscripts, etc.. |
| ++ -- |
Increment/decrement |
| ~ |
Complement to one (bitwise) |
| ! |
Unary NOT |
| & * |
Reference and Dereference (pointers) |
(type)
delete (removes memory storage)
new (allocates memory storage) |
Type casting |
| + - |
Unary less sign |
| * / % |
Arithmetical operations |
| + - |
Arithmetical operations |
| << >> |
Bit shifting (bitwise) |
| < <= > >= |
Relational operators |
| == != |
Relational operators |
| & ^ | |
Bitwise operators |
| && || |
Logic operators |
| ?: |
Conditional |
= += -= *= /= %=
>>= <<= &= ^= |= |
Assignment |
| , |
Comma, Separator |

Class Development Support
 | Classes are logical methods to organize data and functions in the same
structure. |
 | Classes are declared using keyword 'class' (similar to the C
keyword struct, but with the possibility of including functions
as members, instead of only data). |
 | The form is: |
class class_name {
permission_label_1:
member1;
permission_label_2:
member2;
...
} object_name;
 | class_name is a name for the class (user defined type)
and the optional field |
 | object_name is one, or several, valid object identifiers.
|
 | The body of the declaration can contain members,
 | These can be either data or function declarations, and optionally
permission labels, that can be any of these three keywords:
private:, public: or protected:. |
 | These make reference to the permission which the following members
acquire: |
|
 | private members of a class are accessible only from other
members of their same class or from their "friend" classes. |
 | protected members are accessible from members of their same
class and friend classes, and also from members of their derived
classes. |
 | public members are accessible from anywhere the class is
visible. |
 | If we declare members of a class before including any permission label,
the members are considered private, since it is the default
permission that the members of a class declared with the class
keyword acquire. |

Control Statements
Generally the same as C...
 | If-then
|
if (expression) {
statement;
statement;
.... }
if (expression) {
statement;
statement; }
else
statement;
if (expression) {
statement;
statement; }
else {
statement;
statement; }
if (expression) {
statement;
statement; }
else if (expression)
statement;

Input/Output

Resources
References
Tutorials
Note: I am publishing this a bit early -- it still needs some work, but this
is a good start.
|