Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <string.h>
- /*
- void GetMemory(char *p, int num)
- {
- p = (char *)malloc(sizeof(char) * num);
- }
- int main()
- {
- char *str = NULL;
- GetMemory(str, 100);
- // str is still NULL
- strcpy(str, "hello");
- return 0;
- }
- */
- void GetMemory(char **p, int num)
- {
- *p = (char *)malloc(sizeof(char) * num);
- }
- int main()
- {
- char *str = NULL;
- GetMemory(&str, 100);
- strcpy(str, "hello");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement