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...
// 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] =
128[1] =
136
137
138
139
128[2] =

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

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

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

new2dint()

340
341
342
343
p = 868
344
345
346
347
348
349
350
351
i = -6227368
?
?
?
?
384
385
386
387
388
389
390
391
m = 3
n = 4

free2dint()

348
349
350
351
p = -4146276128
384
385
386
387
388
389
390
391
?
?
?
?
m = 3

free2dint(): for()

360
361
362
363
i = 0

main()

416
417
418
419
420
421
422
423
p = NULL
m = 1742143121
424
425
426
427
n = -1767505106

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

The actual address of allocated memory is the
address shown plus 142463232 (0x87DD100).

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