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...
#define N 8
int compared(const void *p1,const void *p2){
  ...
» static int called; » » int x1=*(int *)p1, x2=*(int *)p2; » ++called; » if (x1<x2) return -1; » return x1>x2;
} int main(){
  ...
» int x[N]={8,6,3,5,7,1,4,2}; » qsort(x, N, sizeof *x, compared); » » for ( int i=0;i<N; ++i) printf("%d\n", xi); » return 0;
}
Memory

Static variables

128
129
130
131
compared:
called =
0

compared()

260
261
262
263
264
265
266
267
p2 = 828
p1 = 824
268
269
270
271
272
273
274
275
?
?
?
?
x1 = 8
276
277
278
279
x2 = 6

compared()

260
261
262
263
264
265
266
267
p2 = 844
p1 = 840
268
269
270
271
272
273
274
275
?
?
?
?
x1 = 7
276
277
278
279
x2 = 1

compared()

260
261
262
263
264
265
266
267
p2 = 852
p1 = 848
268
269
270
271
272
273
274
275
?
?
?
?
x1 = 4
276
277
278
279
x2 = 2

compared()

260
261
262
263
264
265
266
267
p2 = 836
p1 = 832
268
269
270
271
272
273
274
275
?
?
?
?
x1 = 3
276
277
278
279
x2 = 5

compared()

340
341
342
343
344
345
346
347
p2 = 848
p1 = 840
348
349
350
351
352
353
354
355
?
?
?
?
x1 = 1
356
357
358
359
x2 = 2

compared()

340
341
342
343
344
345
346
347
p2 = 832
p1 = 824
348
349
350
351
352
353
354
355
?
?
?
?
x1 = 6
356
357
358
359
x2 = 3

compared()

340
341
342
343
344
345
346
347
p2 = 848
p1 = 844
348
349
350
351
352
353
354
355
?
?
?
?
x1 = 7
356
357
358
359
x2 = 2

compared()

340
341
342
343
344
345
346
347
p2 = 852
p1 = 844
348
349
350
351
352
353
354
355
?
?
?
?
x1 = 7
356
357
358
359
x2 = 4

compared()

340
341
342
343
344
345
346
347
p2 = 836
p1 = 824
348
349
350
351
352
353
354
355
?
?
?
?
x1 = 6
356
357
358
359
x2 = 5

compared()

420
421
422
423
424
425
426
427
p2 = 852
p1 = 836
428
429
430
431
432
433
434
435
?
?
?
?
x1 = 8
436
437
438
439
x2 = 7

compared()

420
421
422
423
424
425
426
427
p2 = 852
p1 = 832
428
429
430
431
432
433
434
435
?
?
?
?
x1 = 6
436
437
438
439
x2 = 7

compared()

420
421
422
423
424
425
426
427
p2 = 852
p1 = 828
428
429
430
431
432
433
434
435
?
?
?
?
x1 = 5
436
437
438
439
x2 = 7

compared()

420
421
422
423
424
425
426
427
p2 = 844
p1 = 824
428
429
430
431
432
433
434
435
?
?
?
?
x1 = 3
436
437
438
439
x2 = 2

compared()

420
421
422
423
424
425
426
427
p2 = 848
p1 = 828
428
429
430
431
432
433
434
435
?
?
?
?
x1 = 5
436
437
438
439
x2 = 4

compared()

420
421
422
423
424
425
426
427
p2 = 840
p1 = 824
428
429
430
431
432
433
434
435
?
?
?
?
x1 = 3
436
437
438
439
x2 = 1

compared()

420
421
422
423
424
425
426
427
p2 = 848
p1 = 824
428
429
430
431
432
433
434
435
?
?
?
?
x1 = 3
436
437
438
439
x2 = 4

main(): for()

820
821
822
823
i = 0

main()

824
825
826
827
828
829
830
831
x[0] = 8
x[1] = 6
832
833
834
835
836
837
838
839
x[2] = 3
x[3] = 5
840
841
842
843
844
845
846
847
x[4] = 7
x[5] = 1
848
849
850
851
852
853
854
855
x[6] = 4
x[7] = 2

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

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

Output

1
2
3
4
5
6
7
8
                                                                                                                                                                                                                                                                       

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