Expression in C

Expression in C. Expression in C Tutorial. Learn Expression in C
Expression in C.

What is Expression in C ?

In C, an expression is a combination of operators, constants, variables, and function calls that can be evaluated to produce a value. Expressions are used to perform calculations, manipulate data, and make decisions in a C program.

Types of Expressions in C

1. Arithmetic Expressions:

  • These expressions involve mathematical operations like addition, subtraction, multiplication, and division.
ExampleDescription
x + yAddition
x - ySubtraction
x * yMultiplication
x / yDivision
x % yModulus (remainder)

2. Relational Expressions:

  • These expressions are used for comparing values and return a Boolean result (true or false).
ExampleDescription
x == yEqual to
x != yNot equal to
x < yLess than
x > yGreater than
x <= yLess than or equal to
x >= yGreater than or equal to

3. Logical Expressions:

  • These expressions involve logical operators and return a Boolean result.
ExampleDescription
x && yLogical AND
`x
!xLogical NOT

4. Bitwise Expressions:

  • These expressions perform bitwise operations on integers.
ExampleDescription
x & yBitwise AND
`xy`
x ^ yBitwise XOR (exclusive OR)
~xBitwise NOT (complement)
x << nLeft shift by n bits
x >> nRight shift by n bits

5. Assignment Expressions:

  • These expressions assign a value to a variable.
ExampleDescription
x = yAssign y to x
x += yIncrement x by y
x -= yDecrement x by y
x *= yMultiply x by y
x /= yDivide x by y
x %= yAssign the remainder of x/y

6. Conditional (Ternary) Expressions:

  • These expressions provide a way to make decisions based on a condition.
ExampleDescription
x ? y : zIf x is true, return y; else return z

7. Comma Expressions:

  • These expressions evaluate multiple expressions separated by commas and return the value of the last expression.
ExampleDescription
x, y, zEvaluate x, then y, then z and return z

8. Function Call Expressions:

  • These expressions involve calling a function and can return a value.
ExampleDescription
function(x, y)Call a function with arguments x and y

More: