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...
// 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] = 1.75848e-37
128[1] = 2.20341e-39

144
145
146
147
148
149
150
151
144[0] = 1.13984e+20
144[1] = 2.23353e-38

160
161
162
163
164
165
166
167
160[0] = -0.000160685
160[1] = 1.14236e-38

main()

296
297
298
299
300
301
302
303
n = 134536703
p = -4152352605

main(): for()

304
305
306
307
i = 0

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

The actual address of allocated memory is the
address shown plus 164991592 (0x9D59268).

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