複數加法2

 avatar
user_3763047219
c_cpp
2 years ago
801 B
1
Indexable
Never
// 2+3i real imag

struct complex {
	int real;
	int imag;
	int unuse[10000];
};

//結構型態的宣告 傳進兩個結構 回傳一個結構 
void add_complex(struct complex *a, struct complex *b, struct complex *c)
	//*a *b *c都是記憶體位址 指向外面的abc
{
	printf("a pointer value = %p\n", a);
	printf("a pointer = %p\n", &a);
	(*c).real = (*a).real + (*b).real;
	(*c).imag = (*a).imag + (*b).imag;
	//return c;不用retuen c 了 直接存到c裡面
	printf("%d\n", sizeof(a));
	//傳進去的a只用4bytes 之前的方法要傳進四萬多bytes
}

int main()
{
	struct complex a = { 1,3 }, b = { 5, 2 }, c;
	//c = a + b;
	printf("%d\n", sizeof(struct complex));
	add_complex(&a, &b, &c);//放abc三個結構的位址
	//print_complex(c);
	//c = a * b;

}