Skip to content

Instantly share code, notes, and snippets.

@wurikiji
Last active June 22, 2017 02:25
Show Gist options
  • Save wurikiji/97b2fdb7c8270366af9b07e62e6972ef to your computer and use it in GitHub Desktop.
Save wurikiji/97b2fdb7c8270366af9b07e62e6972ef to your computer and use it in GitHub Desktop.
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
struct A{
char *s;
int i;
};
struct B{
struct A *a;
};
int w(struct B *aB){
printf("(%s)(%d)",aB->a->s, aB->a->i);
return 0;
}
int q(struct B *aB){
printf("%s", __FUNCTION__);
struct A *sA = aB->a;
printf("%s", __FUNCTION__);
sA->s = strdup("helloo");
sA->i = 12;
w(aB);
return 0;
}
void assign(struct B *aB){
aB->a = (struct A*) malloc(sizeof(struct A));
}
int main(){
struct B sB;
assign(&sB);
q(&sB);
      free(sB.a);
  return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment