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...
// // Demonstrate passing an array to a function // #define VALUES 4
void readarray(int input[],int n){ » int i; » printf("In readarray() the array is stored at address %p\n", input); » for (i=0; i<n; ++i) { » scanf("%d\n", &input[i]); } }
...
void printarray(int output[],int n){ » int i; » for (i=0; i<n; ++i) { » printf("%d\n", outputi); } }
...
int main(){ » int numbers[VALUES]; » printf("In main() the array is stored at address %p\n", numbers); » readarray(numbers, VALUES); » printf("The value of numbers[2] is: %d\n", numbers2); » printarray(numbers, VALUES); » return 0; }
...
Memory

readarray()

132
133
134
135
input = 196
144
145
146
147
148
149
150
151
i = 2
?
?
?
?
168
169
170
171
172
173
174
175
?
?
?
?
n = 4

printarray()

132
133
134
135
output = 196
144
145
146
147
148
149
150
151
i = 2
?
?
?
?
168
169
170
171
172
173
174
175
?
?
?
?
n = 4

main()

196
197
198
199
numbers[0] = 527344087
200
201
202
203
204
205
206
207
numbers[1] = 762497557
numbers[2] = 1741885073
208
209
210
211
numbers[3] = -1767714002

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

Show Advanced options

.

Input was:

21 33 45 67 

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

Output

In main() the array is stored at address 0xffc0648c
In readarray() the array is stored at address 0xffc0648c
The value of numbers[2] is: 45
21
33
45
67
                                                                                                                                                                                                                                                                       

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