#include<stdio.h>
int main()
{
int a=2;
if(a==3,4)
printf("hello");
return 0;
}
Warning: Condition is always true Why is it always true??
#include<stdio.h>
int main()
{
int a=2;
if(a==3,4)
printf("hello");
return 0;
}
Warning: Condition is always true Why is it always true??
The ,
doesn't work like you think it does.
What a ,
does is evaluate all the expressions that are separated by the ,
in order, then return the last.
So what your if statement is actually doing is checking a==3
which returns false, but it discards this result. Then it checks if(4)
, which returns true.
Essentially your code is:
#include<stdio.h>
int main()
{
int a=2;
if(4)
printf("hello");
return 0;
}
a==3,4
should be
a==3.4
Decimal are symbolised with a dot (.) and not a comma(,). A comma here splits instructions, just as it does in a for statement:
for(int a=0, int b=10 ; b<=0 ; a++,b--)