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...
#define M 3
int main(){ » int n; » float *p[M];// This is the array of pointers » 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 // Advanced point: resizing the arrays // feel free to skip this. » 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] = 0
128[1] = 0

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] = 3.14159
184
185
186
187
188
189
190
191
176[2] = 0
176[3] = 0

200
201
202
203
204
205
206
207
200[0] = 0
200[1] = 0
208
209
210
211
212
213
214
215
200[2] = 0
200[3] = 0

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

main()

368
369
370
371
372
373
374
375
n = 1855603727
?
?
?
?
376
377
378
379
380
381
382
383
p[0] = 729347668
p[1] = 3556297522
384
385
386
387
p[2] = 4013494525

main(): for()

372
373
374
375
i = 0

main(): for()

372
373
374
375
i = 0

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

The actual address of allocated memory is the
address shown plus 136614144 (0x8249100).

Show Advanced options

.

Input was:

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

Size of each vector?
New size of each vector?
                                                                                                                                                                                                                                                                       

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