结构体指针

#include <stdio.h>
#include <string.h>

typedef struct
{
	int foo_test;
} foo;

typedef struct 
{
	foo  *goo_test;
} goo;

typedef struct hoo
{
	goo *hoo_test;
} hoo;

void test(hoo *h, int val)
{
	h->hoo_test->goo_test->foo_test = val;
}

int main(void)
{
	hoo h;
	int val = 3;
	
	foo f;
	goo g;
	
	g.goo_test = &f;
	h.hoo_test = &g;
	
	//h = (hoo *)malloc(sizeof(hoo));
	
	printf("foo f Addr: %#p\r\n", &f);
	printf("goo g Addr: %#p\r\n", &g);
	printf("hoo h Addr: %#p\r\n", &h);
	test(&h, val);
	printf("h.hoo_test Addr %#p\r\n", &h.hoo_test);
	printf("h.hoo_test->goo_test Addr %#p\r\n", &h.hoo_test->goo_test);
	printf("h.hoo_test->goo_test->foo_test Addr %#p\r\n", &h.hoo_test->goo_test->foo_test);
	printf("h.hoo_test->goo_test->foo_test valu %d \r\n", h.hoo_test->goo_test->foo_test);
	return 0;
} 

 


版权声明:本文为shao15232原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。