Lesson 10
( Operators )
Hi and welcome back on learn 4 free programming!
In this lesson i will talk more about operators. Mostly programs contain operators, because mostly programs depends from user. If user enter this, that will happen but if user enter something else, that will happen.... Basically, program depends on what will user enter.
Operators of compare
Expressions involving comparison operators provide after comparing operand logical result of true (non-zero) or false. In next picture you'll see the list of compare operators.
If variables m and n, for example, have values ( m=5, n=11 ). Expression m < n gives result true. If you put m <= n or *m != n they are also true.
![]() |
| Operators of compare |
If variables m and n, for example, have values ( m=5, n=11 ). Expression m < n gives result true. If you put m <= n or *m != n they are also true.
* != means not equal to, because m is different than n this is true.
Logic operators
Expressions that are formed using the comparison operator, from the previous section, can be linked and modified in various ways.
![]() |
| Logic operators |
To negate a logical expression use the operator !. An expression that evaluates to false when it is preceded by the negation operator.
- example:
x == x ----->TRUE
!( x == x ) ----->FALSE
The logical connectives && and | | are used to link complex logical expressions. Operation && on two operands gives result true only if operands have value true. Operation || on two operands gives result true when one or two operands have value true.
Here are some examples:
int m = 20, n = 4;
int x = 2, y = 10;
m && n ------->true
m > n && x < y ------>true
int m = 20, n = 4;
int x = 2, y = 10;
m && n ------->true
m > n && x < y ------>true
m < n || x > y ------->false
Priority of operator && is higher than operator ||. You may need brackets () to achieve the desired order of determining the value of an expression that includes both operator.
- example:
1. ( m > n || x > y ) & m < x ---->false
2. m > n || x > y && m < x -----> true
Priority of operator && is higher than operator ||. You may need brackets () to achieve the desired order of determining the value of an expression that includes both operator.
- example:
1. ( m > n || x > y ) & m < x ---->false
2. m > n || x > y && m < x -----> true
Increment and decrement operators
Increment and decrement of a variable is a usual appearance in programs. Most machines have built-in instructions that perform these operations quickly.
| Increment and decrement |
The effect of operator + + is the addition value 1 to operand. There are more ways to increment or decrement variable.
- for example :
x = x + 1;
x + =1; ----> if type ,instead of 1, 5 it will add 5 ( example: x= 3; x+= 5 --> x=8 )
x++;
All of these examples are the same.
Okay that's it for this lesson come back to learn more about C.
I will be posting more lessons about C programming, so follow me, comment if there is something you would change :) .
If something doesn't work or you need help just email me on: sashans89@gmail.com and i will help you.
See you next time, Bye.
See you next time, Bye.


No comments:
Post a Comment