Zeiger unter C++


engl. pointer

http://www.num.math.uni-goettingen.de/Dokumentationen/C/Einfuehrung/zeiger.html#Zeigerzeiger

Examples


mTyp aName; // Declaration of aName
printf( "%d", &aName )// Print address of aName


mClass *mName;  // Declaration of a pointer t class mClass named mName
mClass* mName;  // Declaration of a pointer t class mClass named mName

(*mName).function();    // Call to a method function() in the class mKalsse
mName->function()// Call to a method function() in the class mKalsse


mTyp** mName;   // Pointer to pointer of mName
mName = new int*[5];    // Create a Pointer to an 1dim array of size 5

mTyp**** mName; // equivalent....


// create an new object of type mKalsse named oKlasse
mClass oKlasse = new mClass()

// Something() returns a pointer to another class
oKlasse2* p2 = oKlasse.Something() 

// Print address
printf( "%d", p2 );            

// Call to a method of the class p2 points to
p2->Method();


// short way to call the method Method()
oKlasse.Something()->Method();


// create new array
int* a = new int[3];


// create new array
mClass50 is a pointer to a array of 50 classes of type mClass (mClass50**)
mClass** a = new mClass*[50];
// a fast way to copy the 50 pointers if type mClass to an other array a
memcpy(a, mClass50, (50*sizeof(mClass*));


int av=1;
int *a;
a= &av;
printf("%d\n",*a);



1. Pointerarithmetik


für
short int i
float ar[10]

gilt

Zugriff auf das erste Element
*ar
ar[0]


Zugriff auf den Zeiger des ersten Elements
&ar[0]
ar


Zugriff auf ein beliebiges Element
*(ar + i)
ar[i]


Zugriff auf die Bytes des Arrays
*((unsigned char*)ar + i)
((unsigned char*)ar)[i]







Siehe auch C

There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki