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...
void unwise_function (double *pp,double *qq);
int main(){
  ...
» double x=17.1, y, *p, *q;// p, q are pointers » p=&x;// The value of p is now the address of x. // If we do anything with or to *p it's doing it to x: » printf(" p: %p\n", p); » printf(" *p: %g\n", *p); » y=*p;// Exactly the same as y = x; » *p=3.14159;// Exactly the same as x = 3.14159; // Now let's make p point to y: » p=&y; » *p=1.414; » q=&x;// The value of q is now the address of x » unwise_function(p, q);// The same as unwise function(&y, &x); // Now x has the value 73.2, y has the value 2.5 » printf("x: %f y: %f\n", x, y);
} void unwise_function(double *p2,double *q2){
  ...
» *p2=2.5; » *q2=73.2;
}
Memory

unwise_function()

128
129
130
131
132
133
134
135
p2 = 176
q2 = 168

main()

160
161
162
163
164
165
166
167
p = -143435289
q = -142043488
168
169
170
171
172
173
174
175
x = 17.1
176
177
178
179
180
181
182
183
y = 4.93746668e-270

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

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

 p: 0xffe34a08
 *p: 17.1
x: 73.200000 y: 2.500000
                                                                                                                                                                                                                                                                       

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