Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. /* Example: StructuresIndirect in CodeBlocks 2. structures as function arguments and return values 3. indirect instances using pointers */ 4. 5. #include 6. #include

1. /* Example: StructuresIndirect in CodeBlocks

2. structures as function arguments and return values

3. indirect instances using pointers */

4.

5. #include

6. #include

7. #include

8.

9. struct cplx

10. {

11. double real; /* real part */

12. double imag; /* imaginary part */

13. };

14.

15. struct cplx add(struct cplx* pa, struct cplx* pb); /* function prototype */

16.

17. int main(void)

18. {

19. struct cplx z;

20. time_t rawtime = time(NULL);

21.

22.

23. struct cplx* px= malloc(sizeof(struct cplx));

24. struct cplx* py= malloc(sizeof(struct cplx));

25.

26. px->real = 2.5;

27. px->imag = 5.0;

28. py->real = 3.2;

29. py->imag = -1.7;

30.

31.

32. z = add(px, py);

33. printf("Indirect Instance z = %4.2f + %4.2f j ", z.real, z.imag);

34. printf("Today is %s", ctime(&rawtime));

35.

36. return 0;

37. }

38.

39.

40. struct cplx add(struct cplx* pa, struct cplx* pb)

41. {

42. struct cplx c = *pa; /* can initialise an auto struct variable */

43.

44. c.real += pb->real;

45. c.imag += pb->imag;

46. return c; /* can return a struct value */

47. }

11. Which lines create instances of the structure, what are the structure names?

12. What are the structure pointer names?

13. Which lines initialize the member elements of the structures? How?

14. Which line is the prototype for a function with structure pointer parameters

15. Which lines are the function definition with structure pointer parameters

16. How are the member elements of an unamed (indirect instance) structure dereferenced (how are the values changed)?

17. How is the addition of two structures accomplished?

18. Could a pointer be returned from the function?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design

Authors: Marion Donnie Dutton Don F. Seaman

14th Edition Globel Edition

1292107634, 978-1292107639

More Books

Students also viewed these Databases questions

Question

What will you do or say to Anthony about this issue?

Answered: 1 week ago