Introduction to C Programming
Decision and Branching Concepts

Outline:

Boolean Type ( or lack thereof in C ) and stdbool.h

Relational Operators

Operator
Meaning
A > B
True ( 1 ) if A is greater than B, false ( 0 ) otherwise
A < B
True ( 1 ) if A is less than B, false ( 0 ) otherwise
A >= B
True ( 1 ) if A is greater than or equal to B, false ( 0 ) otherwise
A <= B
True ( 1 ) if A is less than or equal to B, false ( 0 ) otherwise
A == B
True ( 1 ) if A is exactly equal to B, false ( 0 ) otherwise
A != B
True ( 1 ) if A is not equal to B, false ( 0 ) otherwise

Logical Operators

Operator
Meaning
A && B
A AND B - True ( 1 ) if A is true AND B is also true, false ( 0 ) otherwise
A | | B
A OR B - True ( 1 ) if A is true OR B is true, false ( 0 ) otherwise
! A
NOT A - True ( 1 ) if A is false ( 0 ), false ( 0 ) if A is true ( non-zero ).

if

There is a broad category of conditional statements - they all hinge on a conditional that evaluates to true or false.
        if( condition )
	{
            BB;
	}
	(more code)
void give_feedback(int studentid)
{
	float perc = calculate_grade(studentid);
	if (perc >= 90)
	{
		printf("Great job!\n");
	}
	printf("Current class percentage: %f\n",perc);
}
Details: How it works:

If the condition is true, the BB will execute and then continue with code after the close curly brace. Otherwise, it will skip over BB and go directly to the code after the curly brace.


When to use this construct:

When you want something to happen in a special case. Otherwise, you do the normal thing.