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...
#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
called = 0

compared()

264
265
266
267
268
269
270
271
p2 = 840
p1 = 836
272
273
274
275
276
277
278
279
?
?
?
?
x1 = 3
280
281
282
283
x2 = 5

compared()

264
265
266
267
268
269
270
271
p2 = 832
p1 = 828
272
273
274
275
276
277
278
279
?
?
?
?
x1 = 8
280
281
282
283
x2 = 6

compared()

264
265
266
267
268
269
270
271
p2 = 856
p1 = 852
272
273
274
275
276
277
278
279
?
?
?
?
x1 = 4
280
281
282
283
x2 = 2

compared()

264
265
266
267
268
269
270
271
p2 = 848
p1 = 844
272
273
274
275
276
277
278
279
?
?
?
?
x1 = 7
280
281
282
283
x2 = 1

compared()

344
345
346
347
348
349
350
351
p2 = 852
p1 = 848
352
353
354
355
356
357
358
359
?
?
?
?
x1 = 7
360
361
362
363
x2 = 2

compared()

344
345
346
347
348
349
350
351
p2 = 836
p1 = 828
352
353
354
355
356
357
358
359
?
?
?
?
x1 = 6
360
361
362
363
x2 = 3

compared()

344
345
346
347
348
349
350
351
p2 = 852
p1 = 844
352
353
354
355
356
357
358
359
?
?
?
?
x1 = 1
360
361
362
363
x2 = 2

compared()

344
345
346
347
348
349
350
351
p2 = 856
p1 = 848
352
353
354
355
356
357
358
359
?
?
?
?
x1 = 7
360
361
362
363
x2 = 4

compared()

344
345
346
347
348
349
350
351
p2 = 840
p1 = 828
352
353
354
355
356
357
358
359
?
?
?
?
x1 = 6
360
361
362
363
x2 = 5

compared()

424
425
426
427
428
429
430
431
p2 = 856
p1 = 832
432
433
434
435
436
437
438
439
?
?
?
?
x1 = 5
440
441
442
443
x2 = 7

compared()

424
425
426
427
428
429
430
431
p2 = 856
p1 = 840
432
433
434
435
436
437
438
439
?
?
?
?
x1 = 8
440
441
442
443
x2 = 7

compared()

424
425
426
427
428
429
430
431
p2 = 852
p1 = 828
432
433
434
435
436
437
438
439
?
?
?
?
x1 = 3
440
441
442
443
x2 = 4

compared()

424
425
426
427
428
429
430
431
p2 = 852
p1 = 832
432
433
434
435
436
437
438
439
?
?
?
?
x1 = 5
440
441
442
443
x2 = 4

compared()

424
425
426
427
428
429
430
431
p2 = 856
p1 = 836
432
433
434
435
436
437
438
439
?
?
?
?
x1 = 6
440
441
442
443
x2 = 7

compared()

424
425
426
427
428
429
430
431
p2 = 844
p1 = 828
432
433
434
435
436
437
438
439
?
?
?
?
x1 = 3
440
441
442
443
x2 = 1

compared()

424
425
426
427
428
429
430
431
p2 = 848
p1 = 828
432
433
434
435
436
437
438
439
?
?
?
?
x1 = 3
440
441
442
443
x2 = 2

compared(): for()

824
825
826
827
i = 0

main()

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

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

.
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