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...
// // Permute a string from p to the end and print out each // permutation starting from string start (which never changes) // Does not avoid duplicates //
void permute(char *string_start,char *p){
  ...
» char *swap; » if (p1==0) {// End of string - just print it » printf("%s\n", string_start); » return ; } // permute the string one shorter than this » permute(string_start, p+1); // Go along the string, swapping each element in turn with p » for (swap=p+1; *swap; ++swap) { » char tmp=*swap; » *swap=*p;// swap » *p=tmp; » permute(string_start, p+1); » *p=*swap;// swap back » *swap=tmp; }
} int main(int argc,char * *argv){
  ...
» char string[8]; » while (1) { » printf("String to permute?\n"); » if (scanf("%7s", string)<1) break; » printf("Permutations of %s:\n", string); » permute(string, string); } » return 0;
}
Memory

permute-3()

128
129
130
131
132
133
134
135
p = 382
string_start = 380
144
145
146
147
swap = 256

permute-3()

128
129
130
131
132
133
134
135
p = 382
string_start = 380
144
145
146
147
swap = 256

permute-3()

128
129
130
131
132
133
134
135
p = 382
string_start = 380
144
145
146
147
swap = 256

permute-3()

128
129
130
131
132
133
134
135
p = 382
string_start = 380
144
145
146
147
swap = 256

permute-3()

128
129
130
131
132
133
134
135
p = 382
string_start = 380
144
145
146
147
swap = 256

permute-3()

128
129
130
131
132
133
134
135
p = 382
string_start = 380
144
145
146
147
swap = 256

permute-2()

208
209
210
211
212
213
214
215
p = 381
string_start = 380
224
225
226
227
swap = 336

permute-2()

208
209
210
211
212
213
214
215
p = 381
string_start = 380
224
225
226
227
swap = 336

permute-2()

208
209
210
211
212
213
214
215
p = 381
string_start = 380
224
225
226
227
swap = 336

permute-2(): for() {...}

223
?

permute-2(): for() {...}-2

223
?

permute-2(): for() {...}-2

223
?

permute()

288
289
290
291
292
293
294
295
p = 380
string_start = 380
304
305
306
307
swap = 400

main(): for() {...}

303
?

: for() {...}

303
?

main()

372
373
374
375
argv = 828
376
377
378
379
380
381
382
383
?
?
?
?
string = 'v' ' ' ' ' ' '
384
385
386
387
388
389
390
391
' ' '\0' '\0' '\0'
?
?
?
?
408
409
410
411
argc = 1

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

Show Advanced options

.

Input was:

abc 

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

Output

String to permute?
Permutations of abc:
abc
acb
bac
bca
cba
cab
String to permute?
                                                                                                                                                                                                                                                                       

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