Last active
March 16, 2017 13:33
-
-
Save henrybear327/c86d993b10af88de273a54b0bb5db738 to your computer and use it in GitHub Desktop.
struct pointer.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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