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...
// Flawed attempt at multiple memory allocations #define M 3
int main(){ » int n; » float *p; » printf("Size of each vector?\n"); » scanf("%d", &n);// Find the row size » for ( int i=0;i<M; ++i) p=xmalloc(n*sizeof *p);// Allocate rows // Do something useful... » 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

main()

296
297
298
299
300
301
302
303
n = 761222277
p = -2551974503

main(): for()

304
305
306
307
i = 0

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

The actual address of allocated memory is the
address shown plus 148902144 (0x8E01100).

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?
                                                                                                                                                                                                                                                                       

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