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...
int main(){ » int m, n; » float * *p=NULL;// This will become the array of pointers » printf("How many vectors?\n"); » scanf("%d", &m); » p=xmalloc(m*sizeof *p);// Allocate the array of pointers // The rest of the code is now the same with // the variable 'm' instead of the constant 'M' » printf("Size of each vector?\n"); » scanf("%d", &n);// Find the row size » for ( int i=0;i<m; ++i) pi=xmalloc(n*sizeof *p[i]);// Allocate rows » p[0]1=3.14159; // Use p for something » printf("New size of each vector?\n"); » scanf("%d", &n);// Find new the row size » for ( int i=0;i<m; ++i) pi=realloc(pi, n*sizeof *p[i]);// Resize the rows // Do something else » 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

160
161
162
163
164
165
166
167
160[0] = 0
160[1] = 0

176
177
178
179
180
181
182
183
176[0] = 0
176[1] = 0

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

216
217
218
219
220
221
222
223
216[0] = 0
216[1] = 0
224
225
226
227
228
229
230
231
216[2] = 0
216[3] = 0

240
241
242
243
244
245
246
247
240[0] = 0
240[1] = 0
248
249
250
251
252
253
254
255
240[2] = 0
240[3] = 0

main()

388
389
390
391
m = -380541132
392
393
394
395
396
397
398
399
n = 865171284
p = NULL

main(): for()

400
401
402
403
i = 0

main(): for()

400
401
402
403
i = 0

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

The actual address of allocated memory is the
address shown plus 158277888 (0x96F2100).

Show Advanced options

.

Input was:

3 2 4 

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

Output

How many vectors?
Size of each vector?
New size of each vector?
                                                                                                                                                                                                                                                                       

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