Skip to content
EMPS intranet

Back to top
Hi!   Hi!           Start program

Try stepping through the code


  Value and type of last evaluated expression: Address of array element: Address of array elementx:  (none)

The pointer e inside move_ellipse() points to ellie inside main().

The pointer e inside calculate_area() points to ellie inside main() as it was passed the value by the calling function.

The pointer el inside read_ellipse() points to ellie inside main() so el->member refers to ellie.member.

Your browser does not support the canvas element which will make some the features unavailable.

If you are using Internet Explorer within the University of Exeter try going to the Settings menu (probably the gear shape at the top right of this page), selecting "Compatibility View settings", unchecking "Display intranet sites in Compatibility View" and reloading this page.

Code

 Header...
#define PI 3.14159265358979 typedef struct ellipse { float centre[2]; float axes[2]; float orientation; float area; }Ellipse; void calculate_area (Ellipse *el); void read_ellipse (Ellipse *el); void resize_ellipse (Ellipse *el,float scale); void move_ellipse (Ellipse *el,float dx[2]);
int main(){ » Ellipse ellie; » float moveby[2], resize; » printf("Welcome to the ellipse program\n"); » read_ellipse(&ellie); » printf("The area of the ellipse is: %f\n", ellie.area); » printf("Amount to move the ellipse?\n"); » scanf("%g %g", &moveby0, &moveby1); » move_ellipse(&ellie, moveby); » printf("Amount to resize the ellipse?\n"); » scanf("%g", &resize); » resize_ellipse(&ellie, resize); » return 0; }
...
void read_ellipse(Ellipse *el){ » printf("Centre? (x,y)\n"); » scanf("%f %f", &el->centre[0], &el->centre[1]); » printf("Length of axes ( > 0 )?\n"); » scanf("%f %f", &el->axes[0], &el->axes[1]); » printf("Orientation to the vertical?\n"); » scanf("%f", &el->orientation); » calculate_area(el);// Pass the pointer to another function }
...
void resize_ellipse(Ellipse *el,float scale){ » el->axes0*=scale; » el->axes1*=scale; » calculate_area(el); }
...
void calculate_area(Ellipse *e){ » e->area=PI*e->axes[0]*e->axes[1]; }
...
void move_ellipse(Ellipse *el,float dx[2]){ » el->centre0+=dx0; » el->centre1+=dx1; }
...
Memory

calculate_area()

128
129
130
131
e = 228

calculate_area()

144
145
146
147
e = 228

read_ellipse()

176
177
178
179
el = 228

move_ellipse()

176
177
178
179
180
181
182
183
el = 228
dx = 220

resize_ellipse()

176
177
178
179
180
181
182
183
el = 228
scale = 3.79999995

main()

216
217
218
219
220
221
222
223
resize = 2.38714847e+28
moveby[0] = -1.58221e+25
224
225
226
227
228
229
230
231
moveby[1] = 7.027e-08
ellie.centre[0] = -1.48217e+17
232
233
234
235
236
237
238
239
ellie.centre[1] = -4.49525e+33
ellie.axes[0] = 5.05323e-20
240
241
242
243
244
245
246
247
ellie.axes[1] = 1.37825e-11
ellie.orientation = 2.06185038e+24
248
249
250
251
ellie.area = -2.54576014e-25

NB: the actual memory address of each variable is the
address shown plus 4290828144 (0xFFC0D770).

.

Input was:

7.2 4.5 1.2  4.3 1.7
1.1 2.2 3.8

Show output (Before looking at the output, work out what you think it put should be and see if you are right.)

Output

Welcome to the ellipse program
Centre? (x,y)
Length of axes ( > 0 )?
Orientation to the vertical?
The area of the ellipse is: 16.210619
Amount to move the ellipse?
Amount to resize the ellipse?
                                                                                                                                                                                                                                                                       

Validate   Link-check © Copyright & disclaimer Share
Back to top