||
operator evaluates to true if any of the operands is true. So if first operand evaluates to true
it doesn't check the second. It only checks second operand if first operand was false.
&&
operator evaluates to true only when both the operands are true
. It would check the second operand iff the first one is not false
.
As stated in the manpage:
Upon successful return, these functions return the number of characters printed (excluding the null byte used to end output to strings).
The functions snprintf() and vsnprintf() do not write more than size bytes (including the terminating null byte ('\0')). If the output was truncated due to this limit then the return value is the number of characters (excluding the terminating null byte) which would have been written to the final string if enough space had been available. Thus, a return value of size or more means that the output was truncated. (See also below under NOTES.)
Say you have a code like:
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("%d", printf(""));
return 0;
}
This would print 0
just as explained in the manpage.
If your statement is:
printf("") && printf("XX");
It won't print anything because first operand evaluated to 0
.
Whereas,
printf("") || printf("YY");
Would print YY
.
In your case,
a = (printf("XX")||printf("YY"));
would evaluate printf("YY")
only when the first operand failed to print anything.
a = (printf("XX")&&printf("YY"));
Would print XXYY
when both printf
were successful.