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...
// Allocate a 2-D array of ints
int * * new2dint(int m,int n){
  ...
» int * *p; » int i; » p=xmalloc(m*sizeof *p); » for (i=0; i<m; ++i) pi=malloc(n*sizeof *p[i]); » return p;
} // Free a 2-D array of ints void free2dint(int * *p,int m){
  ...
» for ( int i=0;i<m; ++i) free(pi); » free(p);
} int main(){
  ...
» int * *p=NULL; » int m, n; » do{ » printf("Sizes of array (>0)?\n"); » scanf("%i %i", &m, &n); }while (n<=0||m<=0) ; » p=new2dint(m, n); » p[0]1=17; » p[m-1]0=13; » p[m-1](n-1)=10; » free2dint(p, m);// To demonstrate » return 0;
}
Memory

Allocated memory

128
129
130
131
132
133
134
135
128[0] = 3701782522
128[1] = 3001597281
136
137
138
139
128[2] =

144
145
146
147
148
149
150
151
144[0] = 425993989
144[1] = 1613746743
152
153
154
155
156
157
158
159
144[2] = -1890100563
144[3] = 7687554

168
169
170
171
172
173
174
175
168[0] = -1301690611
168[1] = 1120662322
176
177
178
179
180
181
182
183
168[2] = -1101131320
168[3] = 12978481

192
193
194
195
196
197
198
199
192[0] = 1943279708
192[1] = -1296079330
200
201
202
203
204
205
206
207
192[2] = -2078834997
192[3] = 7045311

free2dint()

340
341
342
343
p = -4155115840
392
393
394
395
396
397
398
399
?
?
?
?
m = 3

new2dint()

348
349
350
351
p = -4155132960
352
353
354
355
356
357
358
359
i = -3473928
?
?
?
?
392
393
394
395
396
397
398
399
m = 3
n = 4

free2dint(): for()

352
353
354
355
i = 0

main()

424
425
426
427
428
429
430
431
p = NULL
m = -143024128
432
433
434
435
n = 1

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

The actual address of allocated memory is the
address shown plus 136376936 (0x820F268).

Show Advanced options

.

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

Sizes of array (>0)?
                                                                                                                                                                                                                                                                       

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