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...
// static demonstration
double addup(double k){
  ...
» static int called; » static double sum; » sum+=k; » printf("k is %g new sum is %f\n", k, sum); » printf("The function has been called %d times\n", ++called); » return sum;
} int main(){
  ...
» int i, max=5; » double mysum; » for (i=1; i<=max; ++i) mysum=addup(sqrt(i)); » printf("The sum of the square roots of 1 to %d is %g\n", max, mysum); » return 0;
}
Memory

Static variables

128
129
130
131
132
133
134
135
addup:
called =
0
?
?
?
?
136
137
138
139
140
141
142
143
addup:
sum =
0

addup()

272
273
274
275
276
277
278
279
k = 1.73205081

addup()

272
273
274
275
276
277
278
279
k = 2.23606798

addup()

272
273
274
275
276
277
278
279
k = 2

addup()

272
273
274
275
276
277
278
279
k = 1.41421356

addup()

272
273
274
275
276
277
278
279
k = 1

main()

336
337
338
339
340
341
342
343
i = 1
max = 5
344
345
346
347
348
349
350
351
mysum = 4.93796491e-270

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

Show Advanced options

.
Show output (Before looking at the output, work out what you think it put should be and see if you are right.)

Output

k is 1 new sum is 1.000000
The function has been called 1 times
k is 1.41421 new sum is 2.414214
The function has been called 2 times
k is 1.73205 new sum is 4.146264
The function has been called 3 times
k is 2 new sum is 6.146264
The function has been called 4 times
k is 2.23607 new sum is 8.382332
The function has been called 5 times
The sum of the square roots of 1 to 5 is 8.38233
                                                                                                                                                                                                                                                                       

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