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...
// Demonstrate prototypes and local variables // Function prototype double mypow (double base,int exponent);
int main(){
  ...
» double base=2; » int exponent=3; » double pow1, pow2; » pow1=mypow(2.0, 3); » pow2=mypow(base, exponent);// Surely the computer will take the hint! » printf("power is %f, exponent is %d\n", pow2, exponent);
} // // 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) {// Or fabs(base) < 1e-50 » 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;
}

Data

mypow()

base (double)   result (double)
128   136
2
  
1
exponent (int)
176
3

mypow()

base (double)   result (double)
128   136
2
  
1
exponent (int)
176
3

main()

exponent (int)   base (double)
212   216
3
  
2
pow1 (double)   pow2 (double)
224   232
-9.53747773e+266
  
4.93986398e-270

Memory

mypow()

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

mypow()

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

main()

212
213
214
215
exponent = 3
216
217
218
219
220
221
222
223
base = 2
224
225
226
227
228
229
230
231
pow1 = -9.53747773e+266
232
233
234
235
236
237
238
239
pow2 = 4.93986398e-270

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

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

power is 8.000000, exponent is 3
                                                                                                                                                                                                                                                                       

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