initial checkin from subversion
This commit is contained in:
38
testmalloc.cc
Normal file
38
testmalloc.cc
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <iostream.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
// Variablen deklarieren
|
||||
int a,i;
|
||||
int *pa,*pb;
|
||||
|
||||
// Speicher für 5 Elemente reservieren
|
||||
pa= malloc(5*sizeof(a));
|
||||
|
||||
// Pointer Sichern
|
||||
pb=pa;
|
||||
|
||||
// Elemente füllen
|
||||
for(i=0;i<5;i++)
|
||||
{
|
||||
*pb=i;
|
||||
// Nächstes Element
|
||||
pb++;
|
||||
}
|
||||
|
||||
// Pointer wieder auf Erstes Element zurücksetzen
|
||||
pb=pa;
|
||||
|
||||
// Elemente ausgeben
|
||||
for(i=0;i<5;i++)
|
||||
{
|
||||
cout << pb << "::" << *pb << "::" << endl;
|
||||
pb++;
|
||||
}
|
||||
|
||||
// Alloszierter Speicher freigeben
|
||||
free(pa);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user