Trace

int list []={15,81,61,38,93,40,13}
for{int p=0;p<5;p++}

{if (list[p]<40)
list [p] +=5;
else
list [p]+=2;
}

for(int q=6 ;q>=0;q––)
{cout<<list[q] <<" " ;
}

Please help me to trace the output for this.
Breakpoint 1, main () at trace.cc:7
7	    int list[] = {15,81,61,38,93,40,13};
(gdb) n              
9	    for(int p=0;p<5;p++)
1: list = {15, 81, 61, 38, 93, 40, 13}
(gdb) display list[p]
2: list[p] = 15
(gdb) display p      
3: p = 0
(gdb) n
11	        if (list[p]<40)
3: p = 0
2: list[p] = 15
1: list = {15, 81, 61, 38, 93, 40, 13}
(gdb) 
12	            list[p] +=5;
3: p = 0
2: list[p] = 15
1: list = {15, 81, 61, 38, 93, 40, 13}
(gdb) 
9	    for(int p=0;p<5;p++)
3: p = 0
2: list[p] = 20
1: list = {20, 81, 61, 38, 93, 40, 13}
(gdb) 
11	        if (list[p]<40)
3: p = 1
2: list[p] = 81
1: list = {20, 81, 61, 38, 93, 40, 13}
(gdb) 
14	            list[p]+=2;
3: p = 1
2: list[p] = 81
1: list = {20, 81, 61, 38, 93, 40, 13}
(gdb) 
9	    for(int p=0;p<5;p++)
3: p = 1
2: list[p] = 83
1: list = {20, 83, 61, 38, 93, 40, 13}
(gdb) 
11	        if (list[p]<40)
3: p = 2
2: list[p] = 61
1: list = {20, 83, 61, 38, 93, 40, 13}
(gdb) 
14	            list[p]+=2;
3: p = 2
2: list[p] = 61
1: list = {20, 83, 61, 38, 93, 40, 13}
(gdb) 
9	    for(int p=0;p<5;p++)
3: p = 2
2: list[p] = 63
1: list = {20, 83, 63, 38, 93, 40, 13}
(gdb) 
11	        if (list[p]<40)
3: p = 3
2: list[p] = 38
1: list = {20, 83, 63, 38, 93, 40, 13}
(gdb) 
12	            list[p] +=5;
3: p = 3
2: list[p] = 38
1: list = {20, 83, 63, 38, 93, 40, 13}
(gdb) 
9	    for(int p=0;p<5;p++)
3: p = 3
2: list[p] = 43
1: list = {20, 83, 63, 43, 93, 40, 13}
(gdb) 
11	        if (list[p]<40)
3: p = 4
2: list[p] = 93
1: list = {20, 83, 63, 43, 93, 40, 13}
(gdb) 
14	            list[p]+=2;
3: p = 4
2: list[p] = 93
1: list = {20, 83, 63, 43, 93, 40, 13}
(gdb) 
9	    for(int p=0;p<5;p++)
3: p = 4
2: list[p] = 95
1: list = {20, 83, 63, 43, 95, 40, 13}
(gdb) 
17	    for(int q=6;q>=0;q--)
1: list = {20, 83, 63, 43, 95, 40, 13}
(gdb) 
19	        cout<<list[q] <<" " ;
1: list = {20, 83, 63, 43, 95, 40, 13}
(gdb) 
17	    for(int q=6;q>=0;q--)
1: list = {20, 83, 63, 43, 95, 40, 13}
(gdb) 
19	        cout<<list[q] <<" " ;
1: list = {20, 83, 63, 43, 95, 40, 13}
(gdb) 
17	    for(int q=6;q>=0;q--)
1: list = {20, 83, 63, 43, 95, 40, 13}
(gdb) 
19	        cout<<list[q] <<" " ;
1: list = {20, 83, 63, 43, 95, 40, 13}
(gdb) 
17	    for(int q=6;q>=0;q--)
1: list = {20, 83, 63, 43, 95, 40, 13}
(gdb) 
19	        cout<<list[q] <<" " ;
1: list = {20, 83, 63, 43, 95, 40, 13}
(gdb) 
17	    for(int q=6;q>=0;q--)
1: list = {20, 83, 63, 43, 95, 40, 13}
(gdb) 
19	        cout<<list[q] <<" " ;
1: list = {20, 83, 63, 43, 95, 40, 13}
(gdb) 
17	    for(int q=6;q>=0;q--)
1: list = {20, 83, 63, 43, 95, 40, 13}
(gdb) 
19	        cout<<list[q] <<" " ;
1: list = {20, 83, 63, 43, 95, 40, 13}
(gdb) 
17	    for(int q=6;q>=0;q--)
1: list = {20, 83, 63, 43, 95, 40, 13}
(gdb) 
19	        cout<<list[q] <<" " ;
1: list = {20, 83, 63, 43, 95, 40, 13}
(gdb) 
17	    for(int q=6;q>=0;q--)
1: list = {20, 83, 63, 43, 95, 40, 13}
(gdb) 
21	    cout << "\n";
1: list = {20, 83, 63, 43, 95, 40, 13}
(gdb) 
13 40 95 43 63 83 20 
22	    return 0;
Last edited on
Topic archived. No new replies allowed.