{"id":5707,"date":"2023-03-29T12:13:18","date_gmt":"2023-03-29T12:13:18","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=5707"},"modified":"2023-03-29T12:25:31","modified_gmt":"2023-03-29T12:25:31","slug":"arithmetic-operators-in-cpp","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/arithmetic-operators-in-cpp\/","title":{"rendered":"Arithmetic Operators in C++"},"content":{"rendered":"\n<p>In this article, we are going to learn about arithmetic <a href=\"https:\/\/gyanipandit.com\/programming\/operators-in-cpp\/\">operators in C++<\/a>. As the name says, Arithmetic operators are the operators, which are used to perform arithmetic operations on the data, like addition, subtraction, multiplication, division, etc.<\/p>\n\n\n\n<h2 class=\"has-text-align-center wp-block-heading\">Arithmetic Operators in C++<\/h2>\n\n\n\n<p>In the below table, you can find the different arithmetic operator symbols, and then we will also perform a simple program to understand the arithmetic operators. For sake of example in the table, consider a = 10 and b = 5.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>Operator<\/th><th>Description<\/th><th>Example<\/th><\/tr><tr><td>+<\/td><td>This operator is used for the addition operation<\/td><td>c = a+b; c contains 15 as the result<\/td><\/tr><tr><td>&#8211;<\/td><td>This operator is used for the subtraction operation<\/td><td>c = a-b; c contains 5 as the result<\/td><\/tr><tr><td>*<\/td><td>This operator is used for a multiplication operation<\/td><td>c = a*b; c contains 50 as the result<\/td><\/tr><tr><td>\/<\/td><td>This operator is used for division operation<\/td><td>c = 10\/5; c contains 2 as the result<\/td><\/tr><tr><td>%<\/td><td>This operator is used to get the remainder when we divide two numbers<\/td><td>c = a % b; c contains 0 as the result since 5 divides 10 and gives a remainder of 0<\/td><\/tr><tr><td>++<\/td><td>This operator is used for incrementation operation, i.e. adding 1 to some number<\/td><td>++a; now the variable a contains 11<\/td><\/tr><tr><td>&#8212;<\/td><td>This operator is used for decrement operation, i.e. subtracting 1 from some number<\/td><td>&#8211;b; now, the variable b contains 4<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>As you can see in the above table, we have listed the arithmetic operator symbols, which can be used to carry out some arithmetic operations, like addition, subtraction, multiplication, division, etc.<\/p>\n\n\n\n<p>Let&#8217;s have a look at a simple program, in which, we will try to perform these different arithmetic operations.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">#include &lt;iostream&gt;<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">int main()<br>{<br>&nbsp; &nbsp; int a = 10, b = 2;<br>&nbsp; &nbsp; std::cout &lt;&lt; &#8220;Addition Operation:&#8221;&lt;&lt;a+b &lt;&lt; std::endl;<br>&nbsp; &nbsp; std::cout &lt;&lt; &#8220;Subtraction Operation:&#8221;&lt;&lt;a-b &lt;&lt; std::endl;<br>&nbsp; &nbsp; std::cout &lt;&lt; &#8220;Multiplication Operation:&#8221;&lt;&lt;a*b &lt;&lt; std::endl;<br>&nbsp; &nbsp; std::cout &lt;&lt; &#8220;Division Operation:&#8221;&lt;&lt;a\/b &lt;&lt; std::endl;<br>&nbsp; &nbsp; std::cout &lt;&lt; &#8220;modulus Operation:&#8221;&lt;&lt;a%b &lt;&lt; std::endl;<br>&nbsp; &nbsp; std::cout &lt;&lt; &#8220;Increment Operation:&#8221;&lt;&lt;++a &lt;&lt; std::endl; \/\/ pre-increment<br>&nbsp; &nbsp; std::cout &lt;&lt; &#8220;Decrement Operation:&#8221;&lt;&lt;&#8211;b&lt;&lt; std::endl;\/\/pre-decrement<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">&nbsp; &nbsp; return 0;<br>}<\/p>\n\n\n\n<p>If you try to execute the above program, this is the output that you get.<\/p>\n\n\n\n<p>Addition Operation:12<br>Subtraction Operation:8<br>Multiplication Operation:20<br>Division Operation:5<br>modulus Operation:0<br>Increment Operation:11<br>Decrement Operation:1<\/p>\n\n\n\n<p>As you can see, we were able to do some arithmetic operations on the data, and as and when required, you can make use of these operator symbols, to perform these arithmetic operations.<\/p>\n\n\n\n<p>Note that with the unary increment and decrement operators, we have things like pre-increment, post-increment, and pre-decrement and post decrement. In the above program, we are doing pre-operations. You can explore more about that.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">FAQs related to Arithmetic operators in C++<\/h4>\n\n\n\n<div class=\"wp-block-rank-math-faq-block\"><div class=\"rank-math-faq-item\"><h3 class=\"rank-math-question\">Q: What are arithmetic operators in C++?<\/h3><div class=\"rank-math-answer\"><strong>Ans:<\/strong> Using the arithmetic operators, we can perform some arithmetic operations, like addition, subtraction, multiplication, division, etc.<\/div><\/div><div class=\"rank-math-faq-item\"><h3 class=\"rank-math-question\">Q: What are the different arithmetic operator symbols in C++?<\/h3><div class=\"rank-math-answer\"><strong>Ans:<\/strong> The arithmetic operator symbols in C++ include the following symbols &#8211; (+, -, *, \/, %, ++, &#8211;)<\/div><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we are going to learn about arithmetic operators in C++. As the name says, Arithmetic operators are the operators, which are used to perform arithmetic operations on the data, like addition, subtraction, multiplication, division, etc. Arithmetic Operators in C++ In the below table, you can find the different arithmetic operator symbols, and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[39],"tags":[209,40,136],"class_list":{"0":"post-5707","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-c","7":"tag-arithmetic-operators-in-c","8":"tag-c","9":"tag-cpp"},"_links":{"self":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/5707","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/comments?post=5707"}],"version-history":[{"count":2,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/5707\/revisions"}],"predecessor-version":[{"id":5713,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/5707\/revisions\/5713"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=5707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=5707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=5707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}