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)

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...
// Shrink or extend a symmetric array
float * * resizesymarray(float * *p,int oldm,int newm){ » int i, siz; » float *dat=NULL; » siz=newm*(newm+1)/2; » if (p!=NULL) dat=p0; » dat=realloc(dat, siz*sizeof *dat); » p=realloc(p, newm*sizeof *p); » for (i=0; i<newm; ++i) pi=dat+i*(i+1)/2; » return p; }
...
// Create a new symmetric array float * * newsymarray(int m){ » return resizesymarray(NULL, 0, m); }
...
// Free a symmetric array void freesymarray(float * *p,int m){ » resizesymarray(p, m, 0); }
...
int main(){ » float * *p=NULL; » int n, newn; » printf("Size of array (>0)?\n"); » scanf("%i", &n); » p=newsymarray(n); » p[0]0=17; » p[n-1]1=11.3; » printf("New size of array (>0)?\n"); » scanf("%i", &newn); » p=resizesymarray(p, n, newn); // Do stuff here » freesymarray(p, newn); // Do more stuff not requiring p » return 0; }
...
Memory

Allocated memory

128
129
130
131
132
133
134
135
128[0] = 0
128[1] = 0
136
137
138
139
140
141
142
143
128[2] = 0
128[3] = 0
144
145
146
147
148
149
150
151
128[4] = 0
128[5] = 0

160
161
162
163
164
165
166
167
160[0] =
160[1] =
168
169
170
171
160[2] =

176
177
178
179
180
181
182
183
176[0] = 17
176[1] = 0
184
185
186
187
188
189
190
191
176[2] = 0
176[3] = 0
192
193
194
195
196
197
198
199
176[4] = 11.3
176[5] = 0
200
201
202
203
204
205
206
207
176[6] = 0
176[7] = 0
208
209
210
211
212
213
214
215
176[8] = 0
176[9] = 0

224
225
226
227
228
229
230
231
224[0] = 128
224[1] = 132
232
233
234
235
236
237
238
239
224[2] = 140
224[3] =

resizesymarray()

372
373
374
375
p = NULL
376
377
378
379
380
381
382
383
i = 1
siz = -3111100
384
385
386
387
388
389
390
391
dat = NULL
?
?
?
?
424
425
426
427
428
429
430
431
?
?
?
?
oldm = 0
432
433
434
435
newm = 3

resizesymarray()

372
373
374
375
p = -4148949416
376
377
378
379
380
381
382
383
i = 4
siz = -3111100
384
385
386
387
388
389
390
391
dat = NULL
?
?
?
?
424
425
426
427
428
429
430
431
?
?
?
?
oldm = 4
432
433
434
435
newm = 0

resizesymarray()

420
421
422
423
p = -4148949480
424
425
426
427
428
429
430
431
i = 4
siz = -3111100
432
433
434
435
436
437
438
439
dat = NULL
?
?
?
?
472
473
474
475
476
477
478
479
?
?
?
?
oldm = 3
480
481
482
483
newm = 4

newsymarray()

472
473
474
475
m = 3

freesymarray()

472
473
474
475
476
477
478
479
p = -4148949416
m = 4

main()

504
505
506
507
508
509
510
511
p = NULL
n = 1741844113
512
513
514
515
newn = -1767509202

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

The actual address of allocated memory is the
address shown plus 142905600 (0x8849100).

.

Input was:

3 4

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

Output

Size of array (>0)?
New size of array (>0)?
                                                                                                                                                                                                                                                                       

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