I have a small piece of code about the sizeof
operator with the ternary operator:
#include
#include
int main()
{
There is no boolean datatype in C, instead logical expressions evaluate to integer values 1
when true otherwise 0
.
Conditional expressions like if
, for
, while
, or c ? a : b
expect an integer, if the number is non-zero it's considered true
except for some special cases, here's a recursive sum function in which the ternary-operator will evaluate true
until n
reach 0
.
int sum (int n) { return n ? n+sum(n-1) : n ;
It can also be used to NULL
check a pointer, here's a recursive function that print the content of a Singly-Linked-List.
void print(sll * n){ printf("%d -> ",n->val); if(n->next)print(n->next); }