c expression

C Expressions

An expression is a formula in the operands are linked to each other by the use of operators to compute a value. An operand can be a function reference, a variable, an array element or a constant.

Lets see the example:

a+b; a-b; a*b;

Italian Trulli

in the c language there are mainly four types of expressions

1. Logical expression
2. Arithmetic expression
3. Relational expression
4. conditional expression

Arithmetic operators in C

The Arithmetic operators are used for numerical calculations such as addition, subtraction, multiplication, division etc

1. Unary arithmetic operators 2. Binary arithmetic operators

Relational operators in C

Relational operators are used to compare values of two expressions. An expression that contains relational operators is known relational expression or called relational expression. if there is relation is true then the value of relational expression is 1 if relation is false then the value of expression is 0. There are some relational operators are- –

Expression Relation Value of Expression
x<=y false 0
x<=y False 0
x==y False 0
x!=y True 1
x>y True 1
x>=y True 1
x==0 False 0
y!=0 True 1
X>1 True 1
10<20 True 1

Logical operators in C

When an Expression that combines two or more expressions is know as logical expression. To combining these expressions we use logical operators.This logical operator return 0 for false and 1 for true. The operands may be constant,expressions or variables . In c language there are three logical operator –

And

This operators gives the net result true if both condition will be true, Otherwise result will be false.

OR

This OR operator gives the result false. if both conditions have the value false. otherwise the result is true

Conditional operator in C

Conditional operator is a ternary operator (? and ::) which is required three expression as operand let us take example its written as –

Testexpression? expression1 : expression2

1. if Testexpression is true(non zero), then only expression1 is evaluted and it becomes print all the values of this conditional expression
2. if Testexpression is false then expression2 is evaluted and it becomes all the values of this conditional expression.

x>y is evaluated if the value of this condition expression is true then the value of variable x will be value of conditional expression otherwise the value of y becomes the value of conditional expression

Let us take example to understand the concept of conditional operator let us suppose x=6 and y=10 and now we are using above conditional operator

Result=x>y ? x : y;