Simple lines of code
If anyone could explain to me in depth these short lines of code, so that I can understand other ones similar to this one when they show up. I know the rest, I just need the bit in the printf brackets explained. Thanks.
#define NUL '\0'
printf("%d",(!c) ? x : c);}
I'll let my compiler do the explaining:
test.c:2:6: warning: return type of 'main' is not 'int' [-Wmain]
test.c: In function 'main':
test.c:3:8: error: 'NULL' undeclared (first use in this function)
test.c:3:8: note: each undeclared identifier is reported only once for each function it appears in
test.c:4:1: error: expected ',' or ';' before 'printf'
test.c:3:6: warning: unused variable 'c' [-Wunused-variable]
You want (!c) ? x : c explained.
That's conditional expression. The part in the parenthesis is evaluated as to TRUE or FALSE. If it's TRUE then the first statement after '?' is executed. If FALSE then the statement after ':'.
If c was zero then !c is TRUE so therefore 'x' is executed (stacked, printed).
If c was non-zero then !c if FALSE so therefore 'c' is executed (stacked, printed).