Home   -   Computerkurs   DemoMatrix   Editpointstatic   Folderwatcher   Gipsydrive   Licenses   Shrinkseries   V4   More...  

All   Asm   Bas   C   C++   C#   CSS   HTML   Java   JS   Lisp   OPAL   PHP   Perl   PS   Py   Rb   SQL   Win  

Previous page Home chapter Next page

Trilo - Downtown - Languages


This page is draft. Please visit the Trekta C++ Course .


C++ includes C and adds new features to it. The new features are most notably classes, which make object oriented programming possible.









A pointer is a variable, that holds not the value itself, but the memory address, where the value is stored. The pointer has a type which determines, how many bytes the value does occupy at it's memory location.

There are two operators * and & involved, the both come in two distinct usages, which we try to tell apart below. Furthermore we discuss three special cases: pointers of type void, pointers to functions, pointers to pointers.

(1) Pointer operator *

This is the most common use, it defines a pointer to a memory address which stores values of a specific type.

               int * pInt = new int(5);      // on heap
               int * pInt = new int[5];      // on heap
               int[] intArray = ... ;        // on stack (CHECK)

(2) Dereference operator *

Solves a pointer into it's referring object type and the concrete object respectively. [Löst einen Pointer auf in den dahinterstehenden Objekttyp bzw. das konkrete Objekt.]

               int *p = new int(5);      // pointer as usual
               dowhat1(*pInt);           // dereference p from pointer to value

(3) Address operator &


               int a = 5;
               int p = &a;  // p now contains the address of a

(4) Reference operator &

With references, a caller can pass a parameter to be changed by a function. If one return value is not enough, but we want two or more, we can to pass a parameter as a reference or as a pointer.

               ///void dowhat1(const int &a);
               ///void dowhat2(cont int *p);
               void dowhat1(int &a);            // declaration, note the &
               void dowhat2(int *p);            // declaration
               int a = 5;                       // declare plus initialaize a value
               dowhat1(a);                      // pass value, taken as reference
               dowhat2(&a);                     // pass the pointer

(5) Pointers of type void

We neet them if we want deal with a pointer before we know it's final type.

               char* pChar = NULL;
               int* pInt = NULL;
               void* pVoid = NULL;
               int t = getType(..);
               int s = getSize(..);
               int s2 = sizeof(..);
               if (t == 0)
                  pChar = (char*) pVoid;

(6) Pointers to functions

It's a delegate mechanism ...

It's a typedef on function pointers ... (very difficult syntax)

               // supplement sample code ...

(7) Pointers to pointers

[It's not soo difficult ... we just need a telling example ...]

               // supplement sample code ...






About the latest C++ Standard: Heise Open News www.heise.de/.. C++ 11 einstimmig als Standard angenommen ..html (20110816°043902), pointing to Herb Sutter's herbsutter.com/.. we-have-an-international-standard-c0x-is-unanimously-approved (20110816°1011) and Bjarne Stroustrup's www2.research.att.com/~bs/C%2B%2B0xFAQ.html (20110816°043902).



20110704°1321 20110704°1331 20110718°1141 20110718°1142 20120130°0921 20120217°1711

Imprint : www.trilo.de