## c operators with examples

In this tutorial, we will learn basic C operators step by step. In this C programming class, we’ll cowl all supported C operators, clarify their objectives with examples.

The operators assist in mathematical and statistical computing. Hence, please learn this tutorial with full focus.

In C programming, we might carry out many operations on variables like addition, subtraction, division, increment, decrement, and many others. And C language has many built-in operators to hold out such duties. Please see beneath.

### What are Operators in C?

The operators are particular symbols that instruct the compiler to carry out a particular operation on the given variable(s).

There are primarily six sorts of operators. C Operators are given below:**Arithmetic OperatorsRelational OperatorsLogical OperatorsBitwise OperatorsAssignment OperatorsMiscellaneous Operators**

Let’s examine them out one by one.

## Types of Operators Explanation

### Arithmetic Operators in C

These operators are used to carry out easy arithmetic operations like addition, subtraction, product, quotient, the rest, and many others.

SYMBOL | USAGE |

+ | It is Used to add two or more variables (a + b) |

– | It is Used to subtract two or more variables (a – b) |

* | It is Used to multiply two or more variables (a * b) |

/ | It is Used to divide two variables (a / b) |

% | It is used to Returns the remaining value (percent) |

++ | It is used to Increments by 1 |

— | It is used to Decrements by 1 |

### Relational Operators in C

Relational operators are used to examine a relationship between two or more variables like ‘greater than,’ ‘less than,’ and many others. If the end result is optimistic, then the situation will succeed.

Please word that we’ll get to study extra about the situations in additional chapters.

The following desk reveals some relational operators supported in C.

SYMBOL | USAGE |

== | It is Used to examine if the values of two or more variables are equal. |

!= | It is used to exams for inequality, i.e., not related. |

> | It is used to Tests if the left value is greater than the right side value. |

< | It is used to Tests if the right value is greater than the right side value. |

>= | It is used to Tests if the left value is greater than or equal to the right side value. |

<= | It is used to Tests if the right value is greater than or equal to the left side value. |

### Logical Operators in C Programming

Logical operators are used to carry out logical operations.

Here are some logical operators supported in C

SYMBOL | USAGE |

&& | The Logical AND operator checks if a situation is true for each of the variables then only it will be True. |

|| | Logical OR operator which exams if the situation is true for both of the two variables. If anyone is true then True |

! | Logical NOT operator which reverses the logical state of an operand. If the state is true then false and if false then True. |

### Bitwise Operators in C Programming

Bitwise operators are used to carry out operations on binary values.

This desk would enable you.

SYMBOL | USAGE |

& | It is Used to carry out binary AND operation |

| | It is Used to carry out binary OR operation |

^ | It is Used to carry out binary XOR operation |

~ | It is Used to carry out binary complement operation |

<< | It is Used to carry out binary Left Shift operation |

>> | It is Used to carry out binary Right Shift operation |

Now you need to know the binary conversion of a decimal quantity. If not, this instance will enable you.

Let us assume two numbers 3 and 4. Now, in binary format, they’re represented as

8421 //Here each ‘1’ beneath these numbers will add that worth to the quantity A = 0011 //It is for 3 it is 0+0+2+1 i.e. 3. B = 0100 //It is for 4 it is 0+1+0+0. ------- A&B = 0000 //AND operation A|B = 0111 //OR operation Complement Operations : ~A = ~3 = 1100 ~B = ~4 = 1011 (Just change 1 by 0 and 0 by 1) Left Shift and Right Shift operations A<<1 = 0110 A>>1 = 0001 (Just shift every binary factor to the left or proper by 1)

### Assignment Operators in C

In C programming, variables get values by utilizing the project operators.

Take an instance, say, if you’ll want to assign the value “7” to a variable recognized as the “count,” then you’ll be able to do so with the following assertion.

var = 7;

There are two subtypes of project operators in C programming.

- The easy operator ( = )
- The compound operators (+=, -=, *=, /=, %=, &=, ^=)

SYMBOL | USAGE |

= | var = 5; The value 5 will get assigned to the variable var. |

+= | var += 5; It means, var= var + 5 |

-= | var -= 5; It means, var = var – 5 |

*= | var *= 5; It means, var = var * 5 |

/= | var /= 5; It means, var = var / 5 |

%= | var %= 5; It means, var = var % 5 |

&= | var &=5; It means, var = var & 5 |

^= | var ^= 5; It means, var = var ^ 5 |

### Miscellaneous Operators

These are some miscellaneous operators.

SYMBOL | USAGE |

sizeof() | It Gives the measurement of a variable |

& | It Gives the tackle of a variable |

* | Pointer is used to level to a variable |

?: | It is Used to examine if a particular situation is true. |

You might not see any applications or pattern code in this chapter as a result of we’ve got been utilizing these C operators in many of our different tutorials.

## Related Posts

- How to compare dates in java|algorithm with source code
- Java roll dice 10000 times with algorithm and source code
- Write a Java program that displays the number of characters, lines, and words in a text
- Write a Java program that reads a file and displays the file on the screen with a line number before each line
- Write a Java program that reads a file name from the user, then displays information about whether the file exists, readable, writable, type of file, and the length of the file in bytes
- Java program to make frequency count of vowels, consonants, special symbols, digits, words in a given text
- Write a Java program for sorting a given list of names in ascending order
- Get Salesforce Answers