+ 1

Can anyone explain this question?

#include<iostream> using namespace std; int main() { int i=4, j=5, k=6, r; r= ( i, j, k); cout<<r; return0; } Here, in this question I thought I would make some 'error', but the real answer is '6' Can anyone explain me how the answer comes 6 instead of giving 'error' Please help.

14th Apr 2022, 9:03 AM
Amul Gaurav
Amul Gaurav - avatar
3 Answers
+ 2
Amul Gaurav here in r = (i, j, k) we are using comma operator comma (,) can be used in 2 ways 1 - a separator 2 - an operator So here using an operator which will not give error and print last value If you do like this: int i = 1, 2, 3; Here we are using a comma separator which will give error
14th Apr 2022, 9:10 AM
AÍąJ
AÍąJ - avatar
+ 2
Now I get that, thanks a lot for your help guys
14th Apr 2022, 9:31 AM
Amul Gaurav
Amul Gaurav - avatar
+ 1
Have you tried running the code on sololearn? It outputs 6 but gives a warning.
14th Apr 2022, 9:11 AM
Lisa
Lisa - avatar