What is used here is the conditional operator ( Also called ternary operator because it uses 3 expressions) The format of the conditional operator is
expression1 ? expression2 : expression3.
Now let me explain this.
If expression1
evaluates to true, then the value of the whole expression is the value of expression2
, otherwise, the value of the whole expression is expression3
.
Now take this simple example
result = marks >= 50 ? 'P' : 'F' ;
result
will have the value 'P'
if the expression marks >= 50
evaluates to true, otherwise, result
will get 'F'
.
Now let us move on to your case
unsigned long long base_size = b >= 2 ? (b-2)/2:0;
printf("%llu\n",(base_size*(base_size+1))/2);
It checks if b >= 2
, if it is, then assigns base_size
the value (b-2)/2
else it assigns base_size
the value 0.
It is also the equivalent of
if( b >= 2 )
base_size = ( b - 2 ) / 2;
else
base_size = 0;
Now, just in case you don't know
printf("%llu\n",(base_size*(base_size+1))/2);
What this does is outputs the value of base_size * ( base_size + 1 ) / 2
onto your output screen.