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...
// // Return base to the power of exponent. // If base == zero and exponent < zero, // print a warning and return zero //
double mypow(double base,int exponent){ » double result=1.0; » if (base==0.0&&exponent<0) { » printf("WARNING: mypow called with zero base and negative exponent\n"); » return 0.0; } » while (exponent>0) { » result*=base; » --exponent; } » while (exponent<0) { » result/=base; » ++exponent; } » return result; }
...
int main(){ » double result;/* The same name as inside mypow() */ » mypow(7.2, 4); » printf("7.2 to the power 4 is %g\n", result);/* Wrong! */ » return 0; }
...
Memory

mypow()

128
129
130
131
132
133
134
135
base = 7.2
136
137
138
139
140
141
142
143
result = 1
176
177
178
179
exponent = 4

main()

184
185
186
187
188
189
190
191
result = 2.24517722e+192

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

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

7.2 to the power 4 is 2.24518e+192
                                                                                                                                                                                                                                                                       

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