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...
// // Simple malloc demonstration // struct proj { float mass; float pos[2]; float v[2]; struct proj *next; };
struct proj* newproj(struct proj *f){
  ...
» struct proj *new; » new=malloc(sizeof *new); » new->next=f; » return new;
} int main(){
  ...
» struct proj *first=NULL; » for ( int i=0;i<4; ++i) first=newproj(first); » return 0;
}
Memory

Allocated memory

128
129
130
131
132
133
134
135
128.mass = 2.1775956e+13
128.pos[0] = -1.96413e+13
136
137
138
139
140
141
142
143
128.pos[1] = 4.58244e+35
128.v[0] = 1.27018e-13
144
145
146
147
148
149
150
151
128.v[1] = 1.03487e-07
128.next = -131947645

160
161
162
163
164
165
166
167
160.mass = -2.8079893e-12
160.pos[0] = 4.01563e-30
168
169
170
171
172
173
174
175
160.pos[1] = 1.73215e-35
160.v[0] = 52.2988
176
177
178
179
180
181
182
183
160.v[1] = -1.53645e-35
160.next = -140395898

192
193
194
195
196
197
198
199
192.mass = -0.172963992
192.pos[0] = -3.15085e-22
200
201
202
203
204
205
206
207
192.pos[1] = 3.70083e-42
192.v[0] = 0
208
209
210
211
212
213
214
215
192.v[1] = 0
192.next = NULL

224
225
226
227
228
229
230
231
224.mass = -541899.125
224.pos[0] = -3.42762e-26
232
233
234
235
236
237
238
239
224.pos[1] = 3.17008e-28
224.v[0] = 5.72764e-08
240
241
242
243
244
245
246
247
224.v[1] = 7.11098e+23
224.next = -132474161

newproj()

380
381
382
383
f = -4148333224
392
393
394
395
new = -4294212990

newproj()

380
381
382
383
f = -4148333192
392
393
394
395
new = -4294212990

newproj()

380
381
382
383
f = NULL
392
393
394
395
new = -4294212990

newproj()

380
381
382
383
f = -4148333160
392
393
394
395
new = -4294212990

main()

452
453
454
455
first = NULL

main(): for()

456
457
458
459
i = 0

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

The actual address of allocated memory is the
address shown plus 145879640 (0x8B1F258).

Show Advanced options

.

Input was:

4.7 8.1

                                                                                                                                                                                                                                                                       

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