Examples
Consider the following code snippet:
int a = 5, b = 10;
int result;
result = (a * b) + (b / a) - 3;
In this example:
(a * b) and (b / a) are arithmetic expressions.
The whole line result = (a * b) + (b / a) - 3; is an assignment expression.
Expressions are the building blocks of statements in C programming, enabling the language to perform a wide range of computations and operations. Understanding how to construct and use expressions effectively is key to mastering C programming.
Let's try this example
int a = 5, b = 10;
int result;
result = (a > b); // This will evaluate to 0 since a is not greater than b.
result = (a < b); // This will evaluate to 1 since a is less than b.
(a > b)
is a Relational Expressions
In the above example, the expression (a > b) is false, so the result will be assigned the value 0. On the other hand, the expression (a < b) is true, so the result will be assigned the value 1.