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 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

printarray()

132
133
134
135
output = 212
144
145
146
147
148
149
150
151
i = -1689336
?
?
?
?
184
185
186
187
188
189
190
191
?
?
?
?
n = 4

readarray()

148
149
150
151
input = 212
160
161
162
163
164
165
166
167
i = 2
?
?
?
?
184
185
186
187
188
189
190
191
?
?
?
?
n = 4

main()

212
213
214
215
numbers[0] = -144800738
216
217
218
219
220
221
222
223
numbers[1] = 134537952
numbers[2] = 134537756
224
225
226
227
numbers[3] = 1

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

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 0xffe638ec
In readarray() the array is stored at address 0xffe638ec
The value of numbers[2] is: 45
21
33
45
67
                                                                                                                                                                                                                                                                       

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