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...
typedef struct wotsit { float val; char *str; int length; }Wotsit; void freewotsit (Wotsit *w);
Wotsit* newwotsit(int len){ » Wotsit *w; » w=xmalloc(sizeof *w); » w->length=len; » w->val=0; » w->str=xmalloc(w->length); » return w; }
...
int main(){ » Wotsit *william; » william=newwotsit(20); » snprintf(william->str, william->length, "Hello, world\n"); // Note how snprintf() safely truncated the string » snprintf(william->str, william->length, "This buffer is %d bytes long\n", william->length); // Note how snprintf() safely truncated the string » freewotsit(william); » william=newwotsit(40); » snprintf(william->str, william->length, "This buffer is %d bytes long\n", william->length); » return 0; }
...
void freewotsit(Wotsit *w){ » free(w->str); » free(w); }
...
Memory

Allocated memory

128
129
130
131
132
133
134
135
128.val = -3.48138667e+15
128.str = 1094632212
136
137
138
139
128.length = 1235222054

128
129
130
131
132
133
134
135
128.val = 0
128.str = 144
136
137
138
139
128.length = 20

144
145
146
147
148
149
150
151
' ' 's' ' ' '#' ' ' ' ' ' ' 'B'
152
153
154
155
156
157
158
159
' ' ' ' ' ' ' ' ' ' ' ' '3' ' '
160
161
162
163
' ' ' ' 'R' '<'

168
169
170
171
172
173
174
175
'p' 'o' 'p' ' ' '4' ' ' '0'
?

newwotsit()

336
337
338
339
340
341
342
343
w = 432
?
?
?
?
376
377
378
379
len = 20

newwotsit()

336
337
338
339
340
341
342
343
w = 432
?
?
?
?
376
377
378
379
len = 40

freewotsit()

376
377
378
379
w = -4146895960

main()

400
401
402
403
william = -142707659

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

The actual address of allocated memory is the
address shown plus 145920240 (0x8B290F0).

Show Advanced options

.
                                                                                                                                                                                                                                                                       

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