{"id":138,"date":"2026-05-21T04:54:39","date_gmt":"2026-05-21T04:54:39","guid":{"rendered":"https:\/\/gigz.pk\/cpp\/?post_type=lesson&#038;p=138"},"modified":"2026-05-22T11:35:44","modified_gmt":"2026-05-22T11:35:44","slug":"binary-operators","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/cpp\/?lesson=binary-operators","title":{"rendered":"Binary Operators"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Binary operators in C++ are operators that work on two operands (values or variables). They are widely used for calculations, comparisons, assignments, and logical operations.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are Binary Operators?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Binary operators perform operations using two operands.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a + b<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>a<\/code> is the first operand<\/li>\n\n\n\n<li><code>b<\/code> is the second operand<\/li>\n\n\n\n<li><code>+<\/code> is the binary operator<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Why Use Binary Operators?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Binary operators are important because they:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Perform mathematical operations<\/li>\n\n\n\n<li>Compare values<\/li>\n\n\n\n<li>Control program logic<\/li>\n\n\n\n<li>Simplify coding tasks<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Types of Binary Operators in C++<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The main types of binary operators are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Arithmetic Operators<\/li>\n\n\n\n<li>Relational Operators<\/li>\n\n\n\n<li>Logical Operators<\/li>\n\n\n\n<li>Assignment Operators<\/li>\n\n\n\n<li>Bitwise Operators<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\">Arithmetic Operators<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Arithmetic operators are used for mathematical calculations.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Arithmetic Operators<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Operator<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td><code>+<\/code><\/td><td>Addition<\/td><\/tr><tr><td><code>-<\/code><\/td><td>Subtraction<\/td><\/tr><tr><td><code>*<\/code><\/td><td>Multiplication<\/td><\/tr><tr><td><code>\/<\/code><\/td><td>Division<\/td><\/tr><tr><td><code>%<\/code><\/td><td>Modulus<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Example of Arithmetic Operators<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;<br>using namespace std;<br><br>int main() {<br><br>    int a = 10, b = 5;<br><br>    cout &lt;&lt; a + b &lt;&lt; endl;<br>    cout &lt;&lt; a - b &lt;&lt; endl;<br>    cout &lt;&lt; a * b &lt;&lt; endl;<br>    cout &lt;&lt; a \/ b &lt;&lt; endl;<br>    cout &lt;&lt; a % b &lt;&lt; endl;<br><br>    return 0;<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Output<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>15<br>5<br>50<br>2<br>0<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">Relational Operators<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Relational operators compare two values.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Relational Operators<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Operator<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td><code>==<\/code><\/td><td>Equal to<\/td><\/tr><tr><td><code>!=<\/code><\/td><td>Not equal to<\/td><\/tr><tr><td><code>&gt;<\/code><\/td><td>Greater than<\/td><\/tr><tr><td><code>&lt;<\/code><\/td><td>Less than<\/td><\/tr><tr><td><code>&gt;=<\/code><\/td><td>Greater than or equal to<\/td><\/tr><tr><td><code>&lt;=<\/code><\/td><td>Less than or equal to<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Example of Relational Operators<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;<br>using namespace std;<br><br>int main() {<br><br>    int a = 10, b = 5;<br><br>    cout &lt;&lt; (a &gt; b) &lt;&lt; endl;<br>    cout &lt;&lt; (a &lt; b) &lt;&lt; endl;<br>    cout &lt;&lt; (a == b) &lt;&lt; endl;<br><br>    return 0;<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Output<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>1<br>0<br>0<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">Logical Operators<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Logical operators combine conditions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Logical Operators<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Operator<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td><code>&amp;&amp;<\/code><\/td><td>Logical AND<\/td><\/tr><tr><td>`<\/td><td><\/td><\/tr><tr><td><code>!<\/code><\/td><td>Logical NOT<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Example of Logical Operators<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;<br>using namespace std;<br><br>int main() {<br><br>    int a = 10, b = 5;<br><br>    cout &lt;&lt; (a &gt; 5 &amp;&amp; b &lt; 10) &lt;&lt; endl;<br>    cout &lt;&lt; (a &gt; 5 || b &gt; 10) &lt;&lt; endl;<br><br>    return 0;<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Output<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>1<br>1<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">Assignment Operators<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Assignment operators assign values to variables.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Assignment Operators<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Operator<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td><code>=<\/code><\/td><td>Assign<\/td><\/tr><tr><td><code>+=<\/code><\/td><td>Add and assign<\/td><\/tr><tr><td><code>-=<\/code><\/td><td>Subtract and assign<\/td><\/tr><tr><td><code>*=<\/code><\/td><td>Multiply and assign<\/td><\/tr><tr><td><code>\/=<\/code><\/td><td>Divide and assign<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Example of Assignment Operators<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;<br>using namespace std;<br><br>int main() {<br><br>    int a = 10;<br><br>    a += 5;<br><br>    cout &lt;&lt; a &lt;&lt; endl;<br><br>    a -= 3;<br><br>    cout &lt;&lt; a &lt;&lt; endl;<br><br>    return 0;<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Output<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>15<br>12<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">Bitwise Operators<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Bitwise operators work directly on binary values.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Bitwise Operators<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Operator<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td><code>&amp;<\/code><\/td><td>Bitwise AND<\/td><\/tr><tr><td>`<\/td><td>`<\/td><\/tr><tr><td><code>^<\/code><\/td><td>Bitwise XOR<\/td><\/tr><tr><td><code>&lt;&lt;<\/code><\/td><td>Left Shift<\/td><\/tr><tr><td><code>&gt;&gt;<\/code><\/td><td>Right Shift<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Example of Bitwise Operator<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;<br>using namespace std;<br><br>int main() {<br><br>    int a = 5, b = 3;<br><br>    cout &lt;&lt; (a &amp; b);<br><br>    return 0;<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Output<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>1<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Difference Between Unary and Binary Operators<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Unary Operators<\/th><th>Binary Operators<\/th><\/tr><\/thead><tbody><tr><td>Work on one operand<\/td><td>Work on two operands<\/td><\/tr><tr><td>Example: <code>++a<\/code><\/td><td>Example: <code>a + b<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Real-Life Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a calculator:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You enter two numbers<\/li>\n\n\n\n<li>Operator performs calculation between them<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">This is how binary operators work.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Binary Operators are Important<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Binary operators are important because they:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Build program logic<\/li>\n\n\n\n<li>Perform calculations<\/li>\n\n\n\n<li>Help in decision making<\/li>\n\n\n\n<li>Are essential in every C++ program<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Applications of Binary Operators<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Binary operators are used in:<\/p>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1779449779206\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Mathematical calculations<\/li>\n\n\n\n<li>Conditional statements<\/li>\n\n\n\n<li>Data processing<\/li>\n\n\n\n<li>Bit manipulation<\/li>\n\n\n\n<li>Software development<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Binary operators in C++ work with two operands and perform arithmetic, logical, relational, assignment, and bitwise operations. They are fundamental building blocks of programming and are widely used in all types of applications.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/cpp\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">Advanced C++ > Operator Overloading > Binary Operators<\/span><\/span><\/div>","protected":false},"menu_order":45,"template":"","class_list":["post-138","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Binary Operators - Learn C++Language with GiGz.PK<\/title>\n<meta name=\"description\" content=\"Learn C++ binary operators with examples of arithmetic, relational, logical, assignment, and bitwise operators used in programming.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Binary Operators - Learn C++Language with GiGz.PK\" \/>\n<meta property=\"og:description\" content=\"Learn C++ binary operators with examples of arithmetic, relational, logical, assignment, and bitwise operators used in programming.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/\" \/>\n<meta property=\"og:site_name\" content=\"Learn C++Language with GiGz.PK\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-22T11:35:44+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/?lesson=binary-operators\",\"url\":\"https:\\\/\\\/gigz.pk\\\/\",\"name\":\"Binary Operators - Learn C++Language with GiGz.PK\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/#website\"},\"datePublished\":\"2026-05-21T04:54:39+00:00\",\"dateModified\":\"2026-05-22T11:35:44+00:00\",\"description\":\"Learn C++ binary operators with examples of arithmetic, relational, logical, assignment, and bitwise operators used in programming.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/cpp\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Advanced C++ > Operator Overloading > Binary Operators\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/\",\"name\":\"Learn C++Language with GiGz.PK\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Binary Operators - Learn C++Language with GiGz.PK","description":"Learn C++ binary operators with examples of arithmetic, relational, logical, assignment, and bitwise operators used in programming.","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:\/\/gigz.pk\/","og_locale":"en_US","og_type":"article","og_title":"Binary Operators - Learn C++Language with GiGz.PK","og_description":"Learn C++ binary operators with examples of arithmetic, relational, logical, assignment, and bitwise operators used in programming.","og_url":"https:\/\/gigz.pk\/","og_site_name":"Learn C++Language with GiGz.PK","article_modified_time":"2026-05-22T11:35:44+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/cpp\/?lesson=binary-operators","url":"https:\/\/gigz.pk\/","name":"Binary Operators - Learn C++Language with GiGz.PK","isPartOf":{"@id":"https:\/\/gigz.pk\/cpp\/#website"},"datePublished":"2026-05-21T04:54:39+00:00","dateModified":"2026-05-22T11:35:44+00:00","description":"Learn C++ binary operators with examples of arithmetic, relational, logical, assignment, and bitwise operators used in programming.","breadcrumb":{"@id":"https:\/\/gigz.pk\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/cpp"},{"@type":"ListItem","position":2,"name":"Advanced C++ > Operator Overloading > Binary Operators"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/cpp\/#website","url":"https:\/\/gigz.pk\/cpp\/","name":"Learn C++Language with GiGz.PK","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/cpp\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/cpp\/index.php?rest_route=\/wp\/v2\/lesson\/138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/cpp\/index.php?rest_route=\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/cpp\/index.php?rest_route=\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/cpp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}