Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
void test(char* command) {
delete command;
command = new char[5];
command[0] = 'f';
}
int main(int argc, char *argv[]) {
char* command = new char;
test(command);
cout << command;
}
void test(char* &myptr) { /* wir wollen eine Referenz auf einen char-ptr*/
myptr = new char[5](); /* sollte ab c++ 03 für eine zero-initialisierung sorgen*/
myptr[0] = 'f';
}
...
char * command;
test(command);
Das funktioniert nur, weil zuerst der Speicherblock freigegeben wird und direkt danach ein neuer angefordert - und da wird der gerade freigegebene Speicherblock wieder zugewiesen.so würde es funktionieren
delete command;
command2 = new char[5];
command = new char[5];
command[0] = 'x'; - und schon sollte es nicht mehr "funktionieren" ;)
delete command2;