Next: Call by Pointer Reference
Up: Pointer Puzzles
Previous: Call by Reference II
int *makeArray(int max)
{
int *result=new int[max];
for(int i=0; i<=max; i++)
result[i]=0;
return result;
}
main()
{
int *newArray;
newArray=makeArray(7);
// ....
delete newArray;
}
| Das Programm ist falsch! |
| Der Zähler in der for-Schleife zählt zu hoch! |
Beachte: Deklaration von i innerhalb der for-Schleife |
Beachte: Speicher wird durch new dynamisch alloziiert. |
| © 1997 Gottfried Rudorfer, C++-AG, Lehrveranstaltungen, Abteilung für Angewandte Informatik, Wirtschaftsuniversität Wien, 3/19/1998 |