Created
November 4, 2012 21:41
-
-
Save leopic/4013890 to your computer and use it in GitHub Desktop.
Probando borrar punteros.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream>; | |
using namespace std; | |
int main() { | |
int miVar, | |
*miPuntero; | |
miVar = 8; | |
miPuntero = &miVar; | |
cout << "Eliminando punteros: " << endl; | |
cout << "Posicion de memoria: " << miPuntero << endl; | |
// simplemente borrando: tira un error o.O? | |
delete miPuntero; | |
cout << "miPuntero: " << miPuntero << endl; | |
// Error: a.out(14399) malloc: *** error for object 0x7fff61e537f4: | |
// pointer being freed was not allocated | |
// *** set a breakpoint in malloc_error_break to debug | |
// Abort trap: 6 | |
// usando new primero: no se borra? | |
miPuntero = new int; | |
delete miPuntero; | |
cout << "miPuntero: " << miPuntero << endl; | |
// miPuntero siempre tiene una direccion almacenada. | |
// usando NULL: parece borrarse | |
miPuntero = NULL; | |
delete miPuntero; | |
cout << "miPuntero: " << miPuntero << endl; | |
// miPuntero retorna 0. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment