This statement takes care of linking of input and output(cin and cout). If we do not write this statement then by default both input and output streams(cin and cout) are linked in a way that before each I/O operation kind of buffer is flushed(That means if we use cin after cout than output stream buffer is cleared and that data is printed to terminal).
By writing above statement we untie those stream flushes. So as the result previous line cout may not be displayed before next line cin.
Now seeing your code(It has some typos like tc-- in while loop, but ignoring it)
One thing what we know is when we type something it is visible to us but not visible to terminal until we press enter.
So when you enter 1 it is not visible to terminal.
When you pressed enter it is the text you have typed so there is no need to think about streams at this point.
Even before typing, “1st step” was in buffer but it is waiting until every IO operation is completed and at last print everything.
After you pressed Enter key, while loop run 1 times and “hello” is also added to buffer after "1st step"
There is no more things to do. So both things are printed one by one.
Read what i have written once again and hopefully you will get what i want to say.
Now another case
Every statement is executed and buffer is flushed everytime at every I/O operation.
It is printed even before taking input from cin. (Because cin flushed cout output stream and printed contents on terminal)
Than input is taken, which is what you have entered from keyboard. It will be visible to terminal when you press enter key. It is simply the text which you have typed.
Remaining execution is done and “hello” is printed once.
Hope you got your doubts cleared. For reference visit this stackoverflow link
Please Upvote if it helped. It motivates me to write more answers. (PS: writing answer at 1AM for you)