Skip to content

Instantly share code, notes, and snippets.

@liweinan
Created April 16, 2018 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liweinan/7b699c7df82f9fc9660b715a41d3583e to your computer and use it in GitHub Desktop.
Save liweinan/7b699c7df82f9fc9660b715a41d3583e to your computer and use it in GitHub Desktop.
把ptr作为reference传递
#include <stdio.h>
int foo(void *addr, void **ptr) {
*ptr = addr;
}
int main() {
int x = 42;
int y = 66;
int *p;
p = &x;
foo(&y, &p);
printf("*p: %d\n", *p);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment