# C Operators: The Complete Guide for Beginners 2021

## C Operators

A symbol that operates on a value or variable is known as an C operators. C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, with a static type system. By design, C provides constructs that map efficiently to typical machine instructions.(from wikipedia )

With the help of examples, you will learn about several operators in C programming in this course. For example, the operator + is used to execute addition. C contains a large number of operators that can be used to do a variety of tasks.

## Operators in C for Arithmetic

On numerical values, an arithmetic operator performs mathematical operations such as addition, subtraction, multiplication, and division (constants and variables).

Calculator in C Language with Sourc... x
Calculator in C Language with Source Code | C Language Projects with Source Code 2021

The table below lists all of the arithmetic operators offered by the C programming language. Assume variable X has a value of 20 and variable Y has a value of 45.

## Example of C Arithmetic Operators

As you might guess, the operators +, -, and * compute addition, subtraction, and multiplication, respectively.

45/20 Equals 2.25 in conventional math. In the program, however, the output is 2. Because both x and y are integers, this is the case. As a result, the result is also an integer. The compiler ignores the phrase after the decimal point, resulting in an answer of 2 rather than 2.25.

The residual is computed using the percent modulo operator. The remaining is 5 when x=20 is divided by y=45. Only integers can be used with the percent operator.

## C Increment and Decrement Operators

The increment ++ and decrement operators in C programming modify the value of an operand (constant or variable) by one.

## Example of C Increment and Decrement Operators

Decrement — reduces the value by one, whereas increment ++ increases it by one. These two operators are unary, which means they only work with one operand.

## C Relational Operators

The relationship between two operands is checked by a relational operator. It yields 1 if the relationship is true, and 0 if the relationship is false.

The table below lists all of the relational operators that C supports. Assume variable A has a value of 10 and variable B has a value of 20.

## Example of C Relational Operators

We verified X and Y values against every relational operator we have in this relational operators example. 1 is TRUE, while 0 is FALSE.

## C Logical Operators

Depending on whether the expression is true or false, a logical operator expression returns either 0 or 1. In C programming, logical operators are frequently employed in decision-making.

## Example of Logical Operators

• Because both operands (a == b) and (c > b) are 1, (a == b) && (c > 5) evaluates to 1. (true).
• Because operand (c b) is 0, (a == b) && (c b) evaluates to 0. (false).
• (a == b) || (c b) equals 1 since (a = b) equals 1. (true).
• Because both operands (a!= b) and (c b) are 0, (a!= b) || (c b) evaluates to 0. (false).
• Because operand (a!= b) is 0,!(a!= b) evaluates to 1. (false). As a result,!(a!= b) equals 1. (true).
• `!(a == b)` evaluates to 0 because `(a == b)` is 1 (true). Hence, `!(a == b)` is 0 (false).

## C Bitwise Operators

This lesson will teach you how to use all six bitwise operators in C programming, along with examples.

Mathematical operations such as addition, subtraction, multiplication, and division are performed in bit-level in the arithmetic-logic unit (which is part of the CPU). Bitwise operators are used in C programming to execute bit-level operations.

In binary representation, assuming A = 60 and B = 13, they will be as follows:

• A = 0011 1100
• B = 0000 1101

—————–

• A&B = 0000 1100
• A|B = 0011 1101
• A^B = 0011 0001
• ~A = 1100 0011

The bitwise operators supported by C are listed in the table below. Assume variable ‘A’ has a value of 60 and variable ‘B’ has a value of 13, then

## Bitwise AND operator &

If the matching bits of two operands are 1, the outcome of bitwise AND is 1. If one of an operand’s bits is 0, the result of the associated bit is also 0.

Consider the bitwise AND operation between two integers of 12 and 25.

## Example of Bitwise AND

We declared two integers, x and y, and assigned the values 9 and 25 to them in our bitwise operators program. 12= 0001001 and 25= 00011001 in binary. The printf statements below will conduct bitwise operations on a and b, then display the results.

## Bitwise OR operator |

When at least one corresponding bit of two operands is 1, the output of bitwise OR is 1. The bitwise OR operator is indicated by the symbol | in C programming.

## Example of Bitwise OR

We declared two integers, x and y, and gave them the values 12 and 25 in our bitwise operators program. 12= 0001001 and 25= 00011001 are the binary equivalents of each other. The printf commands that follow will execute bitwise operations on a and b before printing the results.

## Bitwise XOR (exclusive OR) operator ^

If the corresponding bits of two operands are opposite, the outcome of the bitwise XOR operator is 1. It is denoted by the symbol ^.

## Example of Bitwise XOR

We declared two integers, x and y, and assigned them the values 9 and 65 in our bitwise operators program. 12= 0001001 and 12= 0001001 and 25= 00011001 in binary form. The printf commands below will execute bitwise operations on x and y before displaying the results.

Output:

## Bitwise complement operator ~

The unary complement operator is a bitwise complement operator (works on only one operand). It transforms 1 into 0 and 0 into 1. It is denoted by the symbol.

## Example of Bitwise complement

We declared two output, and assigned them the values 35 and 12 in our bitwise operators program. 35 = 00100011 in binary form. The printf commands below will execute bitwise operations on x and y before displaying the results.

## Shift Operators in C

In C programming, there are two shift operators:

Operator on the right shift
The left shift Operator
Operator on the Right Shift
The right shift operator shifts all bits to the right by a specified amount of bits. >> is the symbol for it.

## Left Shift Operator in C

The left shift operator moves all bits to the left by a specified amount of bits. The bit locations that the left shift operator has abandoned are filled with 0. The left shift operator is represented by the symbol.

## Assignment Operators in C

Assignment operators are used to give a variable a value. The assignment operator’s left side operand is a variable, while the assignment operator’s right side operand is a value. Otherwise, the compiler will throw an error if the value on the right side is not of the same data-type as the variable on the left side.

## Example of Assignment Operators

When you compile and run the preceding program, you will get the following output:

## Misc. Operators

Aside from the operators mentioned above, the C Language has a few more significant operators, such as sizeof and ?:

## Example of Misc. Operators

When you compile and run the preceding program, you will get the following output:

## Operators Precedence in C

The order in which terms in an expression are grouped and evaluated is determined by operator precedence. Certain operators take precedence over others; the multiplication operator, for example, takes precedence over the addition operator.

For example, x = 7 + 3 * 2; because operator * has higher precedence than +, x is allocated 13, not 20, and is multiplied by 3*2 before being added to 7.

The highest-priority operators appear at the top of the table, while the lowest-priority operators appear at the bottom. Higher precedence operators will be evaluated first within an expression.

## Comma Operator in C

It’s mostly used to separate expressions, variable declarations, and function calls, among other things. It has two operands to operate with. It’s a one-to-one operator. The comma is used as a separator.

Syntax of comma operator:

### Summary

A symbol that operates on a variable or value is known as an operator. Operators include arithmetic, logical, conditional, relational, bitwise, and assignment operators, among others. Sizeof(), Pointer operator, Reference operator, and other specific sorts of operators are also available in C.