Operator in c programming language

 πŸ’₯Operators in C Programming Language (In Detail)

In C programming, an operator is a symbol that tells the compiler to perform a specific mathematical or logical operation on variables and values.

πŸ‘‰ Example:

C

a + b

Here, 

        + is an operator and a, b are operands.

πŸ”Ή Types of Operators in C Language

1. Arithmetic Operators

Used to perform basic mathematical operations.

Operator      Meaning         Example

+                   Addition              a + b

-                   Subtraction          a - b

*                  Multiplication      a * b

/                    Division                a / b

%                  Modulus               a % b

πŸ“Œ Example:

C

int sum = a + b;

int rem = a % b;

2. Relational Operators

Used to compare two values.

Operator            Meaning

==                       Equal to

!=                       Not equal to

>                        Greater than

<                        Less than

>=                     Greater or equal to

<=                     Less or equal to

πŸ“Œ Output is always True (1) or False (0)

C

if(a > b)

3. Logical Operators

Used to combine two or more conditions.

Operator            Meaning

&&                      Logical AND

!                          Logical NOT

πŸ“Œ Example:

C

if(a>10 && b<5)

4. Assignment Operators

Used to assign values to variables.

Operator       Example             Meaning

=                       a = 5                  Assign value

+=                   a += 2                  a = a + 2

-=                    a -= 2                  a = a - 2

*=                   a *= 2.                 a = a * 2

/=                   a /= 2                   a = a / 2

%=                a %= 2                a = a % 2

5. Increment & Decrement Operators

Operator               Meaning

++                           Increment

--                             Decrement

πŸ“Œ Types:

Pre Increment → ++a (increase first, then use)

Post Increment → a++ (use first, then increase)

Example:

C

a++;

--b;

6. Bitwise Operators

Used to perform operations at bit level.

Operator             Meaning

&                          AND

|                           OR

^                           XOR

~                          NOT

<<                        Left Shift

>>                        Right Shift

7. Conditional (Ternary) Operator

Syntax:

C

condition ? expression1 : expression2;

πŸ“Œ Example:

C

max = (a>b) ? a : b;

8. Special Operators

Operator                  Use

sizeof                  Find memory size

&                          Address of variable

*                          Pointer operator

,                           Comma operator

Example:

C

sizeof(int);

πŸ”Ή Operator Precedence

Operator precedence decides which operator will be evaluated first.

Example:

C

int result = 10 + 5 * 2;

πŸ‘‰ Output = 20

Comments

Popular posts from this blog

History of c programming language

Evolution of programming languages

How to Create a Bloger account