Date: agosto 25, 2025
Author: Guillermo Garcia
Categories: Embedded C programming Tags: Embedded C programming
In this article we are going to see the logical operators that are important for creating programs in C language.
Table of Contents
In most C programs, one or more calculations will be needed. To this end, the C language is equipped with a number of arithmetic operators as summarized.

Some remarks:
What is the output of the following i++ code?
i=1; j=1; j=i++ output: i=2; j=1;
Use the current value of i in the expression (j=i), afterwards increment i by 1.
What is the output of the following ++i code?
i=1; j=1; j=++i; output: i=2; j=2;
First increment i by 1, then use the new value of i in the expression (j=i).
This evaluate to one of following results:
Conditional expressions are formed by using the equality operators, the relational operators and the logical operators as summarized.

The symbols in the operators ‘==’, ‘!=’, ‘<=’ and ‘>=’ cannot be separated by one or more spaces!.
Often the equality operator ‘==’ is confused with the assignment operator ‘=’ . The expression ‘x=5’ is always true since the assignment operator takes care of assigning the value 5 to the variable x which is not equal to 0. The expression ‘x==5’ is true only if the variable x contains the value 5.
If an expression contains more than one operator, C will apply these operators in a sequence that is determined by the rules of precedence as summarized. The first ones in the table have higher priority.

To change the value stored in a variable, an assignment statement is used. In its most general form, the assignment statement can be written as:
<variable> = <expression> example sum = sum + number; y=2 * cos(x) + 4;
The expression on the right-hand side of this statement will first be evaluated into a result. Afterwards, this result will be assigned to the variable written on the left-hand side of the assignment operator.
C provides a number of assignment operators for abbreviating assignment expressions. For example the statement x = x + a; can be abbreviated with the addition assignment operator ‘+=’ as.


Deja una respuesta