Skip to content
EMPS intranet

Back to top
Hi!   Hi!           Start main()

Try stepping through the code


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

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(){
  ...
» float moveby[2], resize; » Ellipse *e=NULL; » e=malloc(sizeof *e); » if (e==NULL) { » fprintf(stderr, "Out of memory\n"); » exit(99); } » printf("Welcome to the ellipse program\n"); » read_ellipse(e); » printf("The area of the ellipse is: %f\n", e->area); » printf("Amount to move the ellipse?\n"); » scanf("%g %g", &moveby0, &moveby1); » move_ellipse(e, moveby); » printf("Amount to resize the ellipse?\n"); » scanf("%g", &resize); » resize_ellipse(e, 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
} // Resize an ellipse by the same scaling factor in each dimension. void resize_ellipse(Ellipse *el,float scale){
  ...
» el->axes0*=scale; » el->axes1*=scale; » calculate_area(el);
} // Calculate the area of an ellipse and save it in the structure 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

Allocated memory

128
129
130
131
132
133
134
135
128.centre[0] = 1.27141e+07
128.centre[1] = 3.55248e-19
136
137
138
139
140
141
142
143
128.axes[0] = -1.59008e+19
128.axes[1] = -2.94097e+25
144
145
146
147
148
149
150
151
128.orientation = -12498.376
128.area = 2.33788264e-38

calculate_area()

280
281
282
283
e = -4127331648

calculate_area()

280
281
282
283
e = -4127331648

resize_ellipse()

328
329
330
331
332
333
334
335
el = -4127331648
scale = 3.79999995

read_ellipse()

328
329
330
331
el = -4127331648

move_ellipse()

328
329
330
331
332
333
334
335
el = -4127331648
dx = 380

main()

372
373
374
375
resize = -4.37498842e+33
376
377
378
379
380
381
382
383
e = NULL
moveby[0] = 4.0014e-34
384
385
386
387
moveby[1] = 1.4013e-45

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

The actual address of allocated memory is the
address shown plus 159261272 (0x97E2258).

Show Advanced options

.

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