void main()
{
int i=2,j=4;
char x=1 ,y=10;
if(y,x,j,i)
printf(āwelcomeā);
}
void main()
{
int i=2,j=4;
char x=1 ,y=10;
if(y,x,j,i)
printf(āwelcomeā);
}
SO MANY BUGSā¦
$g++ main.cpp -o demo -lm -pthread -lgmpxx -lgmp -lreadline 2>&1
main.cpp:2:11: error: ā::mainā must return āintā
void main()
^
main.cpp: In function āint main()ā:
main.cpp:4:60: error: āprintfā was not declared in this scope
{ int i=2,j=4; char x=1 ,y=10; if(y,x,j,i) printf(āwelcomeā);
^
NOW IT Compiles and runsā¦
#include<stdio.h>
int main()
{ int i=2,j=4; char x=1 ,y=10; if(y,x,j,i) printf(āwelcomeā);
return 0;
}
comma is just changed to && (the logical and operator)!! and then the expression is evaluatedā¦
TRY THIS :
#include<stdio.h>
bool f1()
{
return true;
}
bool f2()
{
return true;
}
int main()
{
if(f1(),f2()) printf("welcome");
return 0;
}
You have the comma operator in action, there.
exp1, exp2, exp3 means exp1 will be evaluated, then exp2 and then exp3. The value of the whole expression id the value of exp3 (the right-most expression).
So, if(y,x,j,i) means if(y!=0, x!=0, j!=0, i!=0) which is again if(true, true, true, true) which boils down to if(true).
So, your if part will get executed.
The final value of the expression representing the comma operator only depends entirely on the right-most expression. It has no connection with the previous expressions. It doesnāt behave like an AND nor does it behave like an OR.
See Comma operator - Wikipedia and the topic under the heading Comma operator ( , ) in http://www.cplusplus.com/doc/tutorial/operators/ for more details.
this is the 6000th answer,sorry but i am celebrating this one
this is the 6000th answer,sorry but i am celebrating this one
you didnāt even test with bool f2() { return false; }
Congratulations, dude!
But, with your celebration, if there is no use to the community, then what is the point in your celebration over here?
He wanted to get negative karma for sure 