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

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

View Full Document Right Arrow Icon
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 first. (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;
Background image of page 1

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

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

This note was uploaded on 01/14/2012 for the course CGS 3460 taught by Professor Staff during the Summer '08 term at University of Florida.

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 Right Arrow Icon
Ask a homework question - tutors are online