With and without ios::sync_with_stdio(0);

With ios::sync_with_stdio(0);cin.tie(0);
#include<bits/stdc++.h>

using namespace std;

int main(){

ios::sync_with_stdio(0);cin.tie(0);

cout << “1st step” << “\n”;

int tc;

cin >> tc;

while(tc–){

cout << “hello” << “\n”;

}

}

Output:
1
1st step
hello

Without ios::sync_with_stdio(0);cin.tie(0);
Output:
1st step
1
hello

Why is the order of output different in both cases?

Hi Ravi ,
when you use ios::sync_with_stdio(0);cin.tie(0);…
then it will firstly take all input and print all the output at last of program.
Here
1 //input
1st step //output
hello //ouput

where as you dont use it , program will work normally by going line by line
As
1st step
1
hello.

hit like if u get it :slight_smile:
and mark it resolved.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.