int main()
{
unsigned int c = -1;
char *s = "Abc";
char *x = "defhe";
((strlen(s)-strlen(x))>c)? printf(s): printf(x);
}
the value of c is 4294967295 and the value of (strlen(s)-strlen(x)) is 4294967294 it should print the x but it is printing the s value.I am not getting why it is like that
the value of c is 4294967295 and the value of (strlen(s)-strlen(x)) is 4294967294
It isn't necessarily true that (strlen(s)-strlen(x)) yields 4294967294. It depends on the value of SIZE_MAX on your system.
If SIZE_MAX is 18446744073709551615 (typically on a 64-bit system) then (strlen(s)-strlen(x)) will be 18446744073709551614 which is obviously greater than 4294967295 (assuming UINT_MAX is 4294967295). Hence, you see printf(s); getting printed.
Use a printf() statement to see the values and understand:
printf("%zu %u\n", strlen(s)-strlen(x), c);
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