Files
clearn/testmalloc.cc

39 lines
538 B
C++
Raw Normal View History

2017-02-07 20:03:49 +00:00
#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<75>cksetzen
pb=pa;
// Elemente ausgeben
for(i=0;i<5;i++)
{
cout << pb << "::" << *pb << "::" << endl;
pb++;
}
// Alloszierter Speicher freigeben
free(pa);
return 0;
}