Skip to content

Instantly share code, notes, and snippets.

@henrybear327
Last active March 16, 2017 13:33
Show Gist options
  • Save henrybear327/c86d993b10af88de273a54b0bb5db738 to your computer and use it in GitHub Desktop.
Save henrybear327/c86d993b10af88de273a54b0bb5db738 to your computer and use it in GitHub Desktop.
struct pointer.cpp
#include <stdio.h>
struct data {
int a;
};
typedef struct data2 {
int aa;
} hello; //以後不用打struct data2,直接叫他hello就好了!!
void foo(struct data* ptr)
{
printf("ptr holds value %p.\n", ptr);
ptr->a = 2;
printf("value changed to 2\n\n");
}
int main()
{
struct data var;
var.a = 1;
printf("var address is %p.\nvar.a is %d\n\n", &var, var.a);
foo(&var);
printf("var address is %p.\nvar.a is %d\n\n", &var, var.a);
// ==================
hello newVar;
newVar.aa = 2000;
printf("newVar.a is %d\n", newVar.aa);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment