{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# quiz4_answers - Programming Using C Quiz 4 Name 1[50p...

This preview shows pages 1–2. Sign up to view the full content.

Programming Using C Quiz 4 Name: 1. [50 p ] Consider the following declarations: typedef struct { enum {RECTANGLE, CIRCLE} shape_kind; struct point center; union { struct { double height, width; } rectangle; struct { double radius; } circle; } u; } Shape; Shape s, *p; (a) [5 p ] Write an appropriate declaration for point, which represents the coordinates of a point in 2D. Answer: struct point{ double x,y; }; Indicate which of the following statements are legal, and show how to repair the ones that aren’t.Assume that for each statement, the statements that precede it are executed ﬁrst. (b) [5 p ] s.shape kind = RECTANGLE Answer: correct (c) [5 p ] printf(“%s”, s.shape kind); Answer: printf(“%d”, s.shape kind); (d) [5 p ] s.center.x = 10.0; Answer: correct (e) [5 p ] s.height = 25.0; Answer: s.u.rectangle.height = 25.0; (f) [5 p ] s.u.circle = 5.0; Answer: s.u.circle.radius = 5.0; (g) [5 p ] p = malloc(sizeof(union u)); Answer: p = malloc(sizeof(Shape)); (h) [5 p ] p.shape kind = CIRCLE;

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 3

quiz4_answers - Programming Using C Quiz 4 Name 1[50p...

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

View Full Document
Ask a homework question - tutors are online