0

I am a beginner in Java. So excuse me for any silly questions, I have the following code

void push (int item) {
        if (tos == 9)
            System.out.println("stack is full");
        else 
            stck [++tos] = item;
    }

Here, I cant understand how the assignment of item is done to tos.

Md. Sabbir Ahmed
  • 850
  • 8
  • 22
  • 2
    What don't you understand about it? Do you know what `++tos` does? Do you know what `stck[0] = item;` does? – GBlodgett Mar 18 '19 at 03:05
  • 1
    `item` isn't assigned to `tos`. It is assigned to an element of the array `stck`. – user207421 Mar 18 '19 at 04:55
  • No need to downvote, `array[idx++]` is hard to get right: https://stackoverflow.com/questions/50683786/why-does-arrayidx-a-increase-idx-once-in-java-8-but-twice-in-java-9-and-1?rq=1 – Thilo Mar 18 '19 at 06:32
  • I cant get the thing that "item" is not even initialized, so what is assigned to tos[0] – Saurabh Jaisinghani Mar 18 '19 at 14:41
  • i got the solution of my query, actually it was about the parameters passed in the method push it wasn't related to increment or stack class – Saurabh Jaisinghani Mar 18 '19 at 15:25

0 Answers0