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...
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 » 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 first vector?\n"); » scanf("%d", &n); // For variety we are making the vectors different sizes » for ( int i=0;i<m; ++i) pi=realloc(pi, (n+i)*sizeof *p[i]); // Do something else » return 0;
}
Memory

Allocated memory

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

144
145
146
147
148
149
150
151
144[0] = -4.59724e-32
144[1] = 4.71977e-39

160
161
162
163
164
165
166
167
160[0] = -3.25344e+21
160[1] = 1.28537e-38

176
177
178
179
180
181
182
183
176[0] = -5.71123e-07
176[1] = 8.72087e-40

192
193
194
195
196
197
198
199
192[0] = -4.59724e-32
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] = -3.25344e+21
216[1] = 1.28537e-38
224
225
226
227
228
229
230
231
216[2] = 0
216[3] = 0
232
233
234
235
216[4] = 0

240
241
242
243
244
245
246
247
240[0] = -5.71123e-07
240[1] = 8.72087e-40
248
249
250
251
252
253
254
255
240[2] = 0
240[3] = 0
256
257
258
259
260
261
262
263
240[4] = 0
240[5] = 0

main()

396
397
398
399
m = 200
400
401
402
403
404
405
406
407
n = -145251513
p = NULL

: for()

408
409
410
411
i = 0

main(): for()

408
409
410
411
i = 0

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

The actual address of allocated memory is the
address shown plus 145261160 (0x8A88268).

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 first vector?
                                                                                                                                                                                                                                                                       

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