I am confused as to why I get this warning:
I intiate matchObsFlag with:
int *matchObsFlag=0;
but when I run this line:
if (matchObsFlag == 1)
I get this warning. Any ideas?
You surely get a warning because you did not cast 1 as such (int*) 1
so you test an equality between different things : an address and an int.
So it is either if(matchObsFlag == (int*)1)
or if(*matchObsFlag == 1)
depending on what you wanna do.
int *matchObsFlag=0;
The type of matchObsFlag
is int*
while the constant literal is of type int
. Comparison between the unrelated types is causing the warning.
matchObsFlag
is a NULL pointer. matchObsFlag
needs to point to a valid memory location if you wish to compare the value pointed by the pointer.
int number = 1;
matchObsFlag = &number;
Now, to compare the value, you need to dereference the pointer. So try -
if (*matchObsFlag == 1)
{
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With