Skip to content

Instantly share code, notes, and snippets.

@leopic
Created November 4, 2012 21:41
Show Gist options
  • Save leopic/4013890 to your computer and use it in GitHub Desktop.
Save leopic/4013890 to your computer and use it in GitHub Desktop.
Probando borrar punteros.
#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