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...
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 = 298.343353
128.str = 3836865911
136
137
138
139
128.length = 14569193

128
129
130
131
132
133
134
135
128.val = 8.4488781e+22
128.str = 3453420768
136
137
138
139
128.length = 459947

144
145
146
147
148
149
150
151
' ' ' ' ' ' ' ' 'D' '&' ' ' 't'
152
153
154
155
156
157
158
159
' ' 'b' ' ' ' ' ')' 'J' ' ' ' '
160
161
162
163
' ' 'e' ' ' '\0'

168
169
170
171
172
173
174
175
' ' 'D' ' ' ' ' ' ' ' ' ' ' ' '
176
177
178
179
180
181
182
183
' ' ' ' ' ' 'Z' ' ' ' ' ' ' ' '
184
185
186
187
188
189
190
191
' ' ' ' ' ' '#' ' ' '?' ' ' 'V'
192
193
194
195
196
197
198
199
' ' ' ' 'J' 'M' ' ' ' ' '<' ' '
200
201
202
203
204
205
206
207
' ' 'e' ' ' ' ' ' ' ' ' 'A' '\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 = -4145392848

main()

400
401
402
403
william = -4291288999

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

The actual address of allocated memory is the
address shown plus 145896024 (0x8B23258).

Show Advanced options

.
                                                                                                                                                                                                                                                                       

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