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...
#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] = -1.50555e+19
128[1] = 2.2346e-39

144
145
146
147
148
149
150
151
144[0] = -5.59419e+22
144[1] = 1.35526e-38

160
161
162
163
164
165
166
167
160[0] = 3.59503e-37
160[1] = 1.0825e-38

176
177
178
179
180
181
182
183
176[0] = -1.50555e+19
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] = -5.59419e+22
200[1] = 1.35526e-38
208
209
210
211
212
213
214
215
200[2] = 0
200[3] = 0

224
225
226
227
228
229
230
231
224[0] = 3.59503e-37
224[1] = 1.0825e-38
232
233
234
235
236
237
238
239
224[2] = 0
224[3] = 0

main()

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

main(): for()

372
373
374
375
i = 0

: for()

372
373
374
375
i = 0

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

The actual address of allocated memory is the
address shown plus 138289768 (0x83E2268).

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