Practice12 - AddComplex Reminder complex a, b, c;...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: AddComplex Reminder complex a, b, c; printf("); scanf("%lf%lf",&(a.real),&(a.img)); printf("); scanf("%lf%lf",&(b.real),&(b.img)); c = AddComp(a,b); printf(result = %g+%gi\n",c.real,c.img); return 0; 1.0 2.0 real img a 3.0 4.0 real img b real img c AddComplex step by step complex AddComp(complex x, complex y) { complex z; z.real = x.real + y.real; z.img = x.img + y.img; return z; } 1.0 2.0 real img x 3.0 4.0 real img y real img z AddComplex step by step complex AddComp(complex x, complex y) { complex z; z.real = x.real + y.real; z.img = x.img + y.img; return z; } 1.0 2.0 real img x 3.0 4.0 real img y 6.0 real img z AddComplex step by step complex AddComp(complex x, complex y) { complex z; z.real = x.real + y.real; z.img = x.img + y.img; return z; } 1.0 2.0 real img x 3.0 4.0 real img y 4.0 6.0 real img z AddComplex step by step complex AddComp(complex x, complex y) { complex z; z.real = x.real + y.real; z.img = x.img + y.img; return z; } 1.0 2.0 real img x 3.0 4.0 real img y 4.0 6.0 real img z AddComplex step by step complex a, b, c; printf("); scanf("%lf%lf",&(a.real),&(a.img)); printf("); scanf("%lf%lf",&(b.real),&(b.img)); c = AddComp(a,b); printf(result = %g+%gi\n",c.real,c.img); return 0; 1.0 2.0 real img a 3.0 4.0 real img b 4.0 6.0 real img c AddComplex step by step complex a, b, c; printf("); scanf("%lf%lf",&(a.real),&(a.img)); printf("); scanf("%lf%lf",&(b.real),&(b.img)); c = AddComp(a,b); printf(result = %g+%gi\n",c.real,c.img); return 0; 1.0 2.0 real img a 3.0 4.0 real img b 4.0 6.0 real img c Miscellaneous structure trivia Structure members may be ordinary variable types, but also other structures and even arrays! Structures can therefore be rather large and take up a lot of space Many times we prefer to pass structures to functions by address, and not by value Thus a new copy of the structure is not created just a pointer to the existing structure More trivia Structures cannot be compared using the == operator They must be compared member by member Usually this will be done in a separate function Structures can be copied using the = operator Member-wise copy Structures containing arrays A structure member that is an array does not behave like an ordinary array When copying a structure that contains a member which is an array, the array is copied element by element Not just the address gets copied For example - array_member.c Reminder ordinary arrays cant be copied simply by using the = operator They must be copied using a loop Structures containing arrays...
View Full Document

This note was uploaded on 01/10/2010 for the course CS 463 taught by Professor Can'tsay during the Spring '09 term at Haaga - Helia University of Applied Sciences.

Page1 / 109

Practice12 - AddComplex Reminder complex a, b, c;...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online