Operators in C programming language are used to solve an expression, to do mathematical calculations, to reach at some logical decision or to assign a value to a variable etc. C++ provides following types of operators.
In C programming, operators are symbols that facilitate various operations on data, allowing manipulation and computation within the code. Arithmetic operators, such as addition, subtraction, multiplication, division, and modulus, perform basic mathematical calculations. Relational operators, including equality (==
), inequality (!=
), greater than (>
), less than (<
), greater than or equal to (>=
), and less than or equal to (<=
), are used for making comparisons between values. Logical operators like AND (&&
), OR (||
), and NOT (!
) are employed in Boolean expressions to control program flow. Additionally, assignment operators (=
) assign values to variables, while increment (++
) and decrement (--
) operators modify variable values. Bitwise operators manipulate individual bits in binary representations of data. Understanding and effectively utilizing these operators are crucial for building robust and efficient C programs.
In C programming, operators are symbols that represent computations or operations to be performed on variables or values. These operators help manipulate data and perform various tasks within a program. The main categories of operators in C include:
- Arithmetic Operators:
+
(Addition)-
(Subtraction)*
(Multiplication)/
(Division)%
(Modulus)
- Relational Operators:
==
(Equal to)!=
(Not equal to)<
(Less than)>
(Greater than)<=
(Less than or equal to)>=
(Greater than or equal to)
- Logical Operators:
&&
(Logical AND)||
(Logical OR)!
(Logical NOT)
- Assignment Operators:
=
(Assignment)+=
(Add and assign)-=
(Subtract and assign)*=
(Multiply and assign)/=
(Divide and assign)%=
(Modulus and assign)
- Increment and Decrement Operators:
++
(Increment)--
(Decrement)
- Bitwise Operators:
&
(Bitwise AND)|
(Bitwise OR)^
(Bitwise XOR)~
(Bitwise NOT)<<
(Left shift)>>
(Right shift)
- Conditional (Ternary) Operator:
? :
(Conditional operator)
Understanding and using these operators are fundamental to writing C programs for various tasks and computations.
Operators in C programming language
- Arithmetic Operators
- Relational Operators
- Assignment Operators
- Logical Operators
- Unary Operators
Arithmetic operators are used for arithmetical calculations. The following table shows the list of arithmetic operators supported by C & C++.
Operators | Descriptions |
+ | Addition |
– | Subtraction |
* | Multiplication |
/ | Division |
% | Modulus/Remainder |
-
Relational Operators:
Relational operators are also called comparison operators and are used to compare values. The comparison operators, supported by C & C++ are as follows:
Operators | Descriptions |
== | Equal to |
!= | Not Equal |
< | Less than |
> | Greater than |
<= | Less than or equal to |
>= | Greater than or equal to |
-
Assignment Operators:
Assignment operators are used to assign new value to a variable. Assignment operators are combined with other operators to evaluate expressions. The assignment operators, supported by C & C++ are as follows:
Operators | Descriptions |
+= | Assigns a new value by adding to current value. |
-= | Assigns a new value by subtracting from current value. |
*= | Assigns a new value by multiplying with current value. |
/= | Assigns a new value by dividing the current value. |
%= | Assign a new value by modules of the current value. |
-
Logical Operators:
Logical operators are used with Boolean terms. This means that they evaluate an expression resulting as ‘true’ or ‘false’. 1 if expression is true or 0 if false. The logical operators supported by C & C++ are as follow:
Operators | Descriptions |
&& | Logical And (both condition should be true) |
|| | Logical Or (any one condition should be true) |
| | Logical Not |
-
Unary Operators:
All the operators used earlier are called Binary operators because they work on two operands. To evaluate unary operators only one operand is required. C & C++ supports two Unary Operators:
Operators | Descriptions |
++ | increment the value of operand by 1. |
— | decrement the value of operand by 1. |
-
Prefix/Postfix Unary Operators:
The ++/operator can be used using two methods Prefix increment/ decrement operator and Postfix increment/decrement operator.
int num =10;
++num: //Prefix Increment
num ++2 //Postfix Increment
num; //Prefix decrement
num; //Postfix decrement
to learn the basic concepts of C programming Operators in C programming language are very important to learn and practice. and gain knowledge in Operators in C programming language.