Unique number - query regarding input buffer and for loop

int n;

cin >> n;

int no;

int ans = 0;

for (int i=0; i < n; i++)
{

cin >> no;

ans = ans ^ no;

}

}

After hit enter,

the program asks for the first n.

Then it should play loop for each input number n times an !!?

I didn’t get that the way bhaiya enter input in such style.

Means how it works this way !!!

In console:
7
1 2 3 4 5 6 7

Explain to me the input style used in the program.

Hope you got my doubt.

hello @omkarvp99

first this line will read n . in console it is 7 . so n will be 7.

now this loop will execute n(7) times and in each iteration it will read one number .
so in total it will read 7 numbers one by one.

i.e first it will read 1 then 2 then 3 so on till 7

1 Like

@aman212yadav, means 1 2 3 4 5 6 7 already stores in kind of memory buffer or what?

yeah it is stored in input buffer, and then program reads from that buffer

1 Like

@aman212yadav oh, interesting. Thanks.

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.

1 Like