C語言面試題---指標篇(二)
阿新 • • 發佈:2018-12-16
- # include <stdio.h>
- # include <stdlib.h>
- # include <string.h>
- void getMemory( char **p , int num)
- {
- *p = malloc(num);
- }
- int main()
- {
- char * str = NULL;
- getMemory(&str,100);
- strcpy(str,"hello");
- free(str);
- if(str != NULL)
- {
- printf("%p\n",str);
- }
- return 0;
- }