其实还有一种方法可以不用双重指针。方法如下:
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- void test(int *p)
- {
- *p = malloc(100);
- printf("p = %p \n",(void*)*p);
- }
- int main()
- {
- int p = 0;
- test(&p);
- printf("p = %p \n",(void *)p);
- return 0;
- }
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int test()
- {
- return malloc(100);
- }
- int main()
- {
- int p = 0;
- p = test();
- printf("p = %p \n",(void *)p);
- return 0;
- }