DEV Community

He Codes IT
He Codes IT

Posted on

What are Operators in C

What are Operators in C
December 19, 2022 by admin
Operators in C are special symbols that perform specific operations on one, two, or three operands and produce a result. These operations can include arithmetic, logical, bitwise, assignment, and more. In this post, we’ll take a closer look at the different types of operators in C and how they are used in programming.

What are Operators in C

Image description
Arithmetic Operators
Arithmetic operators are used to perform basic mathematical operations, such as addition, subtraction, multiplication, and division. These operators are commonly used in C programs to perform calculations and assign values to variables.

Here are some examples of arithmetic operators in C:

+: used to add two operands. For example, 5 + 3 would result in 8.
-: used to subtract one operand from another. For example, 5 - 3 would result in 2.
*: used to multiply two operands. For example, 5 * 3 would result in 15.
/: used to divide one operand by another. For example, 6 / 2 would result in 3.
%: used to find the remainder of a division operation. For example, 7 % 3 would result in 1.
Assignment Operators
Assignment operators are used to assign a value to a variable. The most common assignment operator in C is the equal sign (=). This operator is used to assign a value to a variable, like this:

int x = 5

In this example, the assignment operator = is used to assign the value 5 to the variable x.

There are also compound assignment operators in C, which are used to perform an operation and assign the result to a variable in a single statement. These operators include:

+=: used to add a value to a variable and assign the result to the variable. For example, x += 3 would add 3 to x and assign the result to x.
-=: used to subtract a value from a variable and assign the result to the variable. For example, x -= 3 would subtract 3 from x and assign the result to x.
*=: used to multiply a value by a variable and assign the result to the variable. For example, x *= 3 would multiply x by 3 and assign the result to x.
/=: used to divide a variable by a value and assign the result to the variable. For example, x /= 3 would divide x by 3 and assign the result to x.
Comparison Operators
Comparison operators are used to compare two values and determine if they are equal, greater than, or less than each other. These operators are commonly used in C to control the flow of a program using conditional statements.

Here are some examples of comparison operators in C:

==: used to determine if two values are equal. For example, 5 == 5 would evaluate to true, while 5 == 3 would evaluate to false.
!=: used to determine if two values are not equal. For example, 5 != 5 would evaluate to false, while 5 != 3 would evaluate to true.

<: used to determine if one value is greater than another. For example, 5 > 6 would evaluate to false, while 5 < 6 would evaluate to true.

READ MORE

at :
https://hecodesit.com/what-are-operators-in-c/

Top comments (0)