{"id":80943,"date":"2021-06-22T09:00:03","date_gmt":"2021-06-22T03:30:03","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=80943"},"modified":"2021-06-22T09:00:03","modified_gmt":"2021-06-22T03:30:03","slug":"c-operators-types-and-examples","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/c-operators-types-and-examples\/","title":{"rendered":"C Operators &#8211; Types and Examples"},"content":{"rendered":"<p><span style=\"font-weight: 400\">The C programming language comes with very rich built-in functions. There is a vast use of operators in all programming languages. Operators are a useful and powerful feature of the C\/C++ programming language. Without them, the functionality of C is useless. It makes it easy for a programmer to write codes very efficiently and easily.\u00a0<\/span><\/p>\n<h3>What are Operators?<\/h3>\n<p><span style=\"font-weight: 400\">An operator is a symbol that operates on a variable or value. It is used for performing certain operations like arithmetical, logical, relational, etc.<\/span><\/p>\n<p><span style=\"font-weight: 400\">When a programmer wants to perform some type of mathematical operation then you have to use operators. The purpose of operators is mainly for mathematical and logical calculations.<\/span><\/p>\n<h3>Types of Operators in C<\/h3>\n<p><span style=\"font-weight: 400\">In C, there are various types of operators available to perform various operations. <\/span><span style=\"font-weight: 400\">Following are the list of operators present in C:-<\/span><\/p>\n<h4>1. Arithmetic Operators in C<\/h4>\n<p><span style=\"font-weight: 400\">The purpose of this operator is to perform mathematical operations like addition, subtraction, division, multiplication etc.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Operator<\/b><\/td>\n<td><b>What it does<\/b><\/td>\n<td><b>Example<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">+<\/span><\/td>\n<td><span style=\"font-weight: 400\">Addition between 2 operands.<\/span><\/td>\n<td><span style=\"font-weight: 400\">A + B = 10<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">\u2212<\/span><\/td>\n<td><span style=\"font-weight: 400\">Subtraction between 2 operands.<\/span><\/td>\n<td><span style=\"font-weight: 400\">A \u2212 B = 0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">*<\/span><\/td>\n<td><span style=\"font-weight: 400\">Multiplication between 2 operands.<\/span><\/td>\n<td><span style=\"font-weight: 400\">A * B = 25<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">\/<\/span><\/td>\n<td><span style=\"font-weight: 400\">Division between 2 operands.<\/span><\/td>\n<td><span style=\"font-weight: 400\">B \/ A = 1<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">%<\/span><\/td>\n<td><span style=\"font-weight: 400\">Modulus Operator and remainder of after an integer division.<\/span><\/td>\n<td><span style=\"font-weight: 400\">B % A = 0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">++<\/span><\/td>\n<td><span style=\"font-weight: 400\">Increases the integer value by one.<\/span><\/td>\n<td><span style=\"font-weight: 400\">A++ = 6<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">&#8212;<\/span><\/td>\n<td><span style=\"font-weight: 400\">Decreases the integer value by one.<\/span><\/td>\n<td><span style=\"font-weight: 400\">B&#8211; = 4<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Example of Arithmetic Operators in C:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int main()\n{\n  int a = 10,b = 15, result;\n  result = a+b;\n  printf(\"Welcome to TechVidvan Tutorials...\\n\");  \n  printf(\"Addition: a+b = %d \\n\",result);\n  result = a-b;\n  printf(\"Subtraction: a-b = %d \\n\",result);\n  result = a*b;\n  printf(\"Multiplication: a*b = %d \\n\",result);\n  result = a\/b;\n  printf(\"Division: a\/b = %d \\n\",result);\n  result = a%b;\n  printf(\"Modulo Division: %d \\n\",result);\n  result = ++a;\n  printf(\"Increment the value of a by 1: %d \\n\",result);\n  result = --b;\n  printf(\"Decremented the value of b by 1: %d \\n\",result);\n  return 0;\n}\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Welcome to TechVidvan Tutorials&#8230;<br \/>\nAddition: a+b = 25<br \/>\nSubtraction: a-b = -5<br \/>\nMultiplication: a*b = 150<br \/>\nDivision: a\/b = 0<br \/>\nModulo Division: 10<br \/>\nIncrement the value of a by 1: 11<br \/>\nDecremented the value of b by 1: 14<\/div>\n<h4>2. Increment Operator in C<\/h4>\n<p>Mainly used for incrementing the value of an integer. It is represented by the \u2018++\u2019 operator. ++x will increase the value of the variable x instantly. But if it is placed after the variable then it gets increased before the execution of the next statement.<\/p>\n<p><strong>Example of C Increment Operator<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\nint main() {\n  int a = 10;\n  ++a;\n  printf(\"Value of a: %d\",a);\n  return 0;\n}\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\"><span style=\"font-weight: 400\">Value of a: 11<\/span><\/div>\n<h4>3. Decrement Operator in C<\/h4>\n<p>Mainly used for decrementing the value of an integer. It is represented by the \u2018&#8211;\u2019 operator. &#8211;x will decrease the value of the variable x instantly. But if it is placed after the variable then it gets decreased before the execution of the next statement.<\/p>\n<p><strong>Example of C Decrement Operator<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\nint main() {\n  int a = 10;\n  --a;\n  printf(\"Value of a: %d\",a);\n  return 0;\n}\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\"><span style=\"font-weight: 400\">Value of a: 9<\/span><\/div>\n<h4>4. Assignment Operators in C<\/h4>\n<p><span style=\"font-weight: 400\">The purpose of this operator is to assign value to a variable. The most used assignment operator is \u201c=\u201d.\u00a0<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Operator<\/b><\/td>\n<td><b>Example<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">=<\/span><\/td>\n<td><span style=\"font-weight: 400\">a=b or b=a<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">+=<\/span><\/td>\n<td><span style=\"font-weight: 400\">a += b or a = a+b<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">-=<\/span><\/td>\n<td><span style=\"font-weight: 400\">a -=b or a = a-b<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">*=<\/span><\/td>\n<td><span style=\"font-weight: 400\">a *= b or a = a*b<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">\/=<\/span><\/td>\n<td><span style=\"font-weight: 400\">a \/= b or a = a\/b<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">%=<\/span><\/td>\n<td><span style=\"font-weight: 400\">a %= b or a = a%b<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Example of Assignment Operators in C:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\nint main()\n{\n  int a = 99, result;\n  result = a;\n  printf(\"Welcome to TechVidvan Tutorials...\\n\");\n  printf(\"Value of result = %d\\n\", result);\n  result += a;\t\/\/ or result = result + a\n  printf(\"Value of result = %d\\n\", result); \/\/ After Addition\n  result -= a;\t\/\/ or result = result - a\t \n  printf(\"Value of result = %d\\n\", result); \/\/ After Subtraction\n  result *= a;\t\/\/ or result = result * a\t \n  printf(\"Value of result = %d\\n\", result); \/\/ After Multiplication\n  result \/= a;\t\/\/ or result = result \/ a\n  printf(\"Value of result = %d\\n\", result);\n  return 0;\n}\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Welcome to TechVidvan Tutorials&#8230;<br \/>\nValue of result = 99<br \/>\nValue of result = 198<br \/>\nValue of result = 99<br \/>\nValue of result = 9801<br \/>\nValue of result = 99<\/div>\n<h4>5. Relational Operators in C<\/h4>\n<p><span style=\"font-weight: 400\">Mainly used for checking relationships between operands. With the help of this operator, you can check whether one operand is equal to or greater than the other operand or not.<\/span><\/p>\n<p><span style=\"font-weight: 400\">It returns 1 when the relation is true. And when it is false, it returns 0.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Operator<\/b><\/td>\n<td><b>What it does<\/b><\/td>\n<td><b>Example<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">==<\/span><\/td>\n<td><span style=\"font-weight: 400\">Equal to<\/span><\/td>\n<td><span style=\"font-weight: 400\">5==5 will be 1<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">&gt;<\/span><\/td>\n<td><span style=\"font-weight: 400\">Greater than<\/span><\/td>\n<td><span style=\"font-weight: 400\">5&gt;6 will be 0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">&lt;<\/span><\/td>\n<td><span style=\"font-weight: 400\">Less than<\/span><\/td>\n<td><span style=\"font-weight: 400\">6&lt;7 will be 1<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">&gt;=<\/span><\/td>\n<td><span style=\"font-weight: 400\">Greater than equal to<\/span><\/td>\n<td><span style=\"font-weight: 400\">2 &gt;= 1 will be 1<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">&lt;=<\/span><\/td>\n<td><span style=\"font-weight: 400\">Less than equal to<\/span><\/td>\n<td><span style=\"font-weight: 400\">1 &lt;= 2 will be 1<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">!=<\/span><\/td>\n<td><span style=\"font-weight: 400\">Not equal to\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400\">5 != 6 will be 1<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Example of Relational Operators in C:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\nint main()\n{\n  int j = 6, t = 4;\n\n  printf(\"%d == %d is %d \\n\", j, t, j == t);\n  printf(\"%d &gt; %d is %d \\n\", j, t, j &gt; t);\n  printf(\"%d &lt; %d is %d \\n\", j, t, j &lt; t);\n  printf(\"%d != %d is %d \\n\", j, t, j != t);\n  printf(\"%d &gt;= %d is %d \\n\", j, t, j &gt;= t);\n  printf(\"%d &lt;= %d is %d \\n\", j, t, j &lt;= t);\n\n  return 0;\n}\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">6 == 4 is 0<br \/>\n6 &gt; 4 is 1<br \/>\n6 &lt; 4 is 0<br \/>\n6 != 4 is 1<br \/>\n6 &gt;= 4 is 1<br \/>\n6 &lt;= 4 is 0<\/div>\n<h4>6. Logical Operators in C<\/h4>\n<p><span style=\"font-weight: 400\">In the C programming language, Logical operators are mostly used for decision making. A logical operator returns either 0 or 1 whether the condition is true or false.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Operator<\/b><\/td>\n<td><b>What it does<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">&amp;&amp; (Logical AND)<\/span><\/td>\n<td><span style=\"font-weight: 400\">True only if all conditions satisfy.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">|| (Logical OR)<\/span><\/td>\n<td><span style=\"font-weight: 400\">True only if either one condition satisfies.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">! (Logical Not)<\/span><\/td>\n<td><span style=\"font-weight: 400\">True only if the operand is 0.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Example of Logical Operators in C:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\nint main()\n{\n  int i = 5, j = 5, k = 10, final;\n\n  printf(\"i is equal to j or k greater than j is is %d \\n\", (i == j) &amp;&amp; (k &gt; j));\n\n  printf(\"i is equal to j or k less than j is %d \\n\", (i == j) || (k &lt; j));\n\n  printf(\"i not equal to j or k less than j is %d \\n\", (i != j) || (k &lt; j));\n\n  return 0;\n}\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">i is equal to j or k greater than j is 1<br \/>\ni is equal to j or k less than j is 1<br \/>\ni not equal to j or k less than j is 0<\/div>\n<h4>7. Conditional Operator in C<\/h4>\n<p>Also known as Ternary operator. The main purpose of conditional operators is in decision making statements. It is similar to an if-else statement.<\/p>\n<p>Syntax of a conditional operator:-<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Expression1? statement1: statement2; \n<\/pre>\n<ul>\n<li>Expression1 is a boolean expression, it can be either true or false.<\/li>\n<li>If the Expression1 returns true then statement1 will get executed.<\/li>\n<li>If the Expression1 returns false then statement2 will get executed.<\/li>\n<\/ul>\n<p><strong>Example of Conditional Operators in C:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;  \nint main()  \n{  \nint number=13;\n(number&gt;14)? (printf(\"It is greater than number 14!\")) : (printf(\"It is less than number 14!\"));  \/\/ conditional operator  \nreturn 0;  \n}\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\"><span style=\"font-weight: 400\">It is less than number 14!<\/span><\/div>\n<p><span style=\"font-weight: 400\">If we set the number to 15 then it will give the output\u21d2<\/span> <b>It is greater than number 14!<\/b><\/p>\n<h4>8. Bitwise Operator in C<\/h4>\n<p><span style=\"font-weight: 400\">C also provides special operators for bit operation between two variables.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Operator<\/b><\/td>\n<td><b>Also known as<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">&lt;&lt;<\/span><\/td>\n<td><span style=\"font-weight: 400\">Binary Left Shift Operator<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">&gt;&gt;<\/span><\/td>\n<td><span style=\"font-weight: 400\">Binary Right Shift Operator<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">~<\/span><\/td>\n<td><span style=\"font-weight: 400\">Binary Ones Complement Operator<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">&amp;<\/span><\/td>\n<td><span style=\"font-weight: 400\">Binary AND Operator<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">^<\/span><\/td>\n<td><span style=\"font-weight: 400\">Binary XOR Operator<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">|<\/span><\/td>\n<td><span style=\"font-weight: 400\">Binary OR Operator<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Example of Bitwise Operators in C:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\nint main() {\nint a = 50;      \nint b = 5;    \nint result = 0;      \t \nresult = a &amp; b;   \t\/\/ Binary AND Operator\nprintf(\"Binary AND Operator of a and b is %d\\n\", result );\nresult = a ^ b;   \t\/\/ Binary XOR Operator\nprintf(\"Binary XOR Operator of a and b is %d\\n\", result );\nresult = ~a;      \t\/\/ Binary Ones Complement Operator\nprintf(\"Binary Ones Complement Operator of a is %d\\n\", result );\nresult = a &lt;&lt; 2; \t\/\/ Binary Left Shift Operator\nprintf(\"Binary Left Shift Operator of a is %d\\n\", result );\nresult = a &gt;&gt; 2; \t\/\/ Binary Right Shift Operator\nprintf(\"Binary Right Shift Operator of a is %d\\n\", result );\n}\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Binary AND Operator of a and b is 0<br \/>\nBinary XOR Operator of a and b is 55<br \/>\nBinary Ones Complement Operator of a is -51<br \/>\nBinary Left Shift Operator of a is 200<br \/>\nBinary Right Shift Operator of a is 12<\/div>\n<h4>9. Misc operators in C<\/h4>\n<p><span style=\"font-weight: 400\">It includes operators like sizeof(), reference operator(&amp;), pointer operator(*), condition operator(?).<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Operator<\/b><\/td>\n<td><b>Example<\/b><\/td>\n<td><b>What it does<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">sizeof<\/span><\/td>\n<td><span style=\"font-weight: 400\">sizeof(a)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns the size occupied by the data type of the operand.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">&amp;<\/span><\/td>\n<td><span style=\"font-weight: 400\">&amp;a<\/span><\/td>\n<td><span style=\"font-weight: 400\">Refers to the memory address where operand is stored.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">*<\/span><\/td>\n<td><span style=\"font-weight: 400\">*a<\/span><\/td>\n<td><span style=\"font-weight: 400\">A pointer.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">?:<\/span><\/td>\n<td><span style=\"font-weight: 400\">a? b: statement<\/span><\/td>\n<td><span style=\"font-weight: 400\">Alternative of if-else.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Example:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include&lt;stdio.h&gt;\nint main()\n{\nprintf(\"Welcome to TechVidvan tutorials!\\n\\n\");\nint number = 10, *pointer;\nint another_number=13;\npointer=&amp;number;\nprintf(\"Example of pointer and reference operator!\\n\");\nprintf(\"Memory address: %d\\n\",pointer);\nprintf(\"Example of condition operator!\\n\");\n(another_number&gt;14)? (printf(\"It is greater than number 14!\")) : (printf(\"It is less than number 14!\"));\n\/\/ if you put the value 15 in another_number variable then it will output&gt;&gt; It is greater than number 14!\nreturn 0;\n}\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Welcome to TechVidvan tutorials!<br \/>\nExample of pointer and reference operator!<br \/>\nMemory address: 1701039932<br \/>\nExample of condition operator!<br \/>\nIt is less than number 14!<\/div>\n<h3>Special Operators in C<\/h3>\n<p>Apart from these operators, C supports special operators:-<\/p>\n<p><strong>1. sizeof():-<\/strong> If you want to check the size of data types available in C then you can do it by using sizeof() operator.<\/p>\n<p><strong>2. Reference Operator (&amp;):<\/strong>&#8211; Used for returning the address of a memory location.<\/p>\n<p><strong>3. Pointer Operator (*):<\/strong>&#8211; It is a pointer to a variable.<\/p>\n<h4>sizeof operator in C<\/h4>\n<p>If you want to check the size of data types available in C then you can do it by using sizeof() operator. Below is the code to show the storage sizes of int, char and float data types.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\nint main()\n{\n  printf(\"Sizes of int, char and float...\\n\");\n  printf(\"int is: %d bytes\\n\", sizeof(int));\n  printf(\"char is: %d bytes\\n\", sizeof(char));\n  printf(\"float is: %d bytes\\n\", sizeof(float));\n  return 0;\n}\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Sizes of int, char and float&#8230;<br \/>\nint is: 4 bytes<br \/>\nchar is: 1 bytes<br \/>\nfloat is: 4 bytes<\/div>\n<h4>Comma Operator in C<\/h4>\n<p>Mainly used for separating expressions, variable declarations, function calls etc. It works on two operands. It is a binary operator. Comma acts as a separator.<\/p>\n<p><strong>Syntax of comma operator:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int a=1, b=2, c=3, d=4;<\/pre>\n<h3>Operator Precedence in C<\/h3>\n<p><span style=\"font-weight: 400\">In between operators, some have higher precedence and some have lower precedence. For example, Division has a higher precedence than subtraction operator.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Operator Precedence determines how the expression is evaluated.\u00a0<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Category<\/b><\/td>\n<td><b>Operator<\/b><\/td>\n<td><b>Associativity<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Postfix<\/span><\/td>\n<td><span style=\"font-weight: 400\">() [] -&gt; . ++ &#8211; &#8211;<\/span><\/td>\n<td><span style=\"font-weight: 400\">Left to right<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Unary<\/span><\/td>\n<td><span style=\"font-weight: 400\">+ &#8211; ! ~ ++ &#8211; &#8211; (type)* &amp; sizeof<\/span><\/td>\n<td><span style=\"font-weight: 400\">Right to left<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Multiplicative<\/span><\/td>\n<td><span style=\"font-weight: 400\">* \/ %<\/span><\/td>\n<td><span style=\"font-weight: 400\">Left to right<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Additive<\/span><\/td>\n<td><span style=\"font-weight: 400\">+ &#8211;<\/span><\/td>\n<td><span style=\"font-weight: 400\">Left to right<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Shift<\/span><\/td>\n<td><span style=\"font-weight: 400\">&lt;&lt; &gt;&gt;<\/span><\/td>\n<td><span style=\"font-weight: 400\">Left to right<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Relational<\/span><\/td>\n<td><span style=\"font-weight: 400\">&lt; &lt;= &gt; &gt;=<\/span><\/td>\n<td><span style=\"font-weight: 400\">Left to right<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Equality<\/span><\/td>\n<td><span style=\"font-weight: 400\">== !=<\/span><\/td>\n<td><span style=\"font-weight: 400\">Left to right<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Bitwise AND<\/span><\/td>\n<td><span style=\"font-weight: 400\">&amp;<\/span><\/td>\n<td><span style=\"font-weight: 400\">Left to right<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Bitwise XOR<\/span><\/td>\n<td><span style=\"font-weight: 400\">^<\/span><\/td>\n<td><span style=\"font-weight: 400\">Left to right<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Bitwise OR<\/span><\/td>\n<td><span style=\"font-weight: 400\">|<\/span><\/td>\n<td><span style=\"font-weight: 400\">Left to right<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Logical AND<\/span><\/td>\n<td><span style=\"font-weight: 400\">&amp;&amp;<\/span><\/td>\n<td><span style=\"font-weight: 400\">Left to right<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Logical OR<\/span><\/td>\n<td><span style=\"font-weight: 400\">||<\/span><\/td>\n<td><span style=\"font-weight: 400\">Left to right<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Conditional<\/span><\/td>\n<td><span style=\"font-weight: 400\">?:<\/span><\/td>\n<td><span style=\"font-weight: 400\">Right to left<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Assignment<\/span><\/td>\n<td><span style=\"font-weight: 400\">= += -= *= \/= %=&gt;&gt;= &lt;&lt;= &amp;= ^= |=<\/span><\/td>\n<td><span style=\"font-weight: 400\">Right to left<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Comma<\/span><\/td>\n<td><span style=\"font-weight: 400\">,<\/span><\/td>\n<td><span style=\"font-weight: 400\">Left to right<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Operators which have higher precedence are at the top of the table. And operators which have lower precedence are at the bottom.<\/p>\n<h3>Summary<\/h3>\n<p>An operator is a symbol which operates on a variable or value. There are types of operators like arithmetic, logical, conditional, relational, bitwise, assignment operators etc. Some special types of operators are also present in C like sizeof(), Pointer operator, Reference operator etc.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The C programming language comes with very rich built-in functions. There is a vast use of operators in all programming languages. Operators are a useful and powerful feature of the C\/C++ programming language. Without&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":81234,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3510],"tags":[3599,3600,3601,3602,3603,3604,3605,3606],"class_list":["post-80943","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-programming","tag-arithmetic-operator-in-c","tag-bitwise-operator-in-c","tag-c-operators","tag-conditional-operator-in-c","tag-logical-operator-in-c","tag-operator-precedence-in-c","tag-operators-in-c","tag-relational-operator-in-c"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>C Operators - Types and Examples - TechVidvan<\/title>\n<meta name=\"description\" content=\"Learn about various Operators in C like Arithmetic, Logical, Bitwise, Relational, Conditional etc. Learn about C Operator Precedence.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/c-operators-types-and-examples\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C Operators - Types and Examples - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Learn about various Operators in C like Arithmetic, Logical, Bitwise, Relational, Conditional etc. Learn about C Operator Precedence.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/c-operators-types-and-examples\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-22T03:30:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/Operators-in-C.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C Operators - Types and Examples - TechVidvan","description":"Learn about various Operators in C like Arithmetic, Logical, Bitwise, Relational, Conditional etc. Learn about C Operator Precedence.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/c-operators-types-and-examples\/","og_locale":"en_US","og_type":"article","og_title":"C Operators - Types and Examples - TechVidvan","og_description":"Learn about various Operators in C like Arithmetic, Logical, Bitwise, Relational, Conditional etc. Learn about C Operator Precedence.","og_url":"https:\/\/techvidvan.com\/tutorials\/c-operators-types-and-examples\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2021-06-22T03:30:03+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/Operators-in-C.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/c-operators-types-and-examples\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/c-operators-types-and-examples\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"C Operators &#8211; Types and Examples","datePublished":"2021-06-22T03:30:03+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/c-operators-types-and-examples\/"},"wordCount":1280,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/c-operators-types-and-examples\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/Operators-in-C.jpg","keywords":["Arithmetic Operator in C","Bitwise Operator in C","C Operators","Conditional Operator in C","Logical Operator in C","Operator Precedence in C","Operators in C","Relational Operator in C"],"articleSection":["C Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/c-operators-types-and-examples\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/c-operators-types-and-examples\/","url":"https:\/\/techvidvan.com\/tutorials\/c-operators-types-and-examples\/","name":"C Operators - Types and Examples - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/c-operators-types-and-examples\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/c-operators-types-and-examples\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/Operators-in-C.jpg","datePublished":"2021-06-22T03:30:03+00:00","description":"Learn about various Operators in C like Arithmetic, Logical, Bitwise, Relational, Conditional etc. Learn about C Operator Precedence.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/c-operators-types-and-examples\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/c-operators-types-and-examples\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/c-operators-types-and-examples\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/Operators-in-C.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/Operators-in-C.jpg","width":1200,"height":628,"caption":"Operators in C"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/c-operators-types-and-examples\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"C Operators &#8211; Types and Examples"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/80943","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=80943"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/80943\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/81234"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=80943"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=80943"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=80943"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}