Last active
April 21, 2020 15:02
-
-
Save JimmyOlano/b092784d6cb0401c988f6bda2d06d43a to your computer and use it in GitHub Desktop.
Bestiario de una memoria mal gestionada (II)
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 <string.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
int main() | |
{ | |
char *p1 = (char*)malloc(sizeof(char)*30); | |
memset(p1, '\0', 30); | |
memcpy(p1, "PRIMERA PRUEBA", 30); | |
printf("%s\n", p1); | |
free(p1); | |
char *p2 = (char*)malloc(sizeof(char)*30); | |
memset(p2, '\0', 30); | |
memcpy(p2, "SEGUNDA PRUEBA", 30); | |
free(p1); | |
printf("%s\n", p2); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sin embargo para compilar y que funcione según el artículo debí liberar la memoria de
![Terminal_610](https://user-images.githubusercontent.com/56590627/79881688-87e2c780-83bf-11ea-9b67-c44ba46615d7.png)
p1
antes de imprimir la cadena de caracteres, aporto ese detalle al artículo. Gracias por vuestra atención.