dc unix : preserving initial value even after storing new value at the same array index
7
votes
3
answers
1366
views
I'm unable to understand this example given in manpage of
dc
:
$ dc
1 0:a 0Sa 2 0:a La 0;ap
1
To me answer should be 2 because:
1. 1 0:a
Here we store 1 at 0th position of array a
.
2. 0Sa
Now we push 0 to the stack of register a
.
3. 2 0:a
Now here again we store 2 at 0th position of array a
thereby overwriting the previous 1 stored at that location.
4. La
Now we pop the 0 stored on stack of register a
and push it to main stack.
5. 0;a
Now we again push 0 to the main stack and then pop it to use as an array index and so we push the 2 stored at 0th location of array a
to the main stack.
6. p
Now we print the top of main stack which is 2. So answer should be 2.
What am I missing?
PS- I wanted to use dc
as a tag but looks like it doesn't exist and it's compulsory to use at least one tag so used debian
(my workstation OS).
Asked by rootkea
(196 rep)
Jan 5, 2016, 11:59 PM
Last activity: Oct 17, 2024, 03:26 PM
Last activity: Oct 17, 2024, 03:26 PM