<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1963654198922371192</id><updated>2020-07-30T17:57:35.590+05:30</updated><category term="CPP"/><category term="Flow of Control"/><category term="Pointers"/><category term="Functions"/><category term="Datatype"/><category term="Operators"/><title type='text'>Computer Code C</title><subtitle type='html'>The basic and complete website for competitive coding in C++. Register freely and get your questions answered by renowned teachers and fellow coders from all across the globe. #HappyCoding</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://www.computercodec.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>35</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-8508672485081914186</id><published>2020-07-30T17:57:00.001+05:30</published><updated>2020-07-30T17:57:35.521+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Functions"/><title type='text'>Function Call in C++</title><content type='html'>&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14pt; line-height: 107%;&quot;&gt;As we know, a function is a group of statements combined to perform a particular task. These functions need declarations and definitions. But how to use them in programs? We will read about this topic in this article. But before that let us read about parameters.&lt;/span&gt;&lt;/p&gt; &lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 16pt; line-height: 107%;&quot;&gt;Formal &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 16pt; line-height: 107%;&quot;&gt;Parameters&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14pt; line-height: 107%;&quot;&gt;These are the variables appearing in the function signature. When we declare a function, we put some parameter list to specify which kind of values can be fed into the function. These parameters are called &lt;/span&gt;&lt;/p&gt; &lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 16pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 16pt; line-height: 107%;&quot;&gt;Actual &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 16pt; line-height: 107%;&quot;&gt;Parameters&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14pt; line-height: 107%;&quot;&gt;The variables which are fed into the function at the time of function call are called the &lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14pt; line-height: 107%;&quot;&gt;The following program makes this concept clearer.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;script src=&quot;https://gist.github.com/Computer-Code-C/d4954aa58ec3842e5ab241844ab283e4.js&quot;&gt;&lt;/script&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14pt; line-height: 107%;&quot;&gt;Formal parameters are local to the function and cannot be accessed from outside that function.&amp;nbsp; See the following program.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14pt; line-height: 107%;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;script src=&quot;https://gist.github.com/Computer-Code-C/b4820fddc44eab5f4510650ec705582f.js&quot;&gt;&lt;/script&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 16pt; line-height: 107%;&quot;&gt;Calling &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 16pt; line-height: 107%;&quot;&gt;a Function &lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14pt; line-height: 107%;&quot;&gt;When we wish to use a function, we need to call it into the&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;font-family: Georgia, serif; font-size: 14pt;&quot;&gt;main()&lt;/b&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 14pt;&quot;&gt; function or the function where we want to use it. The function in which another function is called is termed as the &lt;i&gt;Calling Function&lt;/i&gt;.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14pt; line-height: 107%;&quot;&gt;The general syntax for function call is as follows:&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: Georgia, serif; font-size: 14pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;function_name (actual parameters);&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14pt; line-height: 107%;&quot;&gt;A function can be called within any other function using the exactly same syntax. The following program calls a function into another function and also into main().&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14pt; line-height: 107%;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;script src=&quot;https://gist.github.com/Computer-Code-C/cc5d7251fb12ac5497d14387f0599e21.js&quot;&gt;&lt;/script&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Explanation&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;: Here, when the execution starts from main(), the control encounters the function &#39;caller_function()&#39;. The control jumps to the function and starts executing. It then encounters the function &#39;sum()&#39;. Control again jumps to the function &#39;sum()&#39;. Once &#39;sum&#39; is executed, control comes back to &#39;caller_function()&#39; and then back to main().&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14pt; line-height: 107%;&quot;&gt;Any function that is being called into another function must be at least declared before the caller function. For example, the following programs show error when compiled.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;script src=&quot;https://gist.github.com/Computer-Code-C/cd509d1ad1488ec29e082e74784f390b.js&quot;&gt;&lt;/script&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Explana&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;tion :&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;For any function to work properly, it must be at least declared before it is called. Here, &#39;caller_function()&#39; is called into main(). This gives no error as &#39;caller_function()&#39; is defined before main(). When the control checks the &#39;caller_function()&#39;, it encounters &#39;sum()&#39;. It searches for &#39;sum()&#39; declaration before the &#39;caller_function()&#39;. As &#39;sum()&#39; has been defined after &#39;caller_function()&#39; the compiler shows an error that &#39;sum&#39; has not been declared in the scope.&amp;nbsp;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;This program can be correctly written as :&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;/span&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt;&lt;script src=&quot;https://gist.github.com/Computer-Code-C/376c571513401b6c262f2cd1c915d028.js&quot;&gt;&lt;/script&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you find something wrong or if you wish to add some information in this article, feel free to comment on this post or contact us at &lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 14pt;&quot;&gt;Which topics you want an article on? Comment down on this post.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Do not stop here. Read all articles related to C++ &lt;/span&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 14pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to contribute any article for the website, feel free to share it on &lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14pt; line-height: 107%;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/8508672485081914186/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=8508672485081914186&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/8508672485081914186'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/8508672485081914186'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/function-call-in-c.html' title='Function Call in C++'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-4038047980229362324</id><published>2020-07-28T19:57:00.009+05:30</published><updated>2020-07-29T12:38:54.632+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Functions"/><title type='text'>Function Overloading In C++ (Part II)</title><content type='html'>&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A call to an overloaded function is resolved to a particular instance of the function through a process called &lt;i&gt;&lt;span style=&quot;color: black; mso-themecolor: text1;&quot;&gt;argument matching&lt;/span&gt;&lt;/i&gt;. Argument matching involves comparing the actual arguments of the call with the formal arguments of each declared instance of the function.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;There are three possible cases, a function call may result in :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A match&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; : A match is found for the function call.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;No match&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; : No match is found for the function call.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Ambiguous Match&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; : More than one defined instance match for a function call.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The compiler tries to find the best possible match for the function call.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;Search for an &lt;span style=&quot;color: #0070c0;&quot;&gt;Exact Match&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If the types and number of the actual arguments exactly match the types and number of formal arguments, the compiler invokes that particular instance. For example, &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;script src=&quot;https://gist.github.com/Computer-Code-C/4379244086bb01d9b8c5490caba7a3db.js&quot;&gt;&lt;/script&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Output Screen :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #843c0c; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #843C0C; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;Function 1 called&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Reason&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; : The actual argument (here 0) is int type.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;A Match through &lt;span style=&quot;color: #0070c0;&quot;&gt;Promotion&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If no exact match is found, an attempt is made to achieve a match through type promotion of the actual argument.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Integral Promotion &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;: Conversion of integer types (&lt;i&gt;char&lt;/i&gt;, &lt;i&gt;short&lt;/i&gt;, &lt;i&gt;enumerator&lt;/i&gt;) into &lt;i&gt;int&lt;/i&gt;(if all values of type can be represented by &lt;i&gt;int&lt;/i&gt;) or &lt;i&gt;unsigned&lt;/i&gt; &lt;i&gt;int&lt;/i&gt;(if all values can’t be represented by &lt;i&gt;int&lt;/i&gt;) is called integral promotion. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;So, if there is any overloaded function with &lt;i&gt;int&lt;/i&gt; formal type, all smaller integer type (&lt;i&gt;char&lt;/i&gt;, &lt;i&gt;short&lt;/i&gt;, &lt;i&gt;enumerator&lt;/i&gt;) are converted to &lt;i&gt;int&lt;/i&gt; if a perfect match is not found. (Note: In function overloading, the conversion of smaller integer datatypes to &lt;i&gt;int&lt;/i&gt; is favoured over their conversions to some larger types like &lt;i&gt;long&lt;/i&gt; &lt;i&gt;int&lt;/i&gt;or &lt;i&gt;long&lt;/i&gt; &lt;i&gt;long&lt;/i&gt; &lt;i&gt;int&lt;/i&gt;.)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;For example, &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;script src=&quot;https://gist.github.com/Computer-Code-C/e28472e0f3db859343a014634a568abc.js&quot;&gt;&lt;/script&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Output Screen :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #843c0c; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #843C0C; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;Function 1 called&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Reason&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; : ‘a’ is of type &lt;i&gt;char &lt;/i&gt;and thus promoted to type &lt;i&gt;int &lt;/i&gt;after no exact match is found thereby matching&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: #eeeeee; color: #0070c0; font-family: georgia, serif; font-size: 14pt;&quot;&gt;f(int)&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;.&amp;nbsp;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;background-color: #eeeeee; font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;A match through conversions following &lt;span style=&quot;color: #0070c0;&quot;&gt;Standard Conversion Rules &lt;/span&gt;of C++&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;As C++ puts it, it’s possible to convert any datatype to the other if we are fine with loss of information in some cases. Following this rule, the actual argument of any type can be converted to any other type to match the formal arguments. Here the program may show warnings regarding loss of information, but it will not be counted as an error. This last step is used when the matching through the first two steps has failed.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The following program makes the point clearer. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;script src=&quot;https://gist.github.com/Computer-Code-C/b737671dc1d3c69912466bc0bb431132.js&quot;&gt;&lt;/script&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Let us try to understand the steps taken by the compiler one by one.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Step 1&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. When the compiler executes the statement &lt;span style=&quot;background-color: #eeeeee; color: #0070c0;&quot;&gt;f(‘a’);&lt;/span&gt; it first tries to find a function named &lt;span style=&quot;color: #0070c0;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;f()&lt;/span&gt; &lt;/span&gt;that has a character type formal argument. As no such function exists, the compiler takes the next step.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Step 2&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. As &lt;i&gt;char&lt;/i&gt; is a smaller type than &lt;i&gt;int&lt;/i&gt;, compiler tries to find any function named &lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;f()&lt;/span&gt; &lt;/span&gt;with &lt;i&gt;int&lt;/i&gt; formal type so that it may match the function using integral promotion. It fails again and takes the next step.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;   &lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Step 3&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. It then goes for a standard conversion from &lt;i&gt;char&lt;/i&gt; to &lt;i&gt;short&lt;/i&gt; (in this case) and thus calls the function.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;But, there is an associated problem with this type conversion. As any type can be converted to any other type, there is a possibility of multiple matches. If the compiler encounters such a condition where the actual argument type can be changed to match the formal types of more than one function, it is flagged as an error. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Look at the following program. &lt;/span&gt;&lt;/p&gt;&lt;script src=&quot;https://gist.github.com/Computer-Code-C/af727da0eed79402d8a593a29d6a7979.js&quot;&gt;&lt;/script&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;b&gt;Output Screen :&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;background-color: #eeeeee; font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt; line-height: 107%;&quot;&gt;[&lt;span style=&quot;color: red;&quot;&gt;error&lt;/span&gt;] &lt;span style=&quot;color: #843c0c; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #843C0C; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt;call of overloaded f(char) is ambiguous&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;background-color: #eeeeee; color: #843c0c; font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #843C0C; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt;[note] candidates are&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;background-color: #eeeeee; color: #843c0c; font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #843C0C; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt;[note] void f(double)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;     &lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #843c0c; font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #843C0C; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;[note] void f(short int)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The compiler goes to step 3 as before. But while converting &lt;i&gt;char&lt;/i&gt;, it finds two possible matches. It can convert &lt;i&gt;char &lt;/i&gt;to &lt;i&gt;double &lt;/i&gt;and also to &lt;i&gt;short int&lt;/i&gt;. This results in an error as shown in the output.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;If you find something wrong or if you wish to add some information in this article, feel free to comment on this post or contact us at &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Which topics you want an article on? Comment down on this post.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Do not stop here. Read all articles related to C++ &lt;a href=&quot;https://www.computercodec.com/&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;here&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to contribute any article for the website, feel free to share it on &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. We will publish it on the website with your name.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/4038047980229362324/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=4038047980229362324&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/4038047980229362324'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/4038047980229362324'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/function-overloading-in-c-part-ii.html' title='Function Overloading In C++ (Part II)'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-7173012994685322049</id><published>2020-07-27T20:01:00.002+05:30</published><updated>2020-07-27T20:09:18.379+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Functions"/><title type='text'>Restrictions on Function Overloading</title><content type='html'>&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Function overloading is a very important feature of C++. It makes our tasks easier, implements polymorphism and makes the program execution faster. But there are obviously some &lt;b&gt;restrictions on Overloaded Functions&lt;/b&gt;. Let us see them in details.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 18pt; line-height: 107%;&quot;&gt;Restrictions &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 18pt; line-height: 107%;&quot;&gt;on Overloading Functions&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt; &lt;p class=&quot;MsoListParagraphCxSpFirst&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18pt;&quot;&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: Georgia; mso-fareast-font-family: Georgia;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;1.&lt;span style=&quot;font: 7pt &amp;quot;times new roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraphCxSpFirst&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: Georgia; mso-fareast-font-family: Georgia;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;&lt;span style=&quot;font: 7pt &amp;quot;times new roman&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;color: #7f6000; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14.0pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #7F6000; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent4; mso-themecolor: accent4; mso-themeshade: 128;&quot;&gt;First :&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: Georgia; mso-fareast-font-family: Georgia; text-indent: -18pt;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; text-indent: -18pt;&quot;&gt;Any two functions in a set of overloaded functions must have different argument list, i.e. all overloaded functions must have different signatures.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;void func (int a, int b)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//&lt;/span&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;void func (int x, int y)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//&lt;/span&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;These two functions are not overloaded as their signature is same. This will cause compiler error as both the functions are essentially exactly same.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18pt;&quot;&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: Georgia; mso-fareast-font-family: Georgia;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;2.&lt;span style=&quot;font: 7pt &amp;quot;times new roman&amp;quot;;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: Georgia; mso-fareast-font-family: Georgia;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;&lt;span style=&quot;font: 7pt &amp;quot;times new roman&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;color: #7f6000; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14.0pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #7F6000; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent4; mso-themecolor: accent4; mso-themeshade: 128;&quot;&gt;Second :&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; text-indent: -18pt;&quot;&gt;Overloading functions with argument lists of the same types(i.e. same signature), based on return type alone, is an error.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;void func (int a)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//&lt;/span&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;int func (int b)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//&lt;/span&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;These two functions yield error. Different return types with same function signatures are not considered overloaded.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Read more &amp;gt;&amp;gt; &lt;a href=&quot;https://www.computercodec.com/2020/07/function-overloading-in-c.html&quot; target=&quot;_blank&quot;&gt;Function Overloading inC++&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18pt;&quot;&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: Georgia; mso-fareast-font-family: Georgia;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;3.&lt;span style=&quot;font: 7pt &amp;quot;times new roman&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: Georgia; mso-fareast-font-family: Georgia;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;&lt;span style=&quot;font: 7pt &amp;quot;times new roman&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;color: #7f6000; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14.0pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #7F6000; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent4; mso-themecolor: accent4; mso-themeshade: 128;&quot;&gt;Third :&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; text-indent: -18pt;&quot;&gt;Member functions of a class cannot be overloaded solely on the basis of one being static and the other being non-static.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18pt;&quot;&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: Georgia; mso-fareast-font-family: Georgia;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;4.&lt;span style=&quot;font: 7pt &amp;quot;times new roman&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: Georgia; mso-fareast-font-family: Georgia;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;&lt;span style=&quot;font: 7pt &amp;quot;times new roman&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;color: #7f6000; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14.0pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #7F6000; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent4; mso-themecolor: accent4; mso-themeshade: 128;&quot;&gt;Fourth :&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; text-indent: -18pt;&quot;&gt;The &lt;/span&gt;&lt;b style=&quot;font-family: georgia, serif; font-size: 14pt; text-indent: -18pt;&quot;&gt;typedef&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; text-indent: -18pt;&quot;&gt; declarations do not define new types; they introduce synonyms for existing types. They do not affect the overloading mechanism.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;typedef char * CH&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;void Print (char * a);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//&lt;/span&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;void Print (CH b);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;// &lt;/span&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The two functions here, have the same signature as CH is nothing but a synonym for char *. Therefore, such declarations cause compile time error.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Read more&amp;gt;&amp;gt; typedef in C++ (&lt;i&gt;link will be restored shortly&lt;/i&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18pt;&quot;&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: Georgia; mso-fareast-font-family: Georgia;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;5.&lt;span style=&quot;font: 7pt &amp;quot;times new roman&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: Georgia; mso-fareast-font-family: Georgia;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;&lt;span style=&quot;font: 7pt &amp;quot;times new roman&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;color: #7f6000; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14.0pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #7F6000; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent4; mso-themecolor: accent4; mso-themeshade: 128;&quot;&gt;Fifth :&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; text-indent: -18pt;&quot;&gt;Enumerated types are distinct types and can be used to overload functions without any error.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Look at the following program&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;script src=&quot;https://gist.github.com/Computer-Code-C/01bbbc78c1fb546a06949d651607c5ea.js&quot;&gt;&lt;/script&gt;&lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;br /&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;b&gt;Output Screen:&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#b45f06&quot;&gt;Integer&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#b45f06&quot;&gt;Enum&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;font color=&quot;#b45f06&quot;&gt;&amp;nbsp;&lt;/font&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Read more&amp;gt;&amp;gt; &lt;a href=&quot;https://www.computercodec.com/2020/07/user-defined-datatypes-in-cc.html&quot; target=&quot;_blank&quot;&gt;Enumeration in C++&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18pt;&quot;&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: Georgia; mso-fareast-font-family: Georgia;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;6.&lt;span style=&quot;font: 7pt &amp;quot;times new roman&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18pt;&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;color: #7f6000; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14.0pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #7F6000; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent4; mso-themecolor: accent4; mso-themeshade: 128;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Sixth :&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; text-indent: -18pt;&quot;&gt;The types “array of” and “pointer to” are considered identical for the purpose of distinguishing between overloaded functions. This is due to the fact that all arrays are always passed to functions as a pointer.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;void func(int * a)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//&lt;/span&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;void func (int a[])&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//&lt;/span&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;These two functions are same. An array argument is always treated as a pointer.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;See the following program.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;script src=&quot;https://gist.github.com/Computer-Code-C/0d881482c19a41779ac53d875e4767a6.js&quot;&gt;&lt;/script&gt;&lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;br /&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;b&gt;Output Screen :&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;[&lt;font color=&quot;#ff0000&quot;&gt;error&lt;/font&gt;]&lt;font color=&quot;#b45f06&quot;&gt;Note: void func(int *) previously defined here.&lt;/font&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;However, for multi-dimensional arrays these restrictions do not count. These are not used much but just for information, look at the following code:&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;script src=&quot;https://gist.github.com/Computer-Code-C/b0c9d5e4819c9029d3868d54976be5b2.js&quot;&gt;&lt;/script&gt;&lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;br /&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;b&gt;Output Screen:&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#b45f06&quot;&gt;Array&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpLast&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#b45f06&quot;&gt;Pointer&lt;/font&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;If you find something wrong or if you wish to add some information in this article, feel free to comment on this post or contact us at &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Which topics you want an article on? Comment down on this post.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Do not stop here. Read all articles related to C++ &lt;a href=&quot;https://www.computercodec.com/&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;here&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to contribute any article for the website, feel free to share it on &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. We will publish it on the website with your name.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/7173012994685322049/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=7173012994685322049&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/7173012994685322049'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/7173012994685322049'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/restrictions-on-function-overloading.html' title='Restrictions on Function Overloading'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-7294153817981452010</id><published>2020-07-27T12:39:00.003+05:30</published><updated>2020-07-28T20:03:36.222+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Functions"/><title type='text'>Function Overloading in C++</title><content type='html'>&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;What is &lt;span style=&quot;color: #0070c0;&quot;&gt;Function Overloading &lt;/span&gt;?&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A function name having several definitions that are differentiable by the number or types of their arguments in known as overloading of function. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;We know that a function consists of a prototype and a body. The protype consists of the function’s return type, function’s name and its argument list (also known as function signature). Any two functions that happen to have the same name but differ in their function signature, are said to be overloaded. This difference in their signature may be due to changed types of arguments or by changed number of arguments in the argument list or both.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Function overloading implements &lt;i&gt;polymorphism&lt;/i&gt;, which is a key feature of Object Oriented Programming (OOP). The ability of a function to have same name but different behaviours depending upon the situation is considered as &lt;i&gt;polymorphism&lt;/i&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Also, using overloaded functions reduces number of comparisons in a program and thereby makes the program execute faster.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;Declaring&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt; &amp;amp; &lt;span style=&quot;color: #0070c0;&quot;&gt;Defining&lt;/span&gt; Overloaded &lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;Functions&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The key to function overloading is a function’s argument list which is also known as the &lt;i&gt;&lt;span style=&quot;color: #00b050;&quot;&gt;function signature&lt;/span&gt;&lt;/i&gt;. It is the signature, not the function return type that enables function overloading.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If two functions are having same number and types of arguments in the same order, they are said to have the same signature. Even if they are using distinct variable names, it doesn’t matter. For instance, following two functions have same signature.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;void squar (int a, float b);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;void squar (int x, float y);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;C++ lets you overload a function name provided the functions with same name are having different signatures. The signature can differ in the number of arguments or in the type of arguments, or both. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;To overload a function name, all you need to do is – declare and define all the functions with the same name but with different signatures, separately. For instance, following code fragment overloads a function name square().&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;void square (int i);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;void square (char c);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;void square (float f);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;void square (double d);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;After declaring, you must define them separately. This defining can also be done directly at the time of declaration.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;When a function name is declared more than once in a program, the compiler will interpret the second (and the rest) declarations as :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;if the signatures of subsequent functions match the previous function’s, then the second is treated as a re-declaration of the first. In that case the compiler raises error.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;void sum (int a, int b);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;void sum (int x, int y); &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;// &lt;span style=&quot;color: red;&quot;&gt;error&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;if the signatures of two functions match exactly but the return types differ, the second declaration is still treated as an erroneous re-declaration of the first and is flagged at compile time as an error.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;int square (float f);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;float square (float x);&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;// &lt;span style=&quot;color: red;&quot;&gt;error&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Functions with the same signature but different return types are not allowed in C++. You can have different return types, but only when the function signatures are different.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;if the signatures of two functions (having same name) differ, the two functions are considered to be overloaded.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;NOTE :&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; While considering the &lt;i&gt;&lt;span style=&quot;color: #00b050;&quot;&gt;function signature&lt;/span&gt;&lt;/i&gt;, &lt;b&gt;&lt;i&gt;int&lt;/i&gt;&lt;/b&gt; and &lt;b&gt;&lt;i&gt;unsigned&lt;/i&gt;&lt;i&gt;int&lt;/i&gt;&lt;/b&gt; or &lt;b&gt;&lt;i&gt;int&lt;/i&gt;&lt;/b&gt; and &lt;b&gt;&lt;i&gt;const&lt;/i&gt;&lt;/b&gt; &lt;b&gt;&lt;i&gt;int&lt;/i&gt;&lt;/b&gt;, etc are considered different datatypes and so functions with arguments with such differences are considered overloaded. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Read more &amp;gt;&amp;gt; &lt;a href=&quot;https://www.computercodec.com/2020/07/restrictions-on-function-overloading.html&quot; target=&quot;_blank&quot;&gt;Restrictions on Overloaded Functions&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;Calling &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;of Overloaded Functions&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Overloaded functions are called just like other functions. The number and type of arguments determine which function should be invoked. A function call first matches the prototypes available with the number and type of arguments provided with the function call and calls the appropriate function for execution.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Read more &amp;gt;&amp;gt; &lt;a href=&quot;https://www.computercodec.com/2020/07/function-overloading-in-c-part-ii.html&quot; target=&quot;_blank&quot;&gt;Steps involved in finding the Best Match.&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Let us see a demo program in C++&lt;/span&gt;&lt;/p&gt;&lt;script src=&quot;https://gist.github.com/Computer-Code-C/cf130cc595429eedd826177f9abacfaa.js&quot;&gt;&lt;/script&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;b&gt;Output screen :&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#783f04&quot;&gt;Function 2 called&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#783f04&quot;&gt;Function 1 called&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#783f04&quot;&gt;Function 3 called&lt;/font&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;If you find something wrong or if you wish to add some information in this article, feel free to comment on this post or contact us at &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Which topics you want an article on? Comment down on this post.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Do not stop here. Read all articles related to C++ &lt;a href=&quot;https://www.computercodec.com/&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;here&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to contribute any article for the website, feel free to share it on &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. We will publish it on the website with your name.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/7294153817981452010/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=7294153817981452010&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/7294153817981452010'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/7294153817981452010'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/function-overloading-in-c.html' title='Function Overloading in C++'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-1920519515866507152</id><published>2020-07-26T11:43:00.002+05:30</published><updated>2020-07-26T11:43:43.603+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CPP"/><title type='text'>WHY IS &quot;using namespace std&quot; USED IN C++?</title><content type='html'>&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;You must have noticed, all the programs in C++ start with the following two lines of code:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;#include&amp;lt;iostream&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;using namespace std;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Well, let us discuss about these lines of codes in detail.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;background-color: #cccccc;&quot;&gt;What is &lt;span style=&quot;color: #0070c0;&quot;&gt;# &lt;/span&gt;?&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The ‘#’ in C++ is called ‘Pre-processor directive’. The statements starting with ‘#’ are executed before the compilation of program starts, so that the compiler knows all the header files whose members we might have used in our program.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;background-color: #cccccc;&quot;&gt;What is &lt;span style=&quot;color: #0070c0;&quot;&gt;iostream&lt;/span&gt;?&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;All pre-defined functions in C++ are defined under certain files which are called the header files. These in-built functions include functions such as cout, cin, strlen, strcmp, abs, sqrt, pow, sort, etc. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The inbuilt functions cout, cin, endl, etc are defined inside &lt;b&gt;&lt;span style=&quot;color: #833c0b; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt;iostream&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #833c0b; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt; &lt;/span&gt;header file. So now we come to the answer :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #833c0b; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt;iostream&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #833c0b; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;is a header file in C++ that contains all the predefined functions controlling the input and output operations.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;background-color: #cccccc;&quot;&gt;What is &lt;span style=&quot;color: #0070c0;&quot;&gt;#include&amp;lt;iostream&amp;gt;&lt;/span&gt;?&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Whenever we write a program that needs to take input or print something as output, we need &lt;i&gt;cin&lt;/i&gt; and &lt;i&gt;cout&lt;/i&gt; statements. These are defined in &lt;b&gt;&lt;span style=&quot;color: #833c0b; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt;iostream&lt;/span&gt;&lt;/b&gt;. So, we need to copy the &lt;b&gt;&lt;span style=&quot;color: #833c0b; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt;iostream&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #833c0b; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt; &lt;/span&gt;header into our program. The statement &lt;span style=&quot;color: #0070c0;&quot;&gt;#include&amp;lt;iostream&amp;gt;&lt;/span&gt;does exactly this thing. It copies all the content of &lt;b&gt;&lt;span style=&quot;color: #833c0b; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt;iostream&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #833c0b; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt; &lt;/span&gt;header into our program so that we can use all the pre-defined functions and statements it contains.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;background-color: #cccccc;&quot;&gt;What is a &lt;span style=&quot;color: #0070c0;&quot;&gt;namespace&lt;/span&gt;?&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;In programming we cannot have variables, functions etc of same name. So, it becomes tiring when we need to name hundreds of new variables. This problem can be solved using a &lt;b&gt;&lt;span style=&quot;color: #00b050;&quot;&gt;namespace&lt;/span&gt;&lt;/b&gt;. Namespaces allow us to use same name variables by dividing them into different groups.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Let us understand using a daily life example.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Suppose your class in school has 4 sections, A, B, C &amp;amp; D. There are 50 students in each of these sections. Now there is a high probability that out of the total 200 students, few students have the same name. Now if two students with same name are present in one section, it becomes tough to mark them. But if they are in two different sections, this problem is solved as they can be properly identified using their section name. Here the sections are playing the role of namespaces.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;We cannot use two variables with the same name in a program. So, we put them in two different namespaces and then we reference them easily through their respective &lt;b&gt;&lt;span style=&quot;color: #00b050;&quot;&gt;namespace&lt;/span&gt;&lt;/b&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The following code will make this concept clearer.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;script src=&quot;https://gist.github.com/Computer-Code-C/37d256997176f86ff372d00a11ed451a.js&quot;&gt;&lt;/script&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;Output screen:&amp;nbsp; &amp;nbsp;&lt;b&gt;5&lt;/b&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&lt;/b&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;background-color: #cccccc;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;background-color: #cccccc;&quot;&gt;What is &lt;span style=&quot;color: #0070c0;&quot;&gt;std&lt;/span&gt;?&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;std&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;is just a &lt;b&gt;&lt;span style=&quot;color: #00b050;&quot;&gt;namespace&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #00b050;&quot;&gt; &lt;/span&gt;in the header file &lt;b&gt;&lt;span style=&quot;color: #833c0b; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt;iostream&lt;/span&gt;&lt;/b&gt;. This &lt;b&gt;&lt;span style=&quot;color: #00b050;&quot;&gt;namespace&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #00b050;&quot;&gt; &lt;/span&gt;contains all the members of &lt;b&gt;&lt;span style=&quot;color: #843c0c; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #843C0C; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt;iostream&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #843c0c; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #843C0C; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt; &lt;/span&gt;like &lt;i&gt;cin&lt;/i&gt;, &lt;i&gt;cout&lt;/i&gt;, &lt;i&gt;endl&lt;/i&gt; etc. In order to use these statements, we need to tell the compiler that we are &lt;b&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;using namespace std&lt;/span&gt;&lt;/b&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If we ignore this statement, we can still access &lt;i&gt;cin&lt;/i&gt;, &lt;i&gt;cout&lt;/i&gt;statements as &lt;span style=&quot;color: #0070c0;&quot;&gt;std::cin&lt;/span&gt;, &lt;span style=&quot;color: #0070c0;&quot;&gt;std::cout&lt;/span&gt;, etc. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If we do not tell the compiler which &lt;b&gt;&lt;span style=&quot;color: #00b050;&quot;&gt;namespace&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #00b050;&quot;&gt; &lt;/span&gt;we are using, it will generate error because it will have no idea about the &lt;i&gt;cin&lt;/i&gt;&lt;i&gt;cout&lt;/i&gt; statements.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Let us sum up all that we have learnt.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;To take input or to provide output, we need the input output streams and functions which are defined in the &lt;b&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;std&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #00b050;&quot;&gt;namespace&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #00b050;&quot;&gt; &lt;/span&gt;of the &lt;b&gt;&lt;span style=&quot;color: #833c0b; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt;iostream&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #833c0b; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt; &lt;/span&gt;header file. By the statement &lt;span style=&quot;color: #0070c0;&quot;&gt;#include&amp;lt;iostream&amp;gt;&lt;/span&gt;, we tell the compiler to copy all the information from &lt;b&gt;&lt;span style=&quot;color: #833c0b; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt;iostream&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #833c0b; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt; &lt;/span&gt;header file and paste it in our program. The &lt;span style=&quot;color: #0070c0;&quot;&gt;using namespace std &lt;/span&gt;statement tells the compiler that we wish to access all the functions and statements defined in the &lt;b&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;std&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #00b050;&quot;&gt;namespace&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #00b050;&quot;&gt; &lt;/span&gt;of the &lt;b&gt;&lt;span style=&quot;color: #833c0b; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt;iostream&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #833c0b; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt; &lt;/span&gt;header file in our program. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;After these two statements, the compiler knows exactly which statements we want to access and thus allows us to use &lt;i&gt;cin&lt;/i&gt;, &lt;i&gt;cout&lt;/i&gt;, &lt;i&gt;endl&lt;/i&gt; etc without showing any error. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;If you find something wrong or if you wish to add some information in this article, feel free to comment on this post or contact us at &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14.0pt; line-height: 107%;&quot;&gt;Which topics you want an article on? Comment down on this post.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14.0pt; line-height: 107%;&quot;&gt;Do not stop here. Read all articles related to C++ &lt;a href=&quot;https://www.computercodec.com/&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;here&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14.0pt; line-height: 107%;&quot;&gt;If you want to contribute any article for the website, feel free to share it on &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14.0pt; line-height: 107%;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14.0pt; line-height: 107%;&quot;&gt;. We will publish it on the website with your name.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/1920519515866507152/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=1920519515866507152&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/1920519515866507152'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/1920519515866507152'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/why-is-using-namespace-std-used-in-c.html' title='WHY IS &quot;using namespace std&quot; USED IN C++?'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-3627983600191989599</id><published>2020-07-25T19:17:00.003+05:30</published><updated>2020-07-25T19:18:51.358+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CPP"/><category scheme="http://www.blogger.com/atom/ns#" term="Functions"/><title type='text'>FORMS OF FUNCTION IN C++</title><content type='html'>&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Functions are no doubt one of the most important parts of any programming language. They help us to reuse a particular logic multiple number of times inside a program and are very easy to modify. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;To know basics of functions read the article on &lt;a href=&quot;https://www.computercodec.com/2020/07/functions-in-c.html&quot; target=&quot;_blank&quot;&gt;Functions in C++&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Here we will be discussing the various forms of functions that are used in C++. Their use depends upon the task we need to perform. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;We know functions contain a return type, function’s name and argument list. Out of these, the return type and argument list are optional which give rise to the different forms of functions.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #002060; font-family: georgia, serif; font-size: 18pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;background-color: #cccccc;&quot;&gt;Function forms in C++&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Form 1&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #843c0c; font-family: georgia, serif; font-size: 16pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #843C0C; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt;Function with no return type and no argument&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;When we do not need to feed any value into a function nor do we want the function to return some value, we use this form. When a function doesn’t return any value, we put its return type as &lt;i&gt;void&lt;/i&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;General syntax&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;void function_name ()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;// &lt;span style=&quot;color: #0070c0;&quot;&gt;body of function;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;// &lt;span style=&quot;color: #0070c0;&quot;&gt;no return statement&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Form 2&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #843c0c; font-family: georgia, serif; font-size: 16pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #843C0C; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt;Function with return value but no argument&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;When we do not need to pass values to a function but we wish to return some value, we use this form. The return type should match the type of value being returned. If they do not match, the returned value is converted into the return type value which might cause loss in information.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;General syntax&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return_type function_name ()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;// &lt;span style=&quot;color: #0070c0;&quot;&gt;body of the function&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;// &lt;span style=&quot;color: #0070c0;&quot;&gt;return statement&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;where &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;return_type&lt;/span&gt;&lt;/i&gt;can be any C++ datatype (primitive, derived or user-defined) except &lt;i&gt;void&lt;/i&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Form 3&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #843c0c; font-family: georgia, serif; font-size: 16pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #843C0C; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt;Function with no return type but with argument list&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;This form of a function can be used when we want to pass certain values into the function for evaluation but we do not want the function to return a value. As the function returns no value, we use void as the return type.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;General Syntax&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;void function_name (argument list)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;// &lt;span style=&quot;color: #0070c0;&quot;&gt;body of function&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;// &lt;span style=&quot;color: #0070c0;&quot;&gt;no return statement&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Form 4&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #843c0c; font-family: georgia, serif; font-size: 16pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #843C0C; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt;Function with return type and argument list&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;This form is used if we want to pass the values to the function, perform the required operations and then return back the result value. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;General Syntax&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return_type function_name (argument list)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//&lt;span style=&quot;color: #0070c0;&quot;&gt;body of the function&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//&lt;span style=&quot;color: #0070c0;&quot;&gt;return statement&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;For comparison, we will write the same program to find greater of the 2 integers entered by the user, separately using all four forms of a function named &lt;font color=&quot;#2b00fe&quot;&gt;max&lt;/font&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-PrmycTE8xEc/Xxw1wK6ildI/AAAAAAAAAMk/HhGPpMwtVd0ldOWKuEpPQHOfZ5o_QnwQgCLcBGAsYHQ/s1620/form%2B1.jpg&quot; style=&quot;font-size: 14pt; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Functions in C++&quot; border=&quot;0&quot; data-original-height=&quot;1620&quot; data-original-width=&quot;963&quot; height=&quot;625&quot; src=&quot;https://1.bp.blogspot.com/-PrmycTE8xEc/Xxw1wK6ildI/AAAAAAAAAMk/HhGPpMwtVd0ldOWKuEpPQHOfZ5o_QnwQgCLcBGAsYHQ/w373-h625/form%2B1.jpg&quot; title=&quot;Functions in C++&quot; width=&quot;373&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-2cqjiKfnjVI/Xxw1yVt6QGI/AAAAAAAAAMo/a0fHVUGc3Yw44x9Rl7Wp0PwxwlAv1-1eQCLcBGAsYHQ/s1650/form%2B2.jpg&quot; style=&quot;font-size: 14pt; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Functions in C++&quot; border=&quot;0&quot; data-original-height=&quot;1650&quot; data-original-width=&quot;993&quot; height=&quot;625&quot; src=&quot;https://1.bp.blogspot.com/-2cqjiKfnjVI/Xxw1yVt6QGI/AAAAAAAAAMo/a0fHVUGc3Yw44x9Rl7Wp0PwxwlAv1-1eQCLcBGAsYHQ/w376-h625/form%2B2.jpg&quot; title=&quot;Functions in C++&quot; width=&quot;376&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;p&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&amp;nbsp;&lt;img alt=&quot;Functions in C++&quot; border=&quot;0&quot; data-original-height=&quot;1677&quot; data-original-width=&quot;1053&quot; height=&quot;625&quot; src=&quot;https://1.bp.blogspot.com/-6eGJFAgmdkI/Xxw10yPBIDI/AAAAAAAAAMs/Nlp3qErDNIssDiZn1ws9kiugBuaG3kQ_gCLcBGAsYHQ/w393-h625/form%2B3.jpg&quot; title=&quot;Functions in C++&quot; width=&quot;393&quot; /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp; &amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;img alt=&quot;Functions in C++&quot; border=&quot;0&quot; data-original-height=&quot;1707&quot; data-original-width=&quot;1083&quot; height=&quot;625&quot; src=&quot;https://1.bp.blogspot.com/-HI4DWgmsQpg/Xxw13KtIpJI/AAAAAAAAAMw/JqOSpyoYnTg40m2i4sY8WDpkfCAPIXSQQCLcBGAsYHQ/w398-h625/form%2B4.jpg&quot; style=&quot;font-family: georgia, serif; font-size: 18.6667px;&quot; title=&quot;Functions in C++&quot; width=&quot;398&quot; /&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;If you find something wrong or if you wish to add some information in this article, feel free to comment on this post or contact us at &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Which topics you want an article on? Comment down on this post.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Do not stop here. Read all articles related to C++ &lt;a href=&quot;https://www.computercodec.com/&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;here&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to contribute any article for the website, feel free to share it on &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. We will publish it on the website with your name.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/3627983600191989599/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=3627983600191989599&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/3627983600191989599'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/3627983600191989599'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/forms-of-function-in-c.html' title='FORMS OF FUNCTION IN C++'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-6364658835275263523</id><published>2020-07-25T15:42:00.006+05:30</published><updated>2020-07-25T15:46:11.462+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CPP"/><category scheme="http://www.blogger.com/atom/ns#" term="Functions"/><title type='text'>FUNCTIONS IN C++</title><content type='html'>&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 18pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;What is a &lt;span style=&quot;color: #0070c0;&quot;&gt;Function&lt;/span&gt;?&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A function is a set of statements that perform a particular task. When a particular operation needs to be done time and again in a program, we can define a function to perform that operation. The function can then be used anywhere in the program any number of times. Functions are one of the most important parts of any program language. In this article we will learn about basics of functions.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;The &lt;span style=&quot;color: #0070c0;&quot;&gt;main() &lt;/span&gt;function &lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Technically, when we compile a program, there should be a starting point from where our program starts its execution. This starting point is the function &lt;b&gt;main()&lt;/b&gt;.&lt;b&gt; &lt;/b&gt;Every C++ program must have one and only one &lt;b&gt;main()&lt;/b&gt;function. The &lt;b&gt;main()&lt;/b&gt; function is an interesting aspect of C++ and we will read in details about it in some later articles. But almost always, it has an int return type and no arguments.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;Types of functions &lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;In C++, there are 2 types of functions.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #bf8f00; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent4; mso-themeshade: 191;&quot;&gt;In-built library functions&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #bf8f00; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent4; mso-themeshade: 191;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;There are many functions that are already defined under some specific header files and are already present in the installation file for C++. All these header files form the Standard Template Library (STL) of C++. To use these pre-defined functions, we need to include the specific header file in our program using the syntax :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;font color=&quot;#2b00fe&quot;&gt;#include&amp;lt;header_name&amp;gt;&lt;/font&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;To read in details about STL see other articles on our website. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #bf8f00; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent4; mso-themeshade: 191;&quot;&gt;User-defined functions&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #bf8f00; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent4; mso-themeshade: 191;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;These functions are declared and defined by a programmer according to his need and convenience. In this article and the articles that follow, we will be focusing on user-defined functions only.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;Function Definition&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A function definition consists of the function prototype and its body.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-ps5HYi8NQXs/XxwEC9HswMI/AAAAAAAAAME/8WKDaPwTbEM4yWOOf12BmuIRu_0xe4PjQCLcBGAsYHQ/s1203/Function%2Bproto.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Functions in C++&quot; border=&quot;0&quot; data-original-height=&quot;579&quot; data-original-width=&quot;1203&quot; height=&quot;241&quot; src=&quot;https://1.bp.blogspot.com/-ps5HYi8NQXs/XxwEC9HswMI/AAAAAAAAAME/8WKDaPwTbEM4yWOOf12BmuIRu_0xe4PjQCLcBGAsYHQ/w500-h241/Function%2Bproto.jpg&quot; title=&quot;Functions in C++&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Function Prototype&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; : The entire function declaration, i.e. the return type, function name and the parameter list constitute a function prototype.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Function signature&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; : It is a subset of function prototype. The parameter list is termed as a function’s signature. The use of this term arrives while discussing Function Overloading.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;return_type&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; : It is a valid C++ datatype. A function may or may not return any value. In case if a function doesn’t return any value, the return_type is set as &lt;i&gt;void&lt;/i&gt;. Otherwise, the return_type is any valid C++ datatype (primitive, derived or user-defined) depending upon the type of value being returned.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;function_name&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; : This the name of the function. The function is known in the program by this name. While naming a function, keep the following points in mind :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #806000; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent4; mso-themeshade: 128;&quot;&gt;First&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;, it can only consist of alphabets, digits and underscore(_).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #806000; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent4; mso-themeshade: 128;&quot;&gt;Second&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;, it cannot contain any special character (not even space).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #806000; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent4; mso-themeshade: 128;&quot;&gt;Third&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;, it cannot start with a digit.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #806000; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent4; mso-themeshade: 128;&quot;&gt;Fourth&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;, it must not match any keyword in C++.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #806000; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent4; mso-themeshade: 128;&quot;&gt;Fifth&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;, As C++ is a case dependent language, using different case letters means different names. Example, func &amp;amp; Func are two different names.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Argument List&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; : It is a collection of the type of values that the function will take whenever it is called. For example,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(int a, float b)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;This list will take 2 values whenever it is called, one of int type and other of float type. These values will be stored in a and b respectively.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Body&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; : It is the set of statements that perform the desired operation. They may call other functions as well.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Let us see a demo function definition :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;//&lt;span style=&quot;color: #0070c0;&quot;&gt;function to take 2 integers as argument&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;//&lt;span style=&quot;color: #0070c0;&quot;&gt;and return the maximum of the two.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;int max (int a, int b)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int result;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;if(a&amp;gt;b)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;result=a;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;else&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;result=b;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return result;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;}&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Here the function named &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;max&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;is created which takes two integer values as &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;&amp;amp; &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;b&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;and then returns an &lt;i&gt;int&lt;/i&gt; value. See the following statement :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;int great = max(5 , 10);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;cout &amp;lt;&amp;lt; great;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Output : 10&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Here, the function puts 5 in &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;and 10 in &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;b&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;and then executes all its body statements. As &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;b&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;is greater than &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;a&lt;/span&gt;&lt;/i&gt;, 10 is stored in&amp;nbsp;&lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 14.0pt; line-height: 107%; mso-ansi-language: EN-IN; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;&quot;&gt;result&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;and it is returned. This return value is caught by the &lt;/span&gt;&lt;i style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;int&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;variable &lt;/span&gt;&lt;i style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;great&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;. So now &lt;/span&gt;&lt;i style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;great&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;stores 10 (i.e. the larger value among &lt;/span&gt;&lt;i style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;&amp;amp; &lt;/span&gt;&lt;i style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;b&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;).&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;Function Declaration &lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A function declaration tells the compiler about a function name and how to call that function. Basically, a function declaration is the function prototype. The actual body of the function can be defined separately.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Also, in declaration without body, there is no need to name the arguments. Only the type name is sufficient. Example :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#2b00fe&quot;&gt;int max(int a, int b);&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#2b00fe&quot;&gt;int max(int, int);&lt;/font&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;both are correct.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;There are a few things you must keep in mind while declaring and defining a function :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #833c0b; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt;First&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;, the functions that are directly called into &lt;b&gt;main()&lt;/b&gt;must be at least declared&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;before &lt;b&gt;main().&lt;/b&gt;Their full definition may be made before or after &lt;b&gt;main()&lt;/b&gt;. This is important as the compiler must know that such a function that is being called in &lt;b&gt;main()&lt;/b&gt; actually exists.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #833c0b; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt;Second&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;, any other function, that is not being directly called into &lt;b&gt;main()&lt;/b&gt;, can be declared and defined anywhere in the program.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #833c0b; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt;Third&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;, a function must be declared and defined outside of all functions.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-0cF86dbo0Zs/XxwE4jncmFI/AAAAAAAAAMY/vNzeW-PdR4wZEpmXyF3G285_-2f31xUEgCLcBGAsYHQ/s1965/example.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Functions in C++&quot; border=&quot;0&quot; data-original-height=&quot;1965&quot; data-original-width=&quot;1902&quot; height=&quot;781&quot; src=&quot;https://1.bp.blogspot.com/-0cF86dbo0Zs/XxwE4jncmFI/AAAAAAAAAMY/vNzeW-PdR4wZEpmXyF3G285_-2f31xUEgCLcBGAsYHQ/w758-h781/example.jpg&quot; title=&quot;Functions in C++&quot; width=&quot;758&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;p&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;A demo program in C++&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;&lt;div&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-9gfgVvitD0A/XxwEkp7uf9I/AAAAAAAAAMM/LND9cGEUzqEcJDkyOTwbRbK1-3XehxUnwCLcBGAsYHQ/s1950/function%2Bflow.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Functions in C++&quot; border=&quot;0&quot; data-original-height=&quot;1950&quot; data-original-width=&quot;1068&quot; height=&quot;781&quot; src=&quot;https://1.bp.blogspot.com/-9gfgVvitD0A/XxwEkp7uf9I/AAAAAAAAAMM/LND9cGEUzqEcJDkyOTwbRbK1-3XehxUnwCLcBGAsYHQ/w429-h781/function%2Bflow.jpg&quot; title=&quot;Functions in C++&quot; width=&quot;429&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Output Screen :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;b&gt;Enter 2 integers : 25 &lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;34&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;b&gt;Larger integer is 34&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;If you find something wrong or if you wish to add some information in this article, feel free to comment on this post or contact us at &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Which topics you want an article on? Comment down on this post.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Do not stop here. Read all articles related to C++ &lt;a href=&quot;https://www.computercodec.com/&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;here&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to contribute any article for the website, feel free to share it on &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. We will publish it on the website with your name.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/6364658835275263523/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=6364658835275263523&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/6364658835275263523'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/6364658835275263523'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/functions-in-c.html' title='FUNCTIONS IN C++'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-6609088459485493855</id><published>2020-07-24T20:32:00.001+05:30</published><updated>2020-07-25T12:44:33.543+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CPP"/><category scheme="http://www.blogger.com/atom/ns#" term="Flow of Control"/><title type='text'>break AND continue IN C++</title><content type='html'>&lt;h2 style=&quot;line-height: normal; text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #002060; font-family: georgia, serif; font-size: 16pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What are &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 16pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;break &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;color: #002060; font-family: georgia, serif; font-size: 16pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;and &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 16pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;continue &lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #002060; font-family: georgia, serif; font-size: 16pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;statements in C++?&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The &lt;b&gt;break &lt;/b&gt;and &lt;b&gt;continue &lt;/b&gt;statements, along with &lt;i&gt;goto &lt;/i&gt;statement, are termed as the jump statements in C and C++. These are called so because they enable us to jump the control (i.e. move the control) from one point in the program to some other point. Where &lt;i&gt;goto &lt;/i&gt;statement can be used to move control anywhere within a function, &lt;b&gt;break &lt;/b&gt;and &lt;b&gt;continue &lt;/b&gt;are generally used to modify controls for a loop or switch case.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;line-height: normal; text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;THE &lt;span style=&quot;color: #0070c0;&quot;&gt;break &lt;/span&gt;STATEMENT&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;A &lt;b&gt;break&lt;/b&gt; statement is very often used in C or C++ program to directly come out of any loop (&lt;i&gt;for&lt;/i&gt;, &lt;i&gt;while&lt;/i&gt;or &lt;i&gt;do&lt;/i&gt;-&lt;i&gt;while&lt;/i&gt;) and &lt;i&gt;switch&lt;/i&gt; &lt;i&gt;case&lt;/i&gt;. Most of the times break is used with &lt;i&gt;if-else&lt;/i&gt; so that the control moves out of a loop under certain conditions. Reading below will make the concept clearer.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Syntax :&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;break;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;h4 style=&quot;line-height: normal; text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;How &lt;span style=&quot;color: #0070c0;&quot;&gt;break &lt;/span&gt;works?&lt;/span&gt;&lt;/b&gt;&lt;/h4&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The basic rule is that whenever a &lt;b&gt;break&lt;/b&gt;statement is encountered, be it inside a loop or &lt;i&gt;switch&lt;/i&gt; &lt;i&gt;case,&lt;/i&gt; the control immediately comes out of that block (loop or &lt;i&gt;switch&lt;/i&gt; &lt;i&gt;case&lt;/i&gt;). Often &lt;b&gt;break&lt;/b&gt; is used with if-else inside a loop or switch to come out of that loop or switch under the conditions specified in &lt;i&gt;if&lt;/i&gt;.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The &lt;b&gt;break&lt;/b&gt;statement takes control out of the innermost loop in which it is present. So, if there is a nested loop (loop within loop), &lt;b&gt;break&lt;/b&gt; will take control out of the loop in which it is present. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Look at the following representations to understand the concept better :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-U4ZfTc8AlaI/XxrxzR2O7sI/AAAAAAAAALw/Wwk3XuKDN_cxH_MO0f7GrgP9nS3qKzzSgCLcBGAsYHQ/s1506/break.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;break statement in C++&quot; border=&quot;0&quot; data-original-height=&quot;1376&quot; data-original-width=&quot;1506&quot; height=&quot;456&quot; src=&quot;https://1.bp.blogspot.com/-U4ZfTc8AlaI/XxrxzR2O7sI/AAAAAAAAALw/Wwk3XuKDN_cxH_MO0f7GrgP9nS3qKzzSgCLcBGAsYHQ/w500-h456/break.jpg&quot; title=&quot;break statement in C++&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-fyqUO3ABh64/XxryCpFhkQI/AAAAAAAAAL0/UHoq-EWVzvE64jW8l9dbwfGTOZ5Rc8vxgCLcBGAsYHQ/s1194/break%2B1.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;break statement in C++&quot; border=&quot;0&quot; data-original-height=&quot;1182&quot; data-original-width=&quot;1194&quot; height=&quot;495&quot; src=&quot;https://1.bp.blogspot.com/-fyqUO3ABh64/XxryCpFhkQI/AAAAAAAAAL0/UHoq-EWVzvE64jW8l9dbwfGTOZ5Rc8vxgCLcBGAsYHQ/w500-h495/break%2B1.jpg&quot; title=&quot;break statement in C++&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;p&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h4 style=&quot;line-height: normal; text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;A demo program in C++ to show working of &lt;span style=&quot;color: #0070c0;&quot;&gt;break &lt;/span&gt;statement :&lt;/span&gt;&lt;/b&gt;&lt;/h4&gt;&lt;div style=&quot;background-color: azure; border: 1px solid white; height: 850px; width: 350px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;// &lt;span style=&quot;color: #0070c0;&quot;&gt;Program to calculate sum of &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;// &lt;span style=&quot;color: #0070c0;&quot;&gt;maximum 5 integers.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;// &lt;span style=&quot;color: #0070c0;&quot;&gt;If negative integer is entered,&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;// &lt;span style=&quot;color: #0070c0;&quot;&gt;loop terminates.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;#include &amp;lt;iostream&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;using namespace std;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;int main()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int n, i, sum = 0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;for( i = 1; i &amp;lt;= 5; i++)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;cout&amp;lt;&amp;lt; “Enter a number : ”;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;cin&amp;gt;&amp;gt;n;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;if (n &amp;gt;= 0)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;sum = sum + n;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;else&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;break;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;cout&amp;lt;&amp;lt; “Sum is ”&amp;lt;&amp;lt; sum;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;cout&amp;lt;&amp;lt; “Value of i is ”&amp;lt;&amp;lt; i;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return 0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;Output Screen :&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;background-color: #eeeeee; border: 1px solid white; height: 200px; width: 200px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;Enter a number : 12&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;Enter a number : 42&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;Enter a number : -6&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;Sum is 54&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;Value of i is 3 &lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Explanation :&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;In the loop, every time the user is asked to enter a number. The number entered by the user is stored in &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;n&lt;/span&gt;&lt;/i&gt;. If the number is non-negative, it is added to the variable &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;sum&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;and this added value becomes new value of &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;sum&lt;/span&gt;&lt;/i&gt;. But as soon as the user enters a negative number, control encounters a &lt;b&gt;break&lt;/b&gt; statement and immediately comes out of the loop. This is evident from the fact that value of &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;i&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;after the termination of loop is 3 and not 5.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;line-height: normal; text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;THE &lt;span style=&quot;color: #0070c0;&quot;&gt;continue &lt;/span&gt;STATEMENT&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The &lt;b&gt;continue&lt;/b&gt; statement in C or C++ is used in loops to ignore a set of statements. Whenever a &lt;b&gt;continue&lt;/b&gt;statement is encountered, the control moves directly to the condition part in &lt;i&gt;while&lt;/i&gt;or &lt;i&gt;do-while&lt;/i&gt; and to the update part in &lt;i&gt;for&lt;/i&gt; loop. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Syntax :&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;continue;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;h4 style=&quot;line-height: normal; text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;How &lt;span style=&quot;color: #0070c0;&quot;&gt;continue &lt;/span&gt;works?&lt;/span&gt;&lt;/b&gt;&lt;/h4&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The rule is simple. If &lt;b&gt;continue&lt;/b&gt;is encountered anywhere in a &lt;i&gt;for&lt;/i&gt; loop, control passes directly to the update part. If &lt;b&gt;continue&lt;/b&gt; is encountered in a &lt;i&gt;while&lt;/i&gt; or &lt;i&gt;do-while&lt;/i&gt;loop, control passes directly to the condition part. The general working can be understood better from the following diagram.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-V4_xVL6-rCM/XxrxKldeEZI/AAAAAAAAALo/ek9jsodhZD4bVO6-WyuENontOJKzJK0OQCLcBGAsYHQ/s1664/continue.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;continue statement in C++&quot; border=&quot;0&quot; data-original-height=&quot;1268&quot; data-original-width=&quot;1664&quot; height=&quot;476&quot; src=&quot;https://1.bp.blogspot.com/-V4_xVL6-rCM/XxrxKldeEZI/AAAAAAAAALo/ek9jsodhZD4bVO6-WyuENontOJKzJK0OQCLcBGAsYHQ/w625-h476/continue.jpg&quot; title=&quot;continue statement in C++&quot; width=&quot;625&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;p&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Note that if the update part of &lt;i&gt;while&lt;/i&gt;or &lt;i&gt;do-while&lt;/i&gt; loop appear after the &lt;b&gt;continue&lt;/b&gt; statement, it is never actually executed. This results in the condition always being true and loop is repeated infinite times. In short, the program crashes. So, to remove this problem, &lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;it is always advised to use &lt;b&gt;continue&lt;/b&gt;with &lt;i&gt;for&lt;/i&gt; loop, or update the loop variable in &lt;i&gt;while&lt;/i&gt; or &lt;i&gt;do-while&lt;/i&gt;before the &lt;b&gt;continue&lt;/b&gt; statement. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;h4 style=&quot;line-height: normal; text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;A demo program in C++ to show working of &lt;span style=&quot;color: #0070c0;&quot;&gt;continue &lt;/span&gt;statement :&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/h4&gt;&lt;div style=&quot;background-color: azure; border: 1px solid white; height: 750px; width: 350px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;// &lt;span style=&quot;color: #0070c0;&quot;&gt;Program to calculate sum of &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;// &lt;span style=&quot;color: #0070c0;&quot;&gt;maximum 5 integers.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;// &lt;span style=&quot;color: #0070c0;&quot;&gt;If negative integer is entered,&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;// &lt;span style=&quot;color: #0070c0;&quot;&gt;it is ignored.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;#include &amp;lt;iostream&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;using namespace std;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;int main()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int n, sum = 0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;for(int i = 1; i &amp;lt;= 5; i++)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;cout&amp;lt;&amp;lt; “Enter a number : ”;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;cin&amp;gt;&amp;gt;n;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;if (n &amp;lt; 0)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;continue;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;sum = sum + n;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;cout&amp;lt;&amp;lt; “Sum is ”&amp;lt;&amp;lt; sum;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return 0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;Output screen :&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;background-color: #eeeeee; border: 1px solid white; height: 245px; width: 200px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;Enter a number : 12&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;Enter a number : 42&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;Enter a number : -6&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;Enter a number : 50&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;Enter a number : -32&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;Sum is 104&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Explanation :&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;In the loop, every time the user is asked to enter a number. The number entered by the user is stored in &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;n&lt;/span&gt;&lt;/i&gt;. If the number entered is non-negative, the &lt;i&gt;if&lt;/i&gt; statement is not executed and control executes the statement &lt;span style=&quot;background-attachment: initial; background-clip: initial; background-color: #eeeeee; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #0070c0;&quot;&gt;sum= sum+n&lt;/span&gt;. This statement adds the value of &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;n&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;to &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;sum&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;and the resulting value is stored in &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;sum&lt;/span&gt;&lt;/i&gt;. But if the number entered by the user is negative (i.e. less than zero), &lt;b&gt;continue&lt;/b&gt;statement is executed. This passes the control directly to the update part&lt;span style=&quot;background-color: #eeeeee;&quot;&gt; &lt;span style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #0070c0;&quot;&gt;i++&lt;/span&gt;&lt;/span&gt;. Thus, negative numbers are not added into &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;sum&lt;/span&gt;&lt;/i&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;If you find something wrong or if you wish to add some information in this article, feel free to comment on this post or contact us at&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;mso-bookmark: _Hlk46513104;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;mso-bookmark: _Hlk46513104;&quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;mso-bookmark: _Hlk46513104;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;mso-bookmark: _Hlk46513104;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Which topics you want an article on? Comment down on this post.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;mso-bookmark: _Hlk46513104;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Do not stop here. Read all articles related to C++ &lt;a href=&quot;https://www.computercodec.com/&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;here&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;mso-bookmark: _Hlk46513104;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to contribute any article for the website, feel free to share it on &lt;/span&gt;&lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;mso-bookmark: _Hlk46513104;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;mso-bookmark: _Hlk46513104;&quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;mso-bookmark: _Hlk46513104;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. We will publish it on the website with your name.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;mso-bookmark: _Hlk46513104;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Download the pdf form of this article &lt;a href=&quot;https://drive.google.com/file/d/16zCVztPMko-D6VCi-AmZDQDfRnmBVFDs/view?usp=sharing&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;here&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style=&quot;mso-bookmark: _Hlk46513104;&quot;&gt;&lt;/span&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/6609088459485493855/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=6609088459485493855&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/6609088459485493855'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/6609088459485493855'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/break-and-continue-in-c.html' title='break AND continue IN C++'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-8581887123514643483</id><published>2020-07-24T10:53:00.001+05:30</published><updated>2020-07-25T12:44:39.422+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CPP"/><category scheme="http://www.blogger.com/atom/ns#" term="Flow of Control"/><title type='text'>do while LOOP IN C/C++</title><content type='html'>&lt;h2 style=&quot;line-height: normal; text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #002060; font-family: georgia, serif; font-size: 20pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;background-color: #cccccc;&quot;&gt;What is do while loop in C/C++?&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The &lt;b&gt;do&lt;/b&gt; &lt;b&gt;while loop&lt;/b&gt; in C/C++ is a flow of control construct which allows the programmer to repeat a set of statements any desired number of times. Such programming constructs are really useful as instead of writing the same statement n number of times we can simply write it once and repeat it n times. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Suppose you have to print all numbers from 1 to n, where n is to be entered by the user. This n can be in thousands and even lacs. It would be impossible for a person to write thousand &lt;i&gt;cout&lt;/i&gt;statements. In such cases he can simply write one &lt;i&gt;cout&lt;/i&gt; statement and ask the compiler to repeat it n number of times. The &lt;b&gt;do while loop&lt;/b&gt; is one of the tools of telling the compiler to repeat the statement. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The major difference between &lt;b&gt;do while loop&lt;/b&gt; and the other loops is that &lt;b&gt;do while&lt;/b&gt; is an &lt;i&gt;exit controlled&lt;/i&gt; loop. This means that the condition is checked after the body of loop is executed. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Let us learn in details about while loop in C/C++ :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;line-height: normal; text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;background-color: #eeeeee; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;General Syntax :&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;initialization;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;do&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;// body of the loop&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;update;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;} while (condition) ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;Note : A semicolon is put after while (condition) part&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Let us read about the working of &lt;b&gt;do while&lt;/b&gt;loop.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;h3 style=&quot;line-height: normal; text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;How does do while loop work?&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;As we have seen in the syntax, there are four segments associated with any loop. They are initialization, the body of the loop, update statement and condition. Let us learn about them :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Initialization&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;: It is the first step in do while loop. This step initializes the loop variable with an initial value. A loop variable is the variable on which the condition is checked before executing the body of the loop.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Body of the loop&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;: It is the set of statements that needs to be repeated.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Update&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;: After the body of the loop is executed, the control moves to the update statement. An update statement changes the value of the loop variable. It is not mandatory to update the loop variable at last. This can be done anywhere inside the loop.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Condition&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;: In do while loop, the condition is checked at last. After update statement, if the condition is true, the control moves to the body again , otherwise it comes out of the loop.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;As you can see that the condition is placed after the body of the loop, therefore whatever be the condition, the body is definitely executed at least once. This is strange as other looping constructs such as &lt;b&gt;for&lt;/b&gt; and &lt;b&gt;while&lt;/b&gt; check the condition prior to execution of the body.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The following flowchart helps you understand clearly the flow of control in a do while loop :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-tTTTtcKGh8A/XxpszMjiiQI/AAAAAAAAALU/zKK2G7ECPiMvsQF6MkYOpZDZf5qev2EDACLcBGAsYHQ/s1503/DO%2BWHILE%2BGEN.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;do while loop in C/C++&quot; border=&quot;0&quot; data-original-height=&quot;1503&quot; data-original-width=&quot;1074&quot; height=&quot;500&quot; src=&quot;https://1.bp.blogspot.com/-tTTTtcKGh8A/XxpszMjiiQI/AAAAAAAAALU/zKK2G7ECPiMvsQF6MkYOpZDZf5qev2EDACLcBGAsYHQ/w358-h500/DO%2BWHILE%2BGEN.jpg&quot; title=&quot;do while loop in C/C++&quot; width=&quot;358&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Let us visualize the flowchart with a demo code.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;//&lt;span style=&quot;color: #0070c0;&quot;&gt;The loop part to print all &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;//&lt;span style=&quot;color: #0070c0;&quot;&gt;numbers from 1 to 99&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;int i = 1;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;// &lt;span style=&quot;color: #0070c0;&quot;&gt;initialization&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;do&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;cout&amp;lt;&amp;lt; i &amp;lt;&amp;lt; “ ”; // &lt;span style=&quot;color: #0070c0;&quot;&gt;body of loop&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;i++;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;// &lt;span style=&quot;color: #0070c0;&quot;&gt;update&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;} while (i &amp;lt; 100) ;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;// &lt;span style=&quot;color: #0070c0;&quot;&gt;condition&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The equivalent flowchart :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-t2d1MMQc4jI/XxptdP4SVWI/AAAAAAAAALc/P4--taa50B0jqoUqsybHhthvRHtxdcgtQCLcBGAsYHQ/s1503/do%2Bwhile.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;do while loop in C/C++&quot; border=&quot;0&quot; data-original-height=&quot;1503&quot; data-original-width=&quot;1074&quot; height=&quot;500&quot; src=&quot;https://1.bp.blogspot.com/-t2d1MMQc4jI/XxptdP4SVWI/AAAAAAAAALc/P4--taa50B0jqoUqsybHhthvRHtxdcgtQCLcBGAsYHQ/w358-h500/do%2Bwhile.jpg&quot; title=&quot;do while loop in C/C++&quot; width=&quot;358&quot; /&gt;&lt;/a&gt;&lt;/b&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;h3 style=&quot;line-height: normal; text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;A demo program with detailed dry run&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;&lt;div style=&quot;background-color: azure; border: 1px solid white; height: 650px; width: 320px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;//&lt;span style=&quot;color: #0070c0;&quot;&gt;sum of odd numbers from 1 to n&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;#include&amp;lt;iostream&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;using namespace std;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;int main()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int n;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;cin&amp;gt;&amp;gt;n;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int sum=0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int i = 1;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;// &lt;span style=&quot;color: #0070c0;&quot;&gt;initialization&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;do&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;sum=sum+i;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;// &lt;span style=&quot;color: #0070c0;&quot;&gt;body&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;i = i + 2;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;// &lt;span style=&quot;color: #0070c0;&quot;&gt;update&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;} &lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;while(i &amp;lt;= n) ; // &lt;span style=&quot;color: #0070c0;&quot;&gt;condition&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;cout&amp;lt;&amp;lt; “&lt;span style=&quot;color: #00b050;&quot;&gt;Sum is &lt;/span&gt;”&amp;lt;&amp;lt;sum;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return 0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;Input : 10&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Output : Sum is 25&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Let us see how control flows in this program :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;1&lt;/b&gt;. The program declares an integer variable &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;n&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;&lt;/span&gt;and then takes input from &lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;the user. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;2&lt;/b&gt;. Another variable named &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;sum&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;is created and initialized with 0 (zero). This variable stores the sum of numbers. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;3&lt;/b&gt;. As the program is to find sum of odd numbers from 1 to n, we initialize the loop variable (&lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;i&lt;/span&gt;&lt;/i&gt;) with 1.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;4&lt;/b&gt;. The control enters the body of the loop without any condition check. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;5&lt;/b&gt;. Inside the loop, the value of &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;i&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;is added to &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;sum&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;and the result is stored again into &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;sum&lt;/span&gt;&lt;/i&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;6&lt;/b&gt;. Then the control moves to update statement where value of&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;i&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;is increased by 2 so that it becomes the next odd number. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;7&lt;/b&gt;. Control now checks the condition and if found true, all steps from step 5 are again repeated.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;8&lt;/b&gt;. If condition is false, the control moves out of the loop and prints the sum.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;h3 style=&quot;line-height: normal; text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;An important note :&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The looping part of same program can also be written as :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;do&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;if(i % 2 != 0)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;sum = sum + i;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;i++;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;} while(i&amp;lt;n);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is the difference between the two logics? &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Obviously, both the logics produce the same result. But the difference exists in the number of times the loop is repeated. In the first logic the loop is repeated &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;n/2&lt;/span&gt;&lt;/i&gt;times while in second logic, the loop is executed &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;n&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;number of times. So, although both give the same output, the time taken to execute the second logic will be almost twice the time taken to execute the first. For small values of n, this doesn’t make any difference as the time taken is just a fraction of a second. But when value of n becomes very large, the slow execution of second logic becomes noticeable. It is always advised that you should write a code that takes minimum time to give the desired output.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;Related topics :&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/for-loop-in-cc.html&quot; target=&quot;_blank&quot;&gt;for loop in C/C++&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/while-loop-in-cc.html&quot; target=&quot;_blank&quot;&gt;while loop in C/C++&lt;/a&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to add any information or if you find something incorrect in this article, comment down or contact us through the mail :&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. &lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: 13.5pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Which topics you want an article on? Comment down on this post.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Do not stop here. Read all articles related to C++&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://draft.blogger.com/blog/post/edit/1963654198922371192/3003319301167816688&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;here&lt;/span&gt;&lt;/i&gt;&lt;/a&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to contribute any article for the website, feel free to share it on&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://draft.blogger.com/blog/post/edit/1963654198922371192/3003319301167816688&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#2b00fe&quot;&gt;coding.nkcoder@gmail.com&lt;/font&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. We will publish it on the website with your name.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Download the pdf form of this article&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://drive.google.com/file/d/1rA9-iKY0PZDc7BKSMpLW6DGres4eBudK/view?usp=sharing&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;here&lt;/span&gt;&lt;/i&gt;&lt;/a&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/8581887123514643483/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=8581887123514643483&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/8581887123514643483'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/8581887123514643483'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/do-while-loop-in-cc.html' title='do while LOOP IN C/C++'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-9019140470930821459</id><published>2020-07-23T18:21:00.003+05:30</published><updated>2020-07-24T11:03:49.574+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CPP"/><category scheme="http://www.blogger.com/atom/ns#" term="Flow of Control"/><title type='text'>while LOOP IN C/C++</title><content type='html'>&lt;h2 style=&quot;line-height: normal; text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;background-color: #cccccc; color: #002060; font-family: georgia, serif; font-size: 20pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is while loop in C/C++?&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;&lt;div&gt;&lt;b&gt;&lt;span&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The &lt;b&gt;while loop&lt;/b&gt; in C/C++ is a flow of control construct which allows the programmer to repeat a set of statements any desired number of times. Such programming constructs are really useful as instead of writing the same statement n number of times we can simply write it once and repeat it n times.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Suppose you have to print all numbers from 1 to n, where n is to be entered by the user. This n can be in thousands and even lacs. It would be impossible for a person to write thousand &lt;i&gt;cout&lt;/i&gt;statements. In such cases he can simply write one &lt;i&gt;cout&lt;/i&gt; statement and ask the compiler to repeat it n number of times. The &lt;b&gt;while loop&lt;/b&gt; is one of the tools of telling the compiler to repeat the statement. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Let us learn in details about while loop in C/C++ :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;line-height: normal; text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;General Syntax :&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;initialization;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;while (condition)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;// &lt;font color=&quot;#0b5394&quot;&gt;body of the loop&lt;/font&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;update;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Let us read about the working of while loop.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;line-height: normal; text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;How does while loop work?&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;As we have seen in the syntax, there are four segments associated with any loop. They are initialization, condition, update statement and the body of the loop. Let us learn about them :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Initialization&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;: It is the first step in while loop. This step initializes the loop variable with an initial value. A loop variable is the variable on which the condition is checked before executing the body of the loop.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Condition&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;: After initialization, the condition is checked. Condition gives Boolean results, i.e. either true or false. If the condition is true, the control passes into the body of the loop and executes all the statements. If false, the control leaves the loop and comes out of it.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Body of the loop&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;: It is the set of statements that is executed if the condition evaluates to true. It is basically the statement we wish to repeat.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Update&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;: After the body of the loop is executed, the control moves to the update statement. An update statement changes the value of the loop variable. It is not mandatory to update the loop variable at last. This can be done anywhere inside the loop.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;After update, the control again moves to condition and checks if it is still true. If yes, then the body is again executed. Otherwise, the control moves out of the loop.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The following flowchart helps you understand clearly the flow of control in a while loop :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-V9VyDFlbNR0/XxmE3cs6SPI/AAAAAAAAALA/0Z-38IpRjrYJrzMr-Dluq6TSqqKUwsbUACLcBGAsYHQ/s1623/FOR%2BLOOP%2BGEN.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;while loop in C/C++&quot; border=&quot;0&quot; data-original-height=&quot;1623&quot; data-original-width=&quot;834&quot; height=&quot;500&quot; src=&quot;https://1.bp.blogspot.com/-V9VyDFlbNR0/XxmE3cs6SPI/AAAAAAAAALA/0Z-38IpRjrYJrzMr-Dluq6TSqqKUwsbUACLcBGAsYHQ/w256-h500/FOR%2BLOOP%2BGEN.jpg&quot; title=&quot;while loop in C/C++&quot; width=&quot;256&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Let us visualize the flowchart with a demo code.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;//&lt;span style=&quot;color: #0070c0;&quot;&gt;The loop part to print all &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;//&lt;span style=&quot;color: #0070c0;&quot;&gt;numbers from 1 to 99&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;int i = 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;while (i &amp;lt; 100)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;cout&amp;lt;&amp;lt; i &amp;lt;&amp;lt; “ ”;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;i++;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The equivalent flowchart :&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-UBQUJb4Zfic/XxmFHnPVrBI/AAAAAAAAALI/uAYy0RKwslMmXSq6EsCS0eEs0UtL--hEQCLcBGAsYHQ/s1623/For%2Bloop.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;while loop in C/C++&quot; border=&quot;0&quot; data-original-height=&quot;1623&quot; data-original-width=&quot;789&quot; height=&quot;500&quot; src=&quot;https://1.bp.blogspot.com/-UBQUJb4Zfic/XxmFHnPVrBI/AAAAAAAAALI/uAYy0RKwslMmXSq6EsCS0eEs0UtL--hEQCLcBGAsYHQ/w244-h500/For%2Bloop.jpg&quot; title=&quot;while loop in C/C++&quot; width=&quot;244&quot; /&gt;&lt;/a&gt;&lt;/b&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;line-height: normal; text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;A demo program with detailed dry run&amp;nbsp; &lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;&lt;div style=&quot;background-color: azure; border: 1px solid white; height: 650px; width: 310px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;//&lt;span style=&quot;color: #0070c0;&quot;&gt;sum of odd numbers from 1 to n&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;#include&amp;lt;iostream&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;using namespace std;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;int main()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int n;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;cin&amp;gt;&amp;gt;n;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int sum=0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int i = 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;while(i &amp;lt;= n)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;sum=sum+i;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;i = i + 2;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;cout&amp;lt;&amp;lt; “&lt;span style=&quot;color: #00b050;&quot;&gt;Sum is &lt;/span&gt;”&amp;lt;&amp;lt;sum;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return 0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;Input : 10&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Output : Sum is 25&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Let us see how control flows in this program :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;1. The program declares an integer variable &lt;i&gt;&lt;font color=&quot;#0b5394&quot;&gt;n &lt;/font&gt;&lt;/i&gt;and then takes input from &lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;the user. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;2. Another variable named &lt;i&gt;&lt;font color=&quot;#0b5394&quot;&gt;sum &lt;/font&gt;&lt;/i&gt;is created and initialized with 0 (zero). This variable stores the sum of numbers. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;3. As the program is to find sum of odd numbers from 1 to n, we initialize the loop variable (&lt;i&gt;&lt;font color=&quot;#0b5394&quot;&gt;i&lt;/font&gt;&lt;/i&gt;) with 1.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;4. The condition is next checked, and if found true the control enters the body of the loop. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;5. Inside the loop, the value of &lt;i&gt;&lt;font color=&quot;#0b5394&quot;&gt;i &lt;/font&gt;&lt;/i&gt;is added to sum and the result is stored again into &lt;i&gt;&lt;font color=&quot;#0b5394&quot;&gt;sum&lt;/font&gt;&lt;/i&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;6. Then the control moves to update statement where value of&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;i&gt;&lt;font color=&quot;#0b5394&quot;&gt;i &lt;/font&gt;&lt;/i&gt;is increased by 2 so that it becomes the next odd number. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;7. Control again checks the condition and if found true, all steps from step 5 are again repeated.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;8. If condition is false, the control moves out of the loop and prints the sum.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to add any information or find something incorrect in this article, comment down or contact us through the mail :&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;coding.nkcoder@gmail.com&lt;/a&gt;. &lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: 13.5pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;-webkit-text-stroke-width: 0px; font-variant-caps: normal; font-variant-ligatures: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; orphans: 2; text-decoration-color: initial; text-decoration-style: initial; widows: 2; word-spacing: 0px;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Which topics you want an article on? Comment down on this post.&lt;o:p&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot; style=&quot;-webkit-text-stroke-width: 0px; font-variant-caps: normal; font-variant-ligatures: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; orphans: 2; text-decoration-color: initial; text-decoration-style: initial; widows: 2; word-spacing: 0px;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Do not stop here. Read all articles related to C++&amp;nbsp;&lt;a href=&quot;https://www.computercodec.com/&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;here&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot; style=&quot;-webkit-text-stroke-width: 0px; font-variant-caps: normal; font-variant-ligatures: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; orphans: 2; text-decoration-color: initial; text-decoration-style: initial; widows: 2; word-spacing: 0px;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to contribute any article for the website, feel free to share it on&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: 13.5pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. We will publish it on the website with your name.&lt;o:p&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;-webkit-text-stroke-width: 0px; font-variant-caps: normal; font-variant-ligatures: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; orphans: 2; text-decoration-color: initial; text-decoration-style: initial; widows: 2; word-spacing: 0px;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Download pdf of this article &lt;a href=&quot;https://drive.google.com/file/d/160RrR2noZM3iaHX77w-pNz25x6e-aGTa/view?usp=sharing&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;here&lt;/i&gt;&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot; style=&quot;-webkit-text-stroke-width: 0px; font-variant-caps: normal; font-variant-ligatures: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; orphans: 2; text-decoration-color: initial; text-decoration-style: initial; widows: 2; word-spacing: 0px;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;/span&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/9019140470930821459/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=9019140470930821459&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/9019140470930821459'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/9019140470930821459'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/while-loop-in-cc.html' title='while LOOP IN C/C++'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-3331929051087807110</id><published>2020-07-23T12:59:00.001+05:30</published><updated>2020-07-23T17:50:49.444+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CPP"/><category scheme="http://www.blogger.com/atom/ns#" term="Flow of Control"/><title type='text'>FLOW OF CONTROL IN C/C++</title><content type='html'>&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Programs not only store data but also manipulate data in terms of consolidation, rearranging, modifying data. To perform all these tasks, programs need tools for performing repetitive actions or for making decisions. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 18pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;&lt;span style=&quot;background-color: #cccccc;&quot;&gt;FLOW OF CONTROL&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;As we know, a C/C++ program starts its execution from the first statement of main() function and continues till the end. But what if we need to send control back a few statements or if we want to repeat a sequence of statements a given number of times? Most of the problems in real life has two outcomes, either a yes (i.e. true) or a no (i.e. false). How to let our program take a decision?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Well all these problems are solved using special tools which are called the &lt;i&gt;flow of control manipulators&lt;/i&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;But before we learn about them, we must learn what is a statement and what is a block of statements.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Statements &lt;/span&gt;&lt;/b&gt;&lt;/h4&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Statements are the instructions given to the computer to perform any kind of action, be it data movements, be it making decisions or be it repeating actions. Statements are the smallest executable unit of a C/C++ program. Statements are terminated with a semicolon (;). The simplest statement is the empty or NULL statement. It is simply a semicolon (;). A NULL statement is useful in those instances where the syntax of the language requires the presence of a statement but the logic of the program does not (As in loops and their bodies).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;A compound statement in C++ is a sequence of statements enclosed by a pair of curly brackets ({}). For instance,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;statement 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;statement 2;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;statement 3; &lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;// &amp;amp; so on&lt;i&gt; &lt;/i&gt;&lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;} &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;A compound statement is called a &lt;i&gt;block&lt;/i&gt;. A &lt;i&gt;block&lt;/i&gt; is regarded as a single statement and can be used anywhere in a program where a single statement can be used.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Now we will see in brief, all the tools in C++ to control the normal flow of execution.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The if statement of C/C++ &lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;An &lt;b&gt;if&lt;/b&gt; statement is used to test a particular condition; if that condition is true then only the control will move to the statement following &lt;b&gt;if&lt;/b&gt;, otherwise that statement is ignored (Here the statement following &lt;b&gt;if&lt;/b&gt; may be a single or a compound statement).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Obviously, any condition can yield two possible results, either true or false. If the condition in &lt;b&gt;if&lt;/b&gt; part is false then the statement in the &lt;b&gt;else&lt;/b&gt; clause gets executed. The following figure shows a flow chart on how &lt;b&gt;if&lt;/b&gt;-&lt;b&gt;else&lt;/b&gt; statements work.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-XCz7m9-CP3U/XxVzNfMzmNI/AAAAAAAAAJw/CSxVtypCBUMqdkV7Ne9PHuUOcvm7BA5nQCLcBGAsYHQ/s1844/Untitled%2BDiagram%2B%25284%2529.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;FLOW OF CONTROL&quot; border=&quot;0&quot; data-original-height=&quot;1844&quot; data-original-width=&quot;1444&quot; height=&quot;513&quot; src=&quot;https://1.bp.blogspot.com/-XCz7m9-CP3U/XxVzNfMzmNI/AAAAAAAAAJw/CSxVtypCBUMqdkV7Ne9PHuUOcvm7BA5nQCLcBGAsYHQ/w403-h513/Untitled%2BDiagram%2B%25284%2529.png&quot; title=&quot;FLOW OF CONTROL&quot; width=&quot;403&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;p&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;It is important to know that C/C++ doesn’t make it compulsory to use an &lt;b&gt;else&lt;/b&gt; part with &lt;b&gt;if&lt;/b&gt;. The rule is simple. If the condition is true, the immediately following statement of &lt;b&gt;if&lt;/b&gt; gets executed, otherwise the control simply moves to the next statement. This next statement may be an &lt;b&gt;else&lt;/b&gt; or it may be a normal statement.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Also, &lt;b&gt;if&lt;/b&gt; can be used without &lt;b&gt;else&lt;/b&gt; but the converse is not true. Therefore, there cannot be an &lt;b&gt;else&lt;/b&gt; statement without an &lt;b&gt;if&lt;/b&gt;. The following codes will make the concepts clear :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;if(condition)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;statement 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;else&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;statement 2;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Here, if the condition is true, statement 1 is executed; otherwise statement 2 is executed.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;if(condition)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;statement 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;statement 2;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Here, if the condition is true, statement 1 is executed and then the control moves to statement 2; otherwise statement 1 is ignored and control directly passes to statement 2.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;if(condition)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;statement 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;statement 2;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;else&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;statement 3;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;This gives an error. The control on executing 2 has already come out of if clause. When it encounters else, it cannot figure out the if part of this else clause and so declares an error.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Note : &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;In if-else statements, either only the if statement is executed or only the else statement but never both.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;In all the above examples, statement 1,2 &amp;amp; 3 could be a single statement or a compound statement or even a NULL statement.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The switch statement of C++&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;C++ provides a multiple-branch selection statement known as switch. This selection statement successively tests the value of an expression against a list of integer or character constants. When match is found, the statements associated with that constant are executed.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The syntax for switch case is :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 360px; overflow: auto hidden; width: 450px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;width: 150%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;switch (exp)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 150%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 150%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;case constant 1 : statement sequence 1; break;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 150%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;case constant 2 : statement sequence 2; break;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 150%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;case constant 3 : statement sequence 3; break;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 150%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;……….&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 150%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;case constant n-1 : statement sequence n-1; break;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 150%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;default : statement sequence n; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 150%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;} &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;where &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;exp&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;is any expression or a variable (only &lt;i&gt;int&lt;/i&gt; or &lt;i&gt;char&lt;/i&gt;). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The expression is evaluated and the result is compared sequentially from top to bottom, starting at case &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;constant&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;i&gt;1&lt;/i&gt;&lt;/span&gt;. The moment the match is found, all the statement sequences of that case are executed.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Now the importance of &lt;b&gt;break&lt;/b&gt;comes into play. Suppose the &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;exp&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;value matches &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;constant 2&lt;/span&gt;&lt;/i&gt; and there is no &lt;b&gt;break&lt;/b&gt; statement in that case. Then the control keeps on executing all the statement sequences of the following cases until it encounters a &lt;b&gt;break&lt;/b&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;default case&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;is executed in case none of the constants match &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;exp&lt;/span&gt;&lt;/i&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Let us see a few examples :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;int n; cin&amp;gt;&amp;gt;n;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;switch(n)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;case 1 : cout&amp;lt;&amp;lt; “ONE ”; break;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;case 2 : cout&amp;lt;&amp;lt; “TWO”; break;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;case 3 : cout&amp;lt;&amp;lt; “THREE”; break;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;case 4 : cout&amp;lt;&amp;lt; “FOUR”; break;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;default : cout&amp;lt;&amp;lt; “GREATER THAN FOUR”;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;} &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Input : &lt;span style=&quot;color: #bf9000; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #BF9000; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent4; mso-themecolor: accent4; mso-themeshade: 191;&quot;&gt;2&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Output : &lt;span style=&quot;color: #00b050;&quot;&gt;TWO&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Input : &lt;span style=&quot;color: #bf9000; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #BF9000; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent4; mso-themecolor: accent4; mso-themeshade: 191;&quot;&gt;3&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Output : &lt;span style=&quot;color: #00b050;&quot;&gt;THREE&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Input : &lt;span style=&quot;color: #bf9000; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #BF9000; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent4; mso-themecolor: accent4; mso-themeshade: 191;&quot;&gt;6&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Output : &lt;span style=&quot;color: #00b050;&quot;&gt;GREATER THAN FOUR&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Now let us see what happens if we omit &lt;b&gt;break&lt;/b&gt; statement.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;int n; cin&amp;gt;&amp;gt;n;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;switch(n)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;case 1 : cout&amp;lt;&amp;lt; “ONE ”; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;case 2 : cout&amp;lt;&amp;lt; “TWO ”; break;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;case 3 : cout&amp;lt;&amp;lt; “THREE ”;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;case 4 : cout&amp;lt;&amp;lt; “FOUR ”; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;default : cout&amp;lt;&amp;lt; “GREATER THAN FOUR”;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;} &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Input : &lt;span style=&quot;color: #bf9000; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #BF9000; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent4; mso-themecolor: accent4; mso-themeshade: 191;&quot;&gt;1&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Output : &lt;span style=&quot;color: #00b050;&quot;&gt;ONE TWO&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Input : &lt;span style=&quot;color: #bf9000; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #BF9000; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent4; mso-themecolor: accent4; mso-themeshade: 191;&quot;&gt;2&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Output :&lt;span style=&quot;color: #00b050;&quot;&gt; TWO&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Input : &lt;font color=&quot;#bf9000&quot;&gt;3&lt;/font&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Output :&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;color: #00b050;&quot;&gt;THREE FOUR GREATER THAN FOUR&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Other flow of control statements in C/C++ are the loops. C/C++ provides 3 looping structures to execute the same set of statements any desired number of times. These are :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;for loop&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;while loop&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;do while loop&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Click on them to learn in details about them. &lt;i&gt;&lt;font color=&quot;#ffa400&quot;&gt;(Sorry the link will be restored shortly.)&lt;/font&gt;&lt;/i&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Did you find the article helpful? Do you want to add something to it? Feel free to comment on this post below.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Do not stop here. To read all about C/C++ click &lt;a href=&quot;https://www.computercodec.com/&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;&lt;font color=&quot;#ff0000&quot;&gt;here&lt;/font&gt;&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;To download pdf format of this article, click &lt;a href=&quot;https://drive.google.com/file/d/1YCdf2a7_AFhmtuc_UBaxKkPjToDUIUJg/view?usp=sharing&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;&lt;font color=&quot;#ff0000&quot;&gt;here&lt;/font&gt;&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;If you want to contribute any article or any piece of information you can send it on &lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;coding.nkcoder@gmail.com&lt;/a&gt;. We will publish it in your name.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/3331929051087807110/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=3331929051087807110&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/3331929051087807110'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/3331929051087807110'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/flow-of-control-in-cc_23.html' title='FLOW OF CONTROL IN C/C++'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-3003319301167816688</id><published>2020-07-23T12:45:00.003+05:30</published><updated>2020-07-23T18:07:22.938+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CPP"/><category scheme="http://www.blogger.com/atom/ns#" term="Flow of Control"/><title type='text'>for loop IN C/C++</title><content type='html'>&lt;h2 style=&quot;line-height: normal; text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #002060; font-family: georgia, serif; font-size: 20pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;background-color: #cccccc;&quot;&gt;What is for loop in C/C++?&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;&lt;div&gt;&lt;b&gt;&lt;span style=&quot;color: #002060; font-family: georgia, serif; font-size: 20pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The &lt;b&gt;for loop&lt;/b&gt; in C/C++ is a flow of control construct which allows the programmer to repeat a set of statements any desired number of times. Such programming constructs are really useful as instead of writing the same statement n number of times we can simply write it once and repeat it n times.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Suppose you have to print all numbers from 1 to n, where n is to be entered by the user. This n can be in thousands and even lacs. It would be impossible for a person to write thousand &lt;i&gt;cout&lt;/i&gt;&amp;nbsp;statements. In such cases he can simply write one &lt;i&gt;cout&lt;/i&gt;&amp;nbsp;statement and ask the compiler to repeat it n number of times. The &lt;b&gt;for&lt;/b&gt; &lt;b&gt;loop&lt;/b&gt; is one of the tools of telling the compiler to repeat the statement. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Let us learn in details about for loop in C/C++ :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;General Syntax :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;for(initialization ; condition; update)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;// &lt;span style=&quot;color: #0070c0;&quot;&gt;set of statements to be repeated&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The above code is the general syntax and it can be replaced by anyone of the following syntax :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Type 1&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;initialization;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;for ( ; condition ; update)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;//&lt;span style=&quot;color: #0070c0;&quot;&gt;statements to be repeated&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Type&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt; &lt;b&gt;2&lt;/b&gt;.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;for (initialization ; condition ;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;//&lt;span style=&quot;color: #0070c0;&quot;&gt;statements to be repeated&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;update; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Type 3.&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;for (initialization; ;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;if(condition)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;//&lt;span style=&quot;color: #0070c0;&quot;&gt;statements to be repeated&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;update;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;else&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;break;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;There can be more syntax depending on how you want to use it. The thing to keep in mind is the general working of the loop. If your syntax works in accordance to the general rule of a loop, it will work just fine. Let us read about the working of for loop.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;How does&lt;font color=&quot;#2b00fe&quot;&gt; for loop&lt;/font&gt; work?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;As we have seen in the syntax, there are four segments associated with any loop. They are initialization, condition, update statement and the body of the loop. Let us learn about them :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Initialization&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;: It is the first step in for loop. This step initializes the loop variable with an initial value. A loop variable is the variable on which the condition is checked before executing the body of the loop.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Condition&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;: After initialization, the condition is checked. Condition gives Boolean results, i.e. either true or false. If the condition is true, the control passes into the body of the loop and executes all the statements. If false, the control leaves the loop and comes out of it.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Body of the loop&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;: It is the set of statements that is executed if the condition evaluates to true. It is basically the statement we wish to repeat.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Update&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;: After the body of the loop is executed, the control moves to the update statement. An update statement changes the value of the loop variable. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;After update, the control again moves to condition and checks if it is still true. If yes, then the body is again executed. Otherwise, the control moves out of the loop.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The following flowchart helps you understand clearly the flow of control in a for loop :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-xyjxtTLETqA/XxkqqZzg_-I/AAAAAAAAAK0/iUnFcm_OMHAcWv4xvz-bf52Yag-Ne7F-wCLcBGAsYHQ/s1623/FOR%2BLOOP%2BGEN.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;for loop in C/C++&quot; border=&quot;0&quot; data-original-height=&quot;1623&quot; data-original-width=&quot;834&quot; height=&quot;500&quot; src=&quot;https://1.bp.blogspot.com/-xyjxtTLETqA/XxkqqZzg_-I/AAAAAAAAAK0/iUnFcm_OMHAcWv4xvz-bf52Yag-Ne7F-wCLcBGAsYHQ/w256-h500/FOR%2BLOOP%2BGEN.jpg&quot; title=&quot;for loop in C/C++&quot; width=&quot;256&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Let us visualize the flowchart with a demo code.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;//&lt;span style=&quot;color: #0070c0;&quot;&gt;The loop part to print all &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;//&lt;span style=&quot;color: #0070c0;&quot;&gt;numbers from 1 to 99&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;for(int i = 1; i &amp;lt; 100; i++)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;cout&amp;lt;&amp;lt; i;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The equivalent flowchart :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-zG3PILRSXlg/XxkqV2eHaoI/AAAAAAAAAKs/8ObgMJ11XfQS7jrBUYsN7z3pP3V6JSMJgCLcBGAsYHQ/s1623/For%2Bloop.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;for loop in C/C++&quot; border=&quot;0&quot; data-original-height=&quot;1623&quot; data-original-width=&quot;789&quot; height=&quot;512&quot; src=&quot;https://1.bp.blogspot.com/-zG3PILRSXlg/XxkqV2eHaoI/AAAAAAAAAKs/8ObgMJ11XfQS7jrBUYsN7z3pP3V6JSMJgCLcBGAsYHQ/w250-h512/For%2Bloop.jpg&quot; title=&quot;for loop in C/C++&quot; width=&quot;250&quot; /&gt;&lt;/a&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;p&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is&lt;font color=&quot;#2b00fe&quot;&gt; nested for&lt;/font&gt; loop?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The body of the &lt;b&gt;for&lt;/b&gt; &lt;b&gt;loop&lt;/b&gt;can contain any number of statements. These statements may also contain other for statements. When one or more for statements are used in the body of another for statement, it is called nested for loop. Many programs need nested for loops in order to fulfil our task. Some most famous programs that use nested for loop are programs including 2 Dimensional arrays, array sorting or printing some patterns, etc.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The basic working logic of nested loops is not tough. It is very easy to understand and it will be a very helpful exercise if you try to understand the logic yourself. You can look at many programs on this site which use nested loops.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;A demo program with detailed dry run&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;div style=&quot;background-color: azure; border: 1px solid white; height: 600px; width: 310px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;//&lt;span style=&quot;color: #0070c0;&quot;&gt;sum of odd numbers from 1 to n&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;#include&amp;lt;iostream&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;using namespace std;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;int main()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int n;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;cin&amp;gt;&amp;gt;n;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int sum=0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;for(int i=1; i&amp;lt;=n; i+=2)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;sum=sum+i;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;cout&amp;lt;&amp;lt; “&lt;span style=&quot;color: #00b050;&quot;&gt;Sum is &lt;/span&gt;”&amp;lt;&amp;lt;sum;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return 0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Input : 10&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Output : Sum is 25&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Let us see how control flows in this program :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;1. The program declares an integer variable n and then takes input from &lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;the user. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;2. Another variable named sum is created and initialized with 0 (zero). This variable stores the sum of numbers. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;3. As the program is to find sum of odd numbers from 1 to n, we initialize the loop variable (i) with 1.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;4. The condition is next checked, and if found true the control enters the body of the loop. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;5. Inside the loop, the value of i is added to sum and the result is stored again into sum. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;6. Then the control moves to update statement where value of &lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;i is increased by 2 so that value of i becomes the next odd number. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;7. Control again checks the condition and if found true, all steps from step 5 are again repeated.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;8. If condition is false, the control moves out of the loop and prints the sum.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to add any information or find something incorrect in this article, comment down or contact us through the mail : &lt;font color=&quot;#2b00fe&quot;&gt;coding.nkcoder@gmail.com&lt;/font&gt;.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Which topics you want an article on? Comment down on this post.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Do not stop here. Read all articles related to C++ &lt;a href=&quot;https://www.computercodec.com/&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;here&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to contribute any article for the website, feel free to share it on &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. We will publish it on the website with your name.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;     &lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Download the pdf form of this article &lt;a href=&quot;https://drive.google.com/file/d/18tMruBOAX8vUGsjXLI-4A1zsGbQLJhac/view?usp=sharing&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;here&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/3003319301167816688/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=3003319301167816688&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/3003319301167816688'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/3003319301167816688'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/for-loop-in-cc.html' title='for loop IN C/C++'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-6013148085094440652</id><published>2020-07-22T11:38:00.006+05:30</published><updated>2020-07-22T11:44:08.201+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CPP"/><category scheme="http://www.blogger.com/atom/ns#" term="Flow of Control"/><title type='text'>goto STATEMENT IN C/C++</title><content type='html'>&lt;h2 style=&quot;line-height: normal; text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #cccccc; color: #002060; font-family: georgia, serif; font-size: 20pt;&quot;&gt;What is &lt;b&gt;goto statement in C/C++&lt;/b&gt;?&lt;/span&gt;&lt;/h2&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The &lt;b&gt;goto&lt;/b&gt; &lt;b&gt;statement&lt;/b&gt; is a jump statement in C/C++ which is also called unconditional jump statement. It is used to transfer control from any point in a function to some other point (called label). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Let us look into the working of &lt;b&gt;goto&lt;/b&gt;statement. Here we define a &lt;i&gt;label&lt;/i&gt; (which is a user-defined identifier). We then write a statement or a block of statements under that &lt;i&gt;label&lt;/i&gt;. So now whenever we refer to that &lt;i&gt;label&lt;/i&gt;, we are actually referring to those statements. Whenever the compiler reads the statement &lt;b&gt;goto label&lt;/b&gt;, it passes the control to that &lt;i&gt;label&lt;/i&gt; and starts executing from there. Note here that a &lt;i&gt;label&lt;/i&gt; name can be any valid identifier.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Here are 2 basic syntax for &lt;b&gt;goto&lt;/b&gt;&lt;b&gt;statement&lt;/b&gt; :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Type 1&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;:&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;label : statement;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;…//&lt;font color=&quot;#2b00fe&quot;&gt;may be some code&lt;/font&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;goto label;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Type 2&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;:&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;goto label;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;…//&lt;font color=&quot;#2b00fe&quot;&gt;may be some code&lt;/font&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;label : statement;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is the scope of goto statement?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;A goto statement is valid only if it passes control to a label in the same function. Referencing a label outside the function in which it is defined gives compilation error. But within a function a goto statement and a label can be placed anywhere (i.e. maybe type 1 or type 2 ).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;See the following code :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;background-color: azure; border: 1px solid white; height: 360px; width: 250px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;void Sum()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&amp;nbsp;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&amp;nbsp; &amp;nbsp; label : cout&amp;lt;&amp;lt; “&lt;font color=&quot;#ffa400&quot;&gt;Sum&lt;/font&gt;”;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&amp;nbsp;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;int main()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&amp;nbsp;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&amp;nbsp; &amp;nbsp; goto label;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&amp;nbsp; &amp;nbsp; return 0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&amp;nbsp;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;This code gives the following error message:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;[error] label ‘label’ used but not defined&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Let us see a demo code and understand its working using a flowchart.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;//demo run for goto statement&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;label1 : statement1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;goto label3;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;label2 : statement2;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;label3 : statement3;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-9dDhSIZEZQo/XxfWWSBVivI/AAAAAAAAAKg/RXUQvVawERY4AYcf75LlDJ_heK0ZZ6H9wCLcBGAsYHQ/s1149/Untitled%2BDiagram%2B%25282%2529.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;goto Statement in C/C++&quot; border=&quot;0&quot; data-original-height=&quot;1149&quot; data-original-width=&quot;1143&quot; height=&quot;400&quot; src=&quot;https://1.bp.blogspot.com/-9dDhSIZEZQo/XxfWWSBVivI/AAAAAAAAAKg/RXUQvVawERY4AYcf75LlDJ_heK0ZZ6H9wCLcBGAsYHQ/w398-h400/Untitled%2BDiagram%2B%25282%2529.jpg&quot; title=&quot;goto Statement in C/C++&quot; width=&quot;398&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&amp;nbsp;&lt;p&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;A demo program in C++ :&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;background-color: azure; border: 1px solid white; height: 560px; width: 350px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;//&lt;span style=&quot;color: #0070c0;&quot;&gt;find and print all odd numbers&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;//&lt;span style=&quot;color: #0070c0;&quot;&gt;from 1 to 10 using goto&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;#include&amp;lt;iostream&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;using namespace std;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;int main()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int n= 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;label :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;if(n%2 != 0)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;cout&amp;lt;&amp;lt;n&amp;lt;&amp;lt; “ ”;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;n++;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;if(n&amp;lt;=10)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;goto label;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return 0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;Output : 1 3 5 7 9&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;line-height: normal; text-align: left;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;Executing both if &amp;amp; else statement simultaneously&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;We know, in using if-else construct, either the if or the else statement is executed but never both. This is required for correct decision making process. However, the statement that if and else statements cannot be executed simultaneously is not true. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;As we have learnt earlier in this article, goto statement can be used to transfer control from any point to the other in a function. So, can we use it to jump from if part to else part? The answer is yes! Let us see an example :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;background-color: azure; border: 1px solid white; height: 330px; width: 250px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;//&lt;span style=&quot;color: #0070c0;&quot;&gt;code to jump from if to else&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;if(condition)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;statement1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;goto label2;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;else&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;label2 : statement2;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Now if the condition is true, the control will enter &lt;b&gt;if &lt;/b&gt;and execute statement1. Then it will jump to label2 and execute statement2.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;However always be careful when using goto because you may easily end up having an infinite loop.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;line-height: normal; text-align: left;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;Why goto statement is not used by programmers?&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;You must have noticed that although the concept of &lt;b&gt;goto &lt;/b&gt;sounds so important, it is not generally used in programs. There are a few reasons for it :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;First&lt;/b&gt;, using goto in a program makes the logic very complex. You need to take extra care about the control positions and be sure the control doesn’t get trapped in an infinite loop.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;Second&lt;/b&gt;, reading a program developed by some other programmer who has used goto can be really tough. It becomes very hard to debug and correct the program.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;Third&lt;/b&gt;, better and safer options of jump control are available in C/C++ as &lt;b&gt;break &lt;/b&gt;and &lt;b&gt;continue &lt;/b&gt;statements. These statements give the desired result without causing much trouble.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;If you want to add something or correct some information in this post, comment down on this post or contact &lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;coding.nkcoder@gmail.com&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Which topics you want an article on? Comment down on this post.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Do not stop here. Read all articles related to C++ &lt;a href=&quot;https://www.computercodec.com/&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;&lt;font color=&quot;#ff0000&quot;&gt;here&lt;/font&gt;&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to contribute any article for the website, feel free to share it on &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. We will publish it on the website with your name.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Download the pdf form of this article &lt;a href=&quot;https://drive.google.com/file/d/1PkuVGDb-KfbDBKYt5ls7i0S2oougbxox/view?usp=sharing&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;&lt;font color=&quot;#ff0000&quot;&gt;here&lt;/font&gt;&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/6013148085094440652/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=6013148085094440652&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/6013148085094440652'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/6013148085094440652'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/goto-statement-in-cc.html' title='goto STATEMENT IN C/C++'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-6242825315752049510</id><published>2020-07-21T17:10:00.003+05:30</published><updated>2020-07-23T17:48:53.284+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CPP"/><category scheme="http://www.blogger.com/atom/ns#" term="Flow of Control"/><title type='text'>switch case IN C/C++</title><content type='html'>&lt;p class=&quot;MsoNormal&quot; style=&quot;mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The &lt;b&gt;switch case&amp;nbsp;&lt;/b&gt;is a programming construct in C/C++ which allows us to match the result of an expression to certain cases and then display the matching statement. Let us read in details about &lt;b&gt;switch case&lt;/b&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #002060; font-family: georgia, serif; font-size: 18pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;background-color: #cccccc;&quot;&gt;The switch() Statement in C/C++ :&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;C++ provides a multiple-branch selection statement known as switch. This selection statement successively tests the value of an expression against a list of integer or character constants. When a match is found, the statements associated with that constant are executed.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The general syntax of switch statement :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;background-color: azure; border: 1px solid white; height: 380px; overflow: auto hidden; width: 420px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; width: 180%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;switch (exp)&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 13.5pt; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; width: 180%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;{&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 13.5pt; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; width: 180%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;case constant 1 : statement sequence 1; break;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 13.5pt; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; width: 180%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;case constant 2 : statement sequence 2; break;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 13.5pt; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; width: 180%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;case constant 3 : statement sequence 3; break;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 13.5pt; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; width: 180%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;……….&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 13.5pt; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; width: 180%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;case constant n-1 : statement sequence n-1; break;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 13.5pt; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; width: 180%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;default : statement sequence n;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 13.5pt; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; width: 180%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;}&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 13.5pt; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;The &lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;exp&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;is evaluated and its value is matched against the values of the &lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;constants&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;specified in the case statements. When a match is found, the &lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;statement&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt; &lt;i&gt;sequence&lt;/i&gt; &lt;/span&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;associated with that case starts executing. The control goes on executing all the following sequences till it encounters &lt;b&gt;break&lt;/b&gt; or it reaches the end of switch.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;If a case statement does not include a &lt;b&gt;break&lt;/b&gt; statement, then the control continues right on the next case statements until a &lt;b&gt;break&lt;/b&gt; is encountered or the end of switch is reached. This situation (missing &lt;b&gt;break&lt;/b&gt; in case statements) is called &lt;b&gt;&lt;i&gt;fall&lt;/i&gt;&lt;/b&gt; &lt;b&gt;&lt;i&gt;through&lt;/i&gt;&lt;/b&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;The &lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;default&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;case is executed when no match is found. The &lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;default&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;statement is optional, and if it is not present, the control simply comes out of the switch block if none of the cases match.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;Whenever a &lt;b&gt;break&lt;/b&gt;statement is encountered in a switch statement, program execution jumps out of the switch block to the line immediately after switch.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;The following flowchart represents basic working of a switch statement.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-qd-JQij1IXk/XxbNj-DT8_I/AAAAAAAAAKU/OOFh43zcvYgjvytDh6YapuHyHRrOgRt-gCLcBGAsYHQ/s2013/Untitled%2BDiagram%2B%25282%2529.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;switch case in C/C++&quot; border=&quot;0&quot; data-original-height=&quot;2013&quot; data-original-width=&quot;1257&quot; height=&quot;500&quot; src=&quot;https://1.bp.blogspot.com/-qd-JQij1IXk/XxbNj-DT8_I/AAAAAAAAAKU/OOFh43zcvYgjvytDh6YapuHyHRrOgRt-gCLcBGAsYHQ/w313-h500/Untitled%2BDiagram%2B%25282%2529.jpg&quot; title=&quot;switch case in C/C++&quot; width=&quot;313&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&amp;nbsp;&lt;p&gt;&lt;/p&gt; &lt;h3 style=&quot;line-height: normal; text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 16pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;Points to keep in mind while using switch case :&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;First&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;, the expression provided in the switch should result in character or integer type constant. Otherwise, the switch statement becomes invalid and compiler shows error.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;Example :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;Valid expressions – &lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;switch(1+3*6)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;switch(1*2/9%3)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;variables can also be used but they should be storing some integer or character value &lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;– &lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;switch(a+b*c)&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;Second&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;, two cases cannot have the same constant, i.e. duplicate cases are not allowed.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;Third&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;, the default statement is optional and is executed when none of the cases match the value of the expression.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;Fourth&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;, break is an important keyword in switch case. It is optional but should be carefully used in order to avoid fall through.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;Fifth&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;, Nesting of switch case is allowed, i.e. there may be one or more switch cases inside the parent switch block. But it is generally avoided as it makes the program complex and reduces readability.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;Sixth&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;, all case constants must be either character type or integer type. Also, C++ allows constant variables (declared using const) as case constants but C doesn’t. So, for switch statement in C, all case constants must be literals and not associated with any variable. For instance, the code &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;const int a=1;const int b=2;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;switch(1)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;case a : cout&amp;lt;&amp;lt; 1 ;break;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;case b : cout&amp;lt;&amp;lt; 2 ;break;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;default : cout&amp;lt;&amp;lt; “more than 2”;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;works fine with C++ compiler but shows error in C.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;Here is a sample program to find greater of two numbers using switch case :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;background-color: azure; border: 1px solid white; height: 450px; width: 300px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: #2f5597; font-family: georgia, serif;&quot;&gt;include&lt;/span&gt;&lt;span style=&quot;color: black; font-family: georgia, serif;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif;&quot;&gt;iostream&lt;/span&gt;&lt;span style=&quot;color: black; font-family: georgia, serif;&quot;&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif;&quot;&gt;using namespace &lt;b&gt;std&lt;/b&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: #7030a0; font-family: georgia, serif;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black; font-family: georgia, serif;&quot;&gt;main()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: #7030a0; font-family: georgia, serif;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black; font-family: georgia, serif;&quot;&gt;a,b; &lt;/span&gt;&lt;span style=&quot;color: #c55a11; font-family: georgia, serif;&quot;&gt;cin&lt;/span&gt;&lt;span style=&quot;color: black; font-family: georgia, serif;&quot;&gt;&amp;gt;&amp;gt;a&amp;gt;&amp;gt;b;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: #7030a0; font-family: georgia, serif;&quot;&gt;switch &lt;/span&gt;&lt;span style=&quot;color: black; font-family: georgia, serif;&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color: #7030a0; font-family: georgia, serif;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: black; font-family: georgia, serif;&quot;&gt;)(a&amp;gt;b))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;case &lt;/span&gt;&lt;span style=&quot;color: #843c0c; font-family: georgia, serif;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black; font-family: georgia, serif;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #c55a11; font-family: georgia, serif;&quot;&gt;cout&lt;/span&gt;&lt;span style=&quot;color: black; font-family: georgia, serif;&quot;&gt;&amp;lt;&amp;lt;b&amp;lt;&amp;lt; &lt;/span&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif;&quot;&gt;“ is greater ”&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif;&quot;&gt;;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;case &lt;/span&gt;&lt;span style=&quot;color: #843c0c; font-family: georgia, serif;&quot;&gt;1 &lt;/span&gt;&lt;span style=&quot;color: black; font-family: georgia, serif;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #c55a11; font-family: georgia, serif;&quot;&gt;cout&lt;/span&gt;&lt;span style=&quot;color: black; font-family: georgia, serif;&quot;&gt;&amp;lt;&amp;lt;a&amp;lt;&amp;lt; &lt;/span&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif;&quot;&gt;“is greater ”&lt;/span&gt;&lt;span style=&quot;color: black; font-family: georgia, serif;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: #7030a0; font-family: georgia, serif;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: #843c0c; font-family: georgia, serif;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black; font-family: georgia, serif;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif;&quot;&gt;}&lt;span style=&quot;font-size: 14pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;Input : 60 68&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;Output : 68 is greater&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;An interesting exercise for you is to write the following programs using if-else and then using switch.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;1. Check if a character is vowel or not. Take input from user.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;2. Print the day of the week depending on the number input by user. Assume the&amp;nbsp; &amp;nbsp; &amp;nbsp; number to be between 1 to 7 with 1 being Monday and 7 being Sunday.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;Try making a simple calculator using switch case.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;I am not including solutions so that you may practice it yourself. If you want to share your code or ask any doubt you can comment on this post or you can mail me at &lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;coding.nkcoder@gmail.com&lt;/a&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Which topics you want an article on? Comment down on this post.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Do not stop here. Read all articles related to C++ &lt;a href=&quot;https://www.computercodec.com/&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;&lt;i&gt;here&lt;/i&gt;&lt;/font&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to contribute any article for the website, feel free to share it on &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. We will publish it on the website with your name.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Download the pdf form of this article &lt;a href=&quot;https://drive.google.com/file/d/1C0wT7JxmMJom5PJ8PHeYy-mMGxu15laf/view?usp=sharing&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;&lt;i&gt;here&lt;/i&gt;&lt;/font&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/6242825315752049510/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=6242825315752049510&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/6242825315752049510'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/6242825315752049510'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/switch-case-in-cc.html' title='switch case IN C/C++'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-2936325830744806847</id><published>2020-07-20T22:20:00.013+05:30</published><updated>2020-07-23T17:50:23.547+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CPP"/><category scheme="http://www.blogger.com/atom/ns#" term="Flow of Control"/><title type='text'>if-else STATEMENT IN C/C++</title><content type='html'>&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;An &lt;b&gt;if-else&lt;/b&gt;statement in C/C++ is needed whenever the programmer needs to make a decision. This decision is fed into the &lt;b&gt;if-else&lt;/b&gt; statement and the flow of control is regulated depending on the result of the decision. All decisions in programming language result in only two possibilities, either the condition is &lt;i&gt;true&lt;/i&gt;or it is &lt;i&gt;false&lt;/i&gt;. &lt;b&gt;If-else&lt;/b&gt; statement deals with this scenario.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #002060; font-family: georgia, serif; font-size: 18pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #002060; font-family: georgia, serif; font-size: 18pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;The if-else statement in C/C++ &lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #002060; font-family: georgia, serif; font-size: 18pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;An &lt;b&gt;if&lt;/b&gt; statement tests a particular condition; if the condition is &lt;i&gt;true&lt;/i&gt;, a course-of-action is followed, i.e. a particular statement or set of statements is executed. Otherwise (if the condition evaluates to &lt;i&gt;false&lt;/i&gt;), the course-of-action is ignored. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;General syntax for an &lt;b&gt;if&lt;/b&gt;statement is :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;if(expression)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;statement;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;where a &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;statement&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;may consist of a single statement, a compound statement, or even an empty (or NULL) statement. The expression must be enclosed within parenthesis(). If the expression evaluates to &lt;i&gt;true&lt;/i&gt;, the &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;statement&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;is executed, otherwise ignored. For instance,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The code fragment &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;if(ch== ‘ ’)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;spaces ++;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;checks whether variable &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;ch&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;stores a space or not. If it does, the value of &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;spaces&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;is incremented by 1.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;Let’s look at one example :&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;int A,B,C;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cin&amp;gt;&amp;gt;A&amp;gt;&amp;gt;B&amp;gt;&amp;gt;C;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;if(A &amp;gt; 10 &amp;amp;&amp;amp; B &amp;lt; 15)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;C= A+B;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;cout&amp;lt;&amp;lt; “The result is ”&amp;lt;&amp;lt;C;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The above code uses a block of statements. Also, look at the expression used. Here two relational conditions are joined by logical AND (&amp;amp;&amp;amp;).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The expression part is an important aspect of &lt;b&gt;if-else&lt;/b&gt; statement. We know all conditions result in either &lt;i&gt;true&lt;/i&gt; or &lt;i&gt;false&lt;/i&gt;. The compiler takes 0 (zero) as &lt;i&gt;false&lt;/i&gt;and 1 (or any other integer other than 0) as &lt;i&gt;true&lt;/i&gt;. So now our expression may take the following forms :&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;1. if(n)&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;here n can be any number entered by the user or simply a constant. If &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;n&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;is not zero, the expression is taken as &lt;i&gt;true&lt;/i&gt;. For example ,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;if(23)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;statement;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;This expression is true and &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;statement&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;&lt;/span&gt;will be executed.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraph&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;2. if(n&amp;gt;10)&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Here, expression is a single relational expression which is &lt;i&gt;true&lt;/i&gt; if &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;n&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;is greater than 10 and &lt;i&gt;false&lt;/i&gt; if &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;n&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;is less than or equal to 10.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraph&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;3. if(n&amp;gt;10 &amp;amp;&amp;amp; n&amp;lt;20)&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Here, expression is a combination of two relational expressions joined by logical AND. So, if &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;n&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;is greater than 10 and it is less than 20 simultaneously, then only the expression will be true, otherwise it will be &lt;i&gt;false&lt;/i&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraph&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;4. if(n&amp;gt;10, n&amp;gt;20, n&amp;lt;15)&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;                         &lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Here, expression is combination of relational expressions separated by comma operator. As we know expressions separated by comma are evaluated from left to right and the value of entire expression is the value of rightmost expression. Thus (n&amp;gt;10,n&amp;gt;20,n&amp;lt;15) is actually equivalent to only (n&amp;lt;15). So, if &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;n&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;is less than 15 then the condition as a whole will be &lt;i&gt;true&lt;/i&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What if there is another course of action to be followed if the expression evaluates to &lt;i&gt;false&lt;/i&gt;? There is another form of if that allows for this kind of either-or condition by providing an &lt;b&gt;else&lt;/b&gt; clause. The syntax of the &lt;b&gt;if-else&lt;/b&gt; statement is the following :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;if (expression)&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;statement 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;else&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;statement 2;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;If the &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;expression&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;evaluates to &lt;i&gt;true&lt;/i&gt;, the &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;statement 1&lt;/span&gt;&lt;/i&gt; is executed, otherwise, &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;statement 2&lt;/span&gt;&lt;/i&gt; is executed. &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;statement 1&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;and &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;statement 2&lt;/span&gt;&lt;/i&gt;can be single statements, block of statements or empty statements.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The above code can be represented in a flowchart as :&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-ZVqAUu9RLHw/XxXJqkCIuEI/AAAAAAAAAKI/a5ztXCdvCO43HwvxCqWo_ggnlnkHiy9YgCLcBGAsYHQ/s1844/Untitled%2BDiagram%2B%25284%2529.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;if-else statement in C/C++&quot; border=&quot;0&quot; data-original-height=&quot;1844&quot; data-original-width=&quot;1444&quot; height=&quot;400&quot; src=&quot;https://1.bp.blogspot.com/-ZVqAUu9RLHw/XxXJqkCIuEI/AAAAAAAAAKI/a5ztXCdvCO43HwvxCqWo_ggnlnkHiy9YgCLcBGAsYHQ/w314-h400/Untitled%2BDiagram%2B%25284%2529.png&quot; title=&quot;if-else statement in C/C++&quot; width=&quot;314&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Now look at a program in C++ to find greater number among the two.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;background-color: azure; border: 1px solid white; height: 530px; overflow: auto hidden; width: 380px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;width: 150%;&quot;&gt;&lt;span style=&quot;color: grey; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-themecolor: background1; mso-themeshade: 128;&quot;&gt;//program to demonstrate working of if-else&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 150%;&quot;&gt;&lt;span style=&quot;color: grey; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-themecolor: background1; mso-themeshade: 128;&quot;&gt;//Find greater of two numbers.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 150%;&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;lt;iostream&amp;gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 150%;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;using namespace &lt;b&gt;std&lt;/b&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 150%;&quot;&gt;&lt;span style=&quot;color: #7030a0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;main()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 150%;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 150%;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #7030a0;&quot;&gt;int &lt;/span&gt;a,b;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 150%;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #c45911; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;cin&lt;/span&gt;&amp;gt;&amp;gt;a&amp;gt;&amp;gt;b;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 150%;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #7030a0;&quot;&gt;if&lt;/span&gt;(a &amp;gt; b)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 150%;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #c45911; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;cout&lt;/span&gt;&amp;lt;&amp;lt; &lt;span style=&quot;color: #00b050;&quot;&gt;“Greater number is ”&lt;/span&gt; &amp;lt;&amp;lt;a;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 150%;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #7030a0;&quot;&gt;else&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 150%;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #c45911; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;cout&lt;/span&gt;&amp;lt;&amp;lt; &lt;span style=&quot;color: #00b050;&quot;&gt;“Greater number is ”&lt;/span&gt;&amp;lt;&amp;lt;b;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 150%;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #7030a0;&quot;&gt;return &lt;/span&gt;0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 150%;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Input : 10 20&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Output : Greater number is 20&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Nested if&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;A nested &lt;b&gt;if&lt;/b&gt; is an &lt;b&gt;if&lt;/b&gt; that has another &lt;b&gt;if&lt;/b&gt; in its &lt;b&gt;if’s&lt;/b&gt; body or in its &lt;b&gt;else’s&lt;/b&gt;body. The nested &lt;b&gt;ifs&lt;/b&gt; can have 3 different forms :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Form 1 : if nested inside if-part&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;if (expression 1)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;if(expression 2)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;statement 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;else&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;statement 2;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;else&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;statement 3;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;//rest of program&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Explanation&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt; : If expression 1 is true, the control moves into the if block and checks expression 2. If it is true then statement 1 is executed and control moves to rest of program. If expression 2 is false, statement 2 is executed and control moves to rest of program. If the expression 1 is false, the control doesn’t enter the if and executes statement 3 and then moves to rest of program.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Form 2 : if nested inside else-part&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;if(expression 1)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;statement 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;else&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;if(expression 2)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;statement 2;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;else&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;statement 3;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Form 3 : if nested inside both if-part and else-part&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;if(expression 1)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;if(expression 2)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;statement 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;else&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;statement 2;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;else&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;if(expression 3)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;statement 3;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;else&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;statement 4;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Note: All &lt;b&gt;else&lt;/b&gt; statements are always optional.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Well let us take a test.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;background-color: azure; border: 1px solid white; height: 560px; width: 250px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;lt;&lt;span style=&quot;color: #00b050;&quot;&gt;iostream&lt;/span&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;using namespace &lt;b&gt;std&lt;/b&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #7030a0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;main()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #7030a0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;n; &lt;span style=&quot;color: #c55a11; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #C55A11; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;cin&lt;/span&gt;&amp;gt;&amp;gt;n;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #7030a0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;(n % 2==0)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #7030a0;&quot;&gt;if &lt;/span&gt;(n % 5==0)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #c55a11; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #C55A11; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;cout&lt;/span&gt;&amp;lt;&amp;lt; &lt;span style=&quot;color: #00b050;&quot;&gt;“Yes”&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #7030a0;&quot;&gt;else&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #c55a11; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #C55A11; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;cout&lt;/span&gt;&amp;lt;&amp;lt;&lt;span style=&quot;color: #00b050;&quot;&gt; “Part yes”&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #7030a0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;else&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #c55a11; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #C55A11; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;cout&lt;/span&gt;&amp;lt;&amp;lt; &lt;span style=&quot;color: #00b050;&quot;&gt;“No”&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #7030a0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Assume inputs from your side and comment down the output.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The if-else-if Ladder &lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;A common programming construct in C++ is the &lt;i&gt;if-else-if ladder&lt;/i&gt;, which is often also called the &lt;i&gt;if-else-if staircase&lt;/i&gt; because of its appearance.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;General form :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;if (expression 1) statement 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;else&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;if(expression 2) statement 2;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;else&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;if(expression 3) statement 3;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;……&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;else statement 4;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Although it is technically correct to have indentation in the &lt;i&gt;if-else-if ladder&lt;/i&gt; as shown above. But it generally leads to overly deep indentation. For this reason, the &lt;i&gt;if-else-if ladder&lt;/i&gt; is generally indented like :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;if(expression 1)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;statement 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;else if (expression 2)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;statement 2;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;else if (expression 3)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;statement 3;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;……..&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;else&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;statement 4;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Few important points about if-else-if ladder :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpFirst&quot; style=&quot;mso-list: l1 level1 lfo2; text-indent: -18pt;&quot;&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: Georgia; mso-fareast-font-family: Georgia;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;1.&lt;span style=&quot;font: 7pt &amp;quot;times new roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;if statement must be present; and it should be before all else if and else statements.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;mso-list: l1 level1 lfo2; text-indent: -18pt;&quot;&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: Georgia; mso-fareast-font-family: Georgia;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;2.&lt;span style=&quot;font: 7pt &amp;quot;times new roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Any number of else-ifs can be used but they should all be placed between the if and the else statement (if present).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;mso-list: l1 level1 lfo2; text-indent: -18pt;&quot;&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: Georgia; mso-fareast-font-family: Georgia;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;3.&lt;span style=&quot;font: 7pt &amp;quot;times new roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;else is not always needed but if present, it should be only one in number and after all else-ifs.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpLast&quot; style=&quot;mso-list: l1 level1 lfo2; text-indent: -18pt;&quot;&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: Georgia; mso-fareast-font-family: Georgia;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;4.&lt;span style=&quot;font: 7pt &amp;quot;times new roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Once the control enters any of the statements (be it if or any of the else-ifs), it ignores all the following statements and control comes out of if-else-if ladder.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;A common Mistake :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;While comparing for equality, make sure to use the relational equality operator (==) and not the assignment operator (=).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;if(p=4) &lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;is always TRUE statement. To check if value in p is equal to 4, we need to use &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;if(p==4)&lt;/span&gt;&lt;/i&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;p=4 actually assigns 4 to p and all assignments other than 0 (zero) are regarded as true. So, &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;if(p=0)&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;will be always false and any other assignment to p will be always true. So, always keep in mind to use the relational operator (==) and not assignment operator (=).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: 13.5pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot; style=&quot;-webkit-text-stroke-width: 0px; font-variant-caps: normal; font-variant-ligatures: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; orphans: 2; text-decoration-color: initial; text-decoration-style: initial; widows: 2; word-spacing: 0px;&quot;&gt;&lt;span style=&quot;mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Did you find the article helpful? Do you want to add something to it? Feel free to comment on this post below.&lt;o:p&gt;&lt;/o:p&gt;&lt;span style=&quot;color: black; font-size: 13.5pt; line-height: 107%;&quot;&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot; style=&quot;-webkit-text-stroke-width: 0px; font-variant-caps: normal; font-variant-ligatures: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; orphans: 2; text-decoration-color: initial; text-decoration-style: initial; widows: 2; word-spacing: 0px;&quot;&gt;&lt;span style=&quot;mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Do not stop here. To read all about C/C++ click&amp;nbsp;&lt;a href=&quot;https://www.computercodec.com/&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red;&quot;&gt;here&lt;/span&gt;&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;span style=&quot;color: black; font-size: 13.5pt; line-height: 107%;&quot;&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot; style=&quot;-webkit-text-stroke-width: 0px; font-variant-caps: normal; font-variant-ligatures: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; orphans: 2; text-decoration-color: initial; text-decoration-style: initial; widows: 2; word-spacing: 0px;&quot;&gt;&lt;span style=&quot;mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;To download pdf format of this article, click&amp;nbsp;&lt;i&gt;&lt;span&gt;&lt;a href=&quot;https://drive.google.com/file/d/14f64Q6JYZFdg0dBhJOrFWIzGkKYS4c6r/view?usp=sharing&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;here&lt;/font&gt;&lt;/a&gt;&lt;/span&gt;&lt;/i&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;span style=&quot;color: black; font-size: 13.5pt; line-height: 107%;&quot;&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot; style=&quot;-webkit-text-stroke-width: 0px; font-variant-caps: normal; font-variant-ligatures: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; orphans: 2; text-decoration-color: initial; text-decoration-style: initial; widows: 2; word-spacing: 0px;&quot;&gt;&lt;span style=&quot;mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;color: black; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to contribute any article or any piece of information you can send it on&amp;nbsp;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;coding.nkcoder@gmail.com&lt;/a&gt;. We will publish it in your name.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: 13.5pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/2936325830744806847/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=2936325830744806847&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/2936325830744806847'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/2936325830744806847'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/if-else-statement-in-cc.html' title='if-else STATEMENT IN C/C++'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-1213387602302622429</id><published>2020-07-19T17:51:00.002+05:30</published><updated>2020-07-19T17:54:57.144+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CPP"/><title type='text'>SETW() &amp; SETPRECISION() IN C++</title><content type='html'>&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;We know we can print our result on the screen using &lt;b&gt;cout&lt;/b&gt;statement. It is fine if we are only interested in the result. But at times we may need to print our output in a certain way. This task can be fulfilled by using I/O manipulators like &lt;b&gt;setw()&lt;/b&gt;, &lt;b&gt;setprecision()&lt;/b&gt;, etc.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #002060; font-family: georgia, serif; font-size: 18pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;background-color: #cccccc;&quot;&gt;Formatting Output :&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #002060; font-family: georgia, serif; font-size: 18pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Formatting output is important in the development of output screens, which can be easily read and understood. C++ offers several input/output manipulators. Two of these I/O manipulators are &lt;b&gt;setw()&lt;/b&gt; and &lt;b&gt;setprecision()&lt;/b&gt;. In order to use these manipulators, you must include header file &lt;span style=&quot;color: #c45911; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;iomanip&lt;/span&gt;, i.e. your program should also have following #include directive along with other #include directives :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;#include&amp;lt;iomanip&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;note : if you are using Turbo C, you need to use #include&amp;lt;iomanip.h&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;background-color: #cccccc; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;setw() manipulator&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;background-color: #cccccc;&quot;&gt; :&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The &lt;b&gt;setw()&lt;/b&gt; manipulator sets the width of the field assigned for output. It basically right justifies the output. It takes the size of the field (in number of characters) as a parameter. For example, the code :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;cout&amp;lt;&amp;lt;setw(6)&amp;lt;&amp;lt;”R”;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;generates the following output (each underscore is for a space)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Output : &lt;span style=&quot;color: #00b050;&quot;&gt;_ _ _ _ _ R&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;setw()&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; manipulator is &lt;i&gt;non-sticky statement&lt;/i&gt;. This means that a &lt;b&gt;setw()&lt;/b&gt; manipulator is applicable only to its immediately following statement. So, if you want to right justify three numbers in separate lines, you need to repeat &lt;b&gt;setw()&lt;/b&gt; manipulators for each line. For example,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;cout&amp;lt;&amp;lt;setw(8)&amp;lt;&amp;lt;6&amp;lt;&amp;lt;endl;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;cout&amp;lt;&amp;lt;setw(8)&amp;lt;&amp;lt;66&amp;lt;&amp;lt;endl;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;cout&amp;lt;&amp;lt;setw(8)&amp;lt;&amp;lt;666;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Output:&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #00b050;&quot;&gt;_ _ _ _ _ _ _ 6&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #00b050;&quot;&gt;_ _ _ _ _ _ 6 6&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;_ _ _ _ _ 6 6 6&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Also,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cout&amp;lt;&amp;lt;setw(6)&amp;lt;&amp;lt;6&amp;lt;&amp;lt; “R\n”;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cout&amp;lt;&amp;lt;setw(6)&amp;lt;&amp;lt;6;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cout&amp;lt;&amp;lt;setw(6)&amp;lt;&amp;lt; “R”;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Output :&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #00b050;&quot;&gt;_ _ _ _ _ 6 R &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;_ _ _ _ _ 6 _ _ _ _ _ R&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;note : In all the above outputs, underscore (_) means a blank space&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;background-color: #cccccc; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;setprecision() manipulator :&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The &lt;b&gt;setprecission()&lt;/b&gt;manipulator sets the total number of digits to be displayed when floating point numbers are printed. For example,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cout&amp;lt;&amp;lt; setprecision(5)&amp;lt;&amp;lt;123.456;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Output : &lt;span style=&quot;color: #00b050;&quot;&gt;123.46&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;(note: See it displays 5 digits and rounds off the floating point number)&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;setprecission()&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt; manipulator can also be used to set the number of digits after decimal by using an &lt;i&gt;ios flag&lt;/i&gt;. An &lt;i&gt;ios flag&lt;/i&gt;can be set using &lt;b&gt;setf()&lt;/b&gt; as :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cout.setf(ios::fixed);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Once the flag has been set, the number we pass as argument in &lt;b&gt;setprecision()&lt;/b&gt; is the number of decimal places we want to display. For example,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cout.setf(ios::fixed);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cout&amp;lt;&amp;lt;setprecision(3)&amp;lt;&amp;lt;123.4567;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Output : &lt;span style=&quot;color: #00b050;&quot;&gt;123.456&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;(See it displays 5 digits after decimal without rounding off). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Also, &lt;b&gt;setprecision()&lt;/b&gt;is a &lt;i&gt;sticky manipulator&lt;/i&gt;, i.e. whatever precision we set once, sticks with &lt;b&gt;cout&lt;/b&gt; until we change it with another &lt;b&gt;setprecision()&lt;/b&gt; later in the program.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;background-color: #cccccc;&quot;&gt;Additional &lt;i&gt;ios flags&lt;/i&gt; :&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;General syntax:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cout.setf(ios::flag);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;where flag is any one of the following :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid blue; height: 350px; overflow: scroll hidden; width: 610px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;width: 180%;&quot;&gt;&lt;span style=&quot;color: #c45911; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;left&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;: left justify the output&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 180%;&quot;&gt;&lt;span style=&quot;color: #c45911; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;right&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;: right justify the output&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 180%;&quot;&gt;&lt;span style=&quot;color: #c45911; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;showpoint &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;: display decimal points and trailing zeroes for floating&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 180%;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;numbers.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 180%;&quot;&gt;&lt;span style=&quot;color: #c45911; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;uppercase &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;: display the “e” in E-notation as “E”&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 180%;&quot;&gt;&lt;span style=&quot;color: #c45911; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;showpos&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;: display a leading plus sign before positive numbers&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 180%;&quot;&gt;&lt;span style=&quot;color: #c45911; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;scientific&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;: display floating point numbers in scientific (“E”) notation&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 180%;&quot;&gt;&lt;span style=&quot;color: #c45911; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;fixed&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;: display floating point numbers in normal notation-no trailing&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 180%;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;zeroes and no scientific notation. &lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Few examples :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;If you want to represent 6.8 as 6.80&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cout.setf(ios::showpoint);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cout&amp;lt;&amp;lt;setprecision(3)&amp;lt;&amp;lt;6.8;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Output :&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #00b050;&quot;&gt;6.80&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;If you want to represent 60 as +60&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cout.setf(ios::showpos);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cout&amp;lt;&amp;lt;60;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Output : &lt;span style=&quot;color: #00b050;&quot;&gt;+60&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Any flag set using &lt;b&gt;setf()&lt;/b&gt;can be removed using &lt;b&gt;unsetf()&lt;/b&gt;. For example,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cout.setf(ios::showpos);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cout&amp;lt;&amp;lt;60&amp;lt;&amp;lt;endl;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cout&amp;lt;&amp;lt;25&amp;lt;&amp;lt;endl;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cout.unsetf(ios::showpos);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cout&amp;lt;&amp;lt;60;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Output :&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #00b050;&quot;&gt;+60&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;+25&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;60&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Which topics you want an article on? Comment down on this post.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Do not stop here. Read all articles related to C++ &lt;a href=&quot;https://www.computercodec.com/&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;&lt;font color=&quot;#ff0000&quot;&gt;here&lt;/font&gt;&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to contribute any article for the website, feel free to share it on &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. We will publish it on the website with your name.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Download the pdf form of this article &lt;a href=&quot;https://drive.google.com/file/d/1rRHcwHJ2LUIKHeAY9VVt-6zq81W-6453/view?usp=sharing&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;&lt;font color=&quot;#ff0000&quot;&gt;here&lt;/font&gt;&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/1213387602302622429/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=1213387602302622429&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/1213387602302622429'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/1213387602302622429'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/setw-setprecision-in-c.html' title='SETW() &amp; SETPRECISION() IN C++'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-3890956855254904510</id><published>2020-07-18T19:19:00.002+05:30</published><updated>2020-07-18T19:26:08.448+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CPP"/><category scheme="http://www.blogger.com/atom/ns#" term="Operators"/><title type='text'>OPERATORS IN C/C++</title><content type='html'>&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;C/C++ programs are made with the chief intention of solving a certain task. These tasks can be from simple day to day calculations to complex algorithms. But in all these tasks one thing that is common is that we need to compute certain expressions. We need to take inputs from user, then calculate the desired result and output the result on the screen. All these actions are completed using special tokens called the Operators.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #002060; font-family: georgia, serif; font-size: 18pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;background-color: #cccccc; color: #002060; font-family: georgia, serif; font-size: 18pt; line-height: 107%;&quot;&gt;OPERATORS IN C/C++&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #002060; font-family: georgia, serif; font-size: 18pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The operators in C++ are classified into many categories. In this article we will learn about them in very short. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;In a program, we perform various operations on data. Operators let us perform operations on your data.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;C++’s rich set of operators comprise of I/O, arithmetic, relational, logical and certain other types of operators.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;I/O Operators :&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Input coming from the user’s terminal, referred to as &lt;i&gt;standard input&lt;/i&gt; is tied to the predefined iostream &lt;i&gt;cin&lt;/i&gt; and output directed to the user’s terminal, referred to as &lt;i&gt;standard output&lt;/i&gt;, is tied to the predefined iostream &lt;i&gt;cout&lt;/i&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Output operator (“&amp;lt;&amp;lt;”) : The output operator (“put to”) is used to direct a value to standard output. For instance,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;cout&amp;lt;&amp;lt; “The sum of 6 &amp;amp; 2 is ”;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;cout&amp;lt;&amp;lt; 6+2;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Output :&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #00b050;&quot;&gt;The sum of 6 &amp;amp; 2 is 8&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #c55a11; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #C55A11; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;Input Operator (“&amp;gt;&amp;gt;”) &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;: The input operator (“get from”) is used to read a value from standard input.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int n;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;cin&amp;gt;&amp;gt; n&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;This takes input from the user till he hits enter.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Also, many of these operators can be used together to take many inputs or to give many outputs. (It’s called Cascading)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;cout&amp;lt;&amp;lt; “Learn ” &amp;lt;&amp;lt; “to ” &amp;lt;&amp;lt; “code ”;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Output :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #00b050;&quot;&gt;Learn to code&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;Arithmetic Operators :&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;To do arithmetic, C++ uses operators. It provides operators for five basic arithmetic calculations : addition, subtraction, multiplication, division and modulus which are +, -, *, /, % respectively. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Each of these operators is a binary operator i.e. it requires two values (operands) to calculate a final answer. Apart from these binary operators, C++ provides two unary arithmetic operators : unary plus and unary minus.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The arithmetic operators in C++ have the same function as they have in mathematics. The modulus operator (%) produces the remainder of dividing the first operand by second. But both the operands must be integer types here. Rest all other operators can work with integer and floating-point values. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Let us see the workings briefly :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;cout&amp;lt;&amp;lt; 8+6&amp;lt;&amp;lt; “ ”;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;cout&amp;lt;&amp;lt; 8-6&amp;lt;&amp;lt; “ ”;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;cout&amp;lt;&amp;lt; 8*6&amp;lt;&amp;lt; “ ”;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;cout&amp;lt;&amp;lt; 8/6&amp;lt;&amp;lt; “ ”;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;cout&amp;lt;&amp;lt; 8%6;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Output : &lt;/span&gt;&lt;span style=&quot;color: #00b050; font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt; line-height: 107%;&quot;&gt;14 2 48 1 2&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 12pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Note that 8/6 yields 1 and not 1.33. This is due to the fact that both operands 8 &amp;amp; 6 are integers and so the entire expression works as integers. We can understand it as 8 = 6 * (1) + 2; So, the integer division yields 1 and the modulus yields the remainder 2.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Increment/Decrement Operators :&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The increment operator, ++, adds 1 to its operand and the operator – subtracts 1 from its operands. That is, a = a+1 is equal to a++ (or ++a) and a = a-1 is equal to a—(or --a).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The two forms are called postfix and prefix.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Postfix :&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;a++ &lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;or&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;a—&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Prefix&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;:&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;++a &lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;or&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;--a&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The postfix form of ++, -- operators follow the rule use-then change. For example,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;int sum = 6;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;int c = 2;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;sum = sum + (c++);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cout&amp;lt;&amp;lt; “Sum = ” &amp;lt;&amp;lt;sum&amp;lt;&amp;lt;endl;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cout&amp;lt;&amp;lt; “ c = ” &amp;lt;&amp;lt;c;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Output :&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #00b050;&quot;&gt;Sum = 8&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;c = 3&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The prefix form of ++,-- operators follow the rule change-then-use. For example,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;int sum = 6;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;int c = 2;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;sum = sum + (++c);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cout&amp;lt;&amp;lt; “Sum = ” &amp;lt;&amp;lt;sum&amp;lt;&amp;lt;endl;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cout&amp;lt;&amp;lt; “ c = ” &amp;lt;&amp;lt;c;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Output :&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #00b050;&quot;&gt;Sum = 9&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;c = 3&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 12pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Note : &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 12pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Increment/Decrement operators have a higher precedence than the arithmetic operators. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 12pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Post fix form is at higher precedence than prefix form.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Relational Operators :&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Relational operators determine the relation among different operands. C++ provides six relational operators for comparing numbers and characters. But they do not work on arrays.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Each of these operators is binary and returns a Boolean value (i.e. either true or false). If an expression is true, it returns true (or 1) and if the expression is false, it returns false (or 0).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The six relational operators are :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #c55a11; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #C55A11; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;&amp;lt; &lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;(less than)&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #c55a11; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #C55A11; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;&amp;gt; &lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;(greater than)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #c55a11; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #C55A11; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;&amp;lt;= &lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;(less than or equal to)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #c55a11; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #C55A11; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;&amp;gt;=&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;(greater than or equal to)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #c55a11; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #C55A11; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;==&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;(equal to)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #c55a11; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #C55A11; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;!=&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(not equal to)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Logical Operators :&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;   &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;C++ provides for 3 logical operators to combine existing expressions. These are || (logical OR), &amp;amp;&amp;amp; (logical AND) and ! (logical NOT). Let us examine them :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #c55a11; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #C55A11; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;The logical OR operator (||) &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;: It evaluates true if any of the operands evaluate true, else false.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #c55a11; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #C55A11; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;The logical AND operator(&amp;amp;&amp;amp;) &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;: It combines two expressions together just like OR. The resulting expression has the value 1 (i.e. true) only if both of the original expressions (its operands) are true.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #c55a11; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #C55A11; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;The logical NOT operator (!) &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;: This operator, unlike the other two, works on a single expression (operand),i.e. it is a unary operator. It negates or reverses the truth value of an expression, i.e. if the expression is true, then ! (expression) is false and vice versa.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Conditional Operator :&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;C++ offers one conditional operator, which is also popularly called as ternary operator as it needs 3 operands to work.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;General syntax :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 80px; overflow: scroll hidden; width: 350px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;width: 150%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;expression 1 ? expression 2 : expression 3;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;If expression 1 is true, then the value of the whole expression is the value of expression 2, otherwise, the value of the whole expression is the value of expression 3.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Example :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;int marks = 58; char grade;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;grade = marks&amp;gt;=50 ? ‘P’ : ‘F’ ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cout&amp;lt;&amp;lt; “The grade is ”&amp;lt;&amp;lt;grade;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Output : &lt;span style=&quot;color: #00b050;&quot;&gt;The grade is P&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;int marks = 48; char grade;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;grade = marks&amp;gt;=50 ? ‘P’ : ‘F’ ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cout&amp;lt;&amp;lt; “The grade is ”&amp;lt;&amp;lt;grade;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Output : &lt;span style=&quot;color: #00b050;&quot;&gt;The grade is F&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 12pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Note : The value holding variable (here grade) must be of the correct data type.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Some other Operators :&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #c55a11; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #C55A11; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;The Compile-Time Operator sizeof() &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;: It is a unary compile-time operator that returns the length (in bytes) of the variable or any type-specifier which is put within the parenthesis. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;It can be used 2 forms :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 130px; overflow: scroll hidden; width: 410px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;width: 180%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;sizeof var;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;// where var is a declared variable&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 180%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;sizeof&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt; &lt;i&gt;(type);&lt;/i&gt; &lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;// where type is any C++ data type&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #c55a11; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #C55A11; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 191;&quot;&gt;The Comma Operator &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;: A comma operator is used to string together several expressions. The group of expressions separated by commas (,) is evaluated left-to-right in sequence and the result of the right-most expression becomes the value of the total comma-separated expression.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;For example,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;int a=3,b;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;b = (a+1,a+3);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;cout&amp;lt;&amp;lt;b;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Output : &lt;span style=&quot;color: #00b050;&quot;&gt;6&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Evaluating left to right, a+1 = 4; then a+3 = 6. As a+3 is the rightmost expression, it is stored in b.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Which topics you want an article on? Comment down on this post.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Do not stop here. Read all articles related to C++ &lt;a href=&quot;https://www.computercodec.com/&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;&lt;font color=&quot;#ff0000&quot;&gt;here&lt;/font&gt;&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to contribute any article for the website, feel free to share it on &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. We will publish it on the website with your name.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Download the pdf form of this article &lt;a href=&quot;https://drive.google.com/file/d/1BFh0nIM7nIW6TkNkRZ8D4VqyDTqDa-dP/view?usp=sharing&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;&lt;font color=&quot;#ff0000&quot;&gt;here&lt;/font&gt;&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/3890956855254904510/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=3890956855254904510&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/3890956855254904510'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/3890956855254904510'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/operators-in-cc.html' title='OPERATORS IN C/C++'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-1631094499357570392</id><published>2020-07-18T11:17:00.003+05:30</published><updated>2020-07-18T11:25:11.769+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CPP"/><title type='text'>VARIABLES IN C/C++</title><content type='html'>&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A programmer writes a code to perform a task. He is responsible for creating all logics and writing the entire code to serve the purpose. But what is the need of a program? &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A program is useful when it takes input from users all across the globe and then process it to yield the desired result. This work of taking inputs from users and forming meaningful expressions is done by variables.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #002060; font-family: georgia, serif; font-size: 18pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;background-color: #cccccc;&quot;&gt;VARIABLES&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;span&gt;&lt;/span&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Variables (also called Symbolic Variables) represent named storage locations whose values can be manipulated during program run.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A variable is a named memory location which stores values, one at a time, and these values can be changed during the execution of program.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Computer memory consists of memory blocks of 1 byte size, each of which has a unique address. It is through this address that the compiler knows where a particular variable is stored. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Every variable has two values associated with it :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Data value&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;: It is the actual value stored into the variable and is used for all general calculations and operations. It is referred to as &lt;i&gt;rvalue&lt;/i&gt; (read-value)(pronounced as “are-value”).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Location value&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; : It is in a way the location value of a variable. In C++, a &lt;i&gt;lvalue&lt;/i&gt; is something that points at a legal memory block. It appears to the left side of assignment operator (=) and is used to assign a &lt;i&gt;rvalue&lt;/i&gt; to a variable. This concept is a bit tricky and we will read about it in details in a separate article.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;margin-top: 12pt; text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Rules for naming a variable in C/C++ :&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;blockquote style=&quot;border: none; margin: 0px 0px 0px 40px; padding: 0px; text-align: left;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt; text-align: left;&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;A variable name can contain any digit, alphabets or underscore(_), i.e. 0 to 9, A to Z, a to z and _.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;A variable name cannot contain any special character (not even space).&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;A variable name cannot start with a digit, but the digits can be used anywhere else in the name.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;A variable name must not match any of the keywords defined to the C/C++ compiler.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;A variable name can start with underscore (_).&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;As C/C++ is case dependent language, capital and small lettered variables (example : A and a) are considered two separate variables.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;/blockquote&gt;           &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Some Invalid Variable names :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 180px; overflow: scroll hidden; width: 380px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt; width: 150%;&quot;&gt;&lt;span style=&quot;color: #7f6000; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #7F6000; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent4; mso-themecolor: accent4; mso-themeshade: 128;&quot;&gt;1name&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;(starting with a digit)&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt; width: 150%;&quot;&gt;&lt;span style=&quot;color: #7f6000; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #7F6000; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent4; mso-themecolor: accent4; mso-themeshade: 128;&quot;&gt;my name&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;(includes special character (space))&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt; width: 150%;&quot;&gt;&lt;span style=&quot;color: #7f6000; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #7F6000; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent4; mso-themecolor: accent4; mso-themeshade: 128;&quot;&gt;dollar$&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;(includes special character ($))&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt; width: 150%;&quot;&gt;&lt;span style=&quot;color: #7f6000; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #7F6000; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent4; mso-themecolor: accent4; mso-themeshade: 128;&quot;&gt;break&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;(predefined keyword)&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Declaration of a variable :&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Unlike python, C/C++ compiler needs details about what kind of values can be stored in a variable. This information is conveyed through the data type of the variable. Type is important as the compiler decides accordingly what operations are feasible for that variable. C++ has the following data types :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 250px; overflow: scroll hidden; width: 650px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt; width: 180%;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;char&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;: stores a single character in single quotes (e.g.: ‘A’, ‘2’, ‘&amp;amp;’)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt; width: 180%;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;int&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;: stores an integer value (e.g.: 45, 98, -65)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt; width: 180%;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;float&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;: stores a real value (e.g.: 2.05, -6.52, 5.0)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt; width: 180%;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;double&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;: stores real value with higher precision (e.g.: 2.05, -6.52, 5.0)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt; width: 180%;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;boolean&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; : stores either false (as zero (0)) or true (as any number other than 0)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt; width: 180%;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;void&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;: Its an empty type. Used to represent an empty variable.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;General Syntax for declaration :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;data_type variable_name;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;e.g. :&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;int a; char ch; float f; double d;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A variable can also be declared as a constant using the keyword &lt;b&gt;const&lt;/b&gt;. A constant variable is not a &lt;i&gt;lvalue&lt;/i&gt;and so its value cannot be changed once it is initialized. Also, a constant variable must be initialized as soon as it is declared. See the following code for explanation :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 100px; overflow: scroll hidden; width: 450px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt; width: 150%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;const int n ;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;// error: uninitialized const variable&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt; width: 150%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;const int n = 10;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;// ok.&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;h3 style=&quot;margin-top: 12pt; text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Initialization of variables :&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Variables can be initialized in 2 ways :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#800180&quot;&gt;Statically at time of creation&lt;/font&gt; : Example : &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int i = 10;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#800180&quot;&gt;Dynamically during run time&lt;/font&gt; : Example :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;int i = sum/count ;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt; &lt;blockquote style=&quot;border: none; margin: 0px 0px 0px 40px; padding: 0px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt; text-align: left;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;This statement initializes &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;i&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;using the information available at run time, i.e. using the values of variables &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;sum&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;&amp;amp; &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;count&lt;/span&gt;&lt;/i&gt;.&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;margin-top: 12pt; text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Variables based on their scope of action :&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A variable remains in memory as long as the block in which it is declared is under execution. A variable declared within a function cannot be accessed outside the function block. Depending on the scope variables can be grouped into 2 groups : Global &amp;amp; Local.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Global variables :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A variable declared outside all the blocks (i.e. outside all {}) is called a global variable. As it is not enclosed within any block, it is available to all the functions of the program, i.e. its scope is for the entire program. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Local variables :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A variable declared inside some block (i.e. within {}) becomes available to only that block and as soon as control comes out of the block, the variable is removed from the memory. Thus, its scope is limited to that block only.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;To know more about Global &amp;amp; Local variables and examples, read another article on this website.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Which topics you want an article on? Comment down on this post.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Do not stop here. Read all articles related to C++ &lt;a href=&quot;https://www.computercodec.com/&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;&lt;i&gt;here&lt;/i&gt;&lt;/font&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to contribute any article for the website, feel free to share it on &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. We will publish it on the website with your name.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Download the pdf form of this article here.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 12pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/1631094499357570392/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=1631094499357570392&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/1631094499357570392'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/1631094499357570392'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/variables-in-cc.html' title='VARIABLES IN C/C++'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-3908935202708242173</id><published>2020-07-17T19:34:00.002+05:30</published><updated>2020-07-28T11:32:06.471+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Datatype"/><title type='text'>USER DEFINED DATATYPES IN C/C++</title><content type='html'>&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;There are some derived data types that are defined by the user. These are class, structure, union and enumeration. This article briefly talks about these user-defined derived data types.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;span style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #0070c0; font-family: Georgia, serif;&quot;&gt;USER DEFINED DATATYPES &lt;/span&gt;&lt;span style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; font-family: Georgia, serif;&quot;&gt;IN C/C++&lt;/span&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/h2&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;background-color: #eeeeee; font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;Class&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A class represents a group of similar objects. To represent classes in C++, it offers a user defined type called class. Once a class has been defined in C++, objects belonging to that class can easily be created. A class bears the same relationship to an object as a data type bears to a variable.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;To define a class, we describe what sort of information it can represent and what sort of actions you can perform with that data. For instance, if you want to create class – department, it can represent the information like name of the department, number of its employees, name of its head and the actions that can be performed with this information are : addition, deletion, modification of employee data, printing of department report etc. Now this class will be declared in C++ as :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;class department&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;char name[20];&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;int num_emp ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;char h_o_d [20];&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;public:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;void add();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;void Delete();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;void modify();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;void print();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;};&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;department sales; &lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The above code defines a class &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;department&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;and the last statement creates an object named &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;sales&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;of the &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;department&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;class.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;background-color: #eeeeee; font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;Structure&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A structure is a collection of variables (of different data types) referenced under one name, providing of convenient means of keeping related information together. For example, a student record is collection of &lt;i&gt;rollno&lt;/i&gt;, &lt;i&gt;name&lt;/i&gt;, &lt;i&gt;Class&lt;/i&gt;, &lt;i&gt;marks&lt;/i&gt;, &lt;i&gt;grade&lt;/i&gt; etc. A structure definition forms a template that may be used to create structure variables. The variables that make up the structure are called structure elements. The keyword &lt;b&gt;struct&lt;/b&gt; is used to construct a structure.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The following code creates a structure for student records :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;struct student&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;int rollno;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;char name[20];&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;int Class;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;float marks;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;char grade;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;} ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;student s;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The above declaration declares a structure named &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;student&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;with structure elements &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;rollno&lt;/span&gt;&lt;/i&gt;, &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;name&lt;/span&gt;&lt;/i&gt;, &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;Class&lt;/span&gt;&lt;/i&gt;, &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;marks&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;and &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;grade&lt;/span&gt;&lt;/i&gt;. The last line creates (i.e. reserves memory) a structure variable named &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;s&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;of type student.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;As it might seem, both class and structure are similar aspects. You are right. In C++ they only differ depending on their default behaviour. Any member of a structure is by default public, while any member of a class is by default private. In fact, a structure is basically a class defined with &lt;b&gt;struct&lt;/b&gt; keyword.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The members of structure or class can be referenced using . (dot operator) as follows :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;object.member;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Example,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;s.rollno = 12;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;sales.add();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Here, &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;s.rollno&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;accesses &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;rollno&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;member of the variable &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;s&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;(of type student) and sets its value to 12.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Similarly, &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;sales.add()&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;accesses &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;add()&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;function of the object &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;sales&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;(of class department).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;background-color: #eeeeee; font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;Union&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A union is a memory location that is shared by two or more different variables, generally of different types at different times. Defining a union is similar to defining a structure. Following declaration declares a union share having two variables (integer and character type) and creates a union object &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;cnvt&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;&lt;/span&gt;of type share :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;union share&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;int i;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;char ch;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;} ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;union share cnvt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The keyword &lt;b&gt;union&lt;/b&gt; is used for declaring and creating a union. In union &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;cnvt&lt;/span&gt;&lt;/i&gt;, both integer &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;i&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;&amp;amp; character &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;ch&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;share the same memory location. Of course, &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;i&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;being integer takes 4 bytes while &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;ch&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;takes 1 byte. The following figure illustrates the concept :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-QcHu_5xmHeY/Xx--nvG1PiI/AAAAAAAAAOI/HBpN-zXV1VkyufPzfKA9ANfyhx0_WAJBACLcBGAsYHQ/s1458/union.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;User-defined datatypes in C++&quot; border=&quot;0&quot; data-original-height=&quot;663&quot; data-original-width=&quot;1458&quot; height=&quot;286&quot; src=&quot;https://1.bp.blogspot.com/-QcHu_5xmHeY/Xx--nvG1PiI/AAAAAAAAAOI/HBpN-zXV1VkyufPzfKA9ANfyhx0_WAJBACLcBGAsYHQ/w625-h286/union.jpg&quot; title=&quot;User-defined datatypes in C++&quot; width=&quot;625&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A union is used when the same value is needed in different types. For example, if we need 65 at one point of time and ‘A’ at other we may do it in 2 ways:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;First, using the data type casting.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Second, using union.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Using of union is very rare in C++ programs but at times they do serve the purpose.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Let’s see an example:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;cnvt.i = 65;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Once &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;cnvt&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;member is assigned a value, this can be used in all the data types included in the union. For instance,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;cout&amp;lt;&amp;lt; cnvt.i&amp;lt;&amp;lt;endl;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;cout&amp;lt;&amp;lt; cnvt.ch;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Output:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;65 &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #00b050; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;background-color: #eeeeee; font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;Enumeration&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;An alternative method for naming integer constants is often more convenient that const. This can be achieved by creating enumeration using the keyword &lt;b&gt;enum&lt;/b&gt;. For example,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;enum{START, PAUSE, GO};&lt;/span&gt;&lt;/i&gt;&lt;i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The above code defines 3 integer constants, called &lt;i&gt;enumerators&lt;/i&gt;, and assigns values to them. Enumerator values are by default assigned increasing from 0, therefore, the above declaration is equivalent to writing&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;font color=&quot;#3d85c6&quot;&gt;const int START = 0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;font color=&quot;#3d85c6&quot;&gt;const int PAUSE = 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;font color=&quot;#3d85c6&quot;&gt;const int GO = 2;&lt;/font&gt;&lt;/i&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;An enumeration can be named also&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;enum status {START, PAUSE, GO};&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;status i = START;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Here, &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;status&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;acts as a distinct type (&lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;const int&lt;/span&gt;&lt;/i&gt;) and &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;i&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;is initialized with &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;START&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;(i.e. 0).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The enumerator values can be explicitly set by the programmer also.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;enum{START=2, PAUSE, GO};&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Here, &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;START&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;is initialized with 2 and all the other enumerators are initialized increasingly from 2 (i.e. &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;PAUSE&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;= 3 &amp;amp; &lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;GO&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt; &lt;/span&gt;= 4). The rule is that all enumerators are automatically assigned increasing values till an enumerator is again explicitly initialized.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Which topics you want an article on? Comment down on this post.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Do not stop here. Read all articles related to C++ &lt;a href=&quot;https://www.computercodec.com&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;&lt;font color=&quot;#ff0000&quot;&gt;here&lt;/font&gt;&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to contribute any article for the website, feel free to share it on &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. We will publish it on the website with your name.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Download the pdf form of this article &lt;a href=&quot;https://drive.google.com/file/d/19XWCs6h9hlmz7bQ0t-6Vt3-4qb5p9E-w/view?usp=sharing&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;&lt;font color=&quot;#ff0000&quot;&gt;here&lt;/font&gt;&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/3908935202708242173/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=3908935202708242173&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/3908935202708242173'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/3908935202708242173'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/user-defined-datatypes-in-cc.html' title='USER DEFINED DATATYPES IN C/C++'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-6120111234452245861</id><published>2020-07-17T11:36:00.003+05:30</published><updated>2020-07-28T11:19:39.333+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Datatype"/><title type='text'>DERIVED DATATYPES IN C++</title><content type='html'>&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;From the fundamental data types other types can be derived by using declaration operators. This article briefly introduces the derived data types in C++. You can find a detailed explanation of all these types on our site.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h2&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;span style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #0070c0; font-family: Georgia, serif;&quot;&gt;DERIVED DATA TYPES &lt;/span&gt;&lt;span style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; font-family: Georgia, serif;&quot;&gt;IN C/C++&lt;/span&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/h2&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 16.0pt; line-height: 107%;&quot;&gt;Arrays&lt;/span&gt;&lt;/b&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 16.0pt; line-height: 107%; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;Arrays refer to a named list of a finite number of similar data elements.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;General syntax : &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#2b00fe&quot;&gt;data_type array_name [size];&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;where &lt;font color=&quot;#2b00fe&quot;&gt;&lt;i&gt;data_type&lt;/i&gt; &lt;/font&gt;is the type of values array will store, &lt;font color=&quot;#2b00fe&quot;&gt;&lt;i&gt;array_name&lt;/i&gt; &lt;/font&gt;is the name of array and &lt;font color=&quot;#2b00fe&quot;&gt;&lt;i&gt;size&lt;/i&gt; &lt;/font&gt;is an integer denoting the number of elements in the array.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The elements of array can be accessed as :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#2b00fe&quot;&gt;array_name[index];&lt;/font&gt;&lt;font color=&quot;#203864&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;where, &lt;font color=&quot;#2b00fe&quot;&gt;&lt;i&gt;index&lt;/i&gt; &lt;/font&gt;is an integer denoting the position of that element. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Important points on Arrays &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpFirst&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18pt;&quot;&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: Georgia; mso-fareast-font-family: Georgia;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;1.&lt;span style=&quot;font: 7pt &amp;quot;times new roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;An array consists of elements of same data type. If it is an integer array it will store only integer elements. Character array will store only character elements and so on.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18pt;&quot;&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: Georgia; mso-fareast-font-family: Georgia;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;2.&lt;span style=&quot;font: 7pt &amp;quot;times new roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Arrays are allocated contagious memory address which makes them faster and easier to execute.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18pt;&quot;&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: Georgia; mso-fareast-font-family: Georgia;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;3.&lt;span style=&quot;font: 7pt &amp;quot;times new roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Indexing starts with number 0 and continues till size-1.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18pt;&quot;&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: Georgia; mso-fareast-font-family: Georgia;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;4.&lt;span style=&quot;font: 7pt &amp;quot;times new roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Trying to reference an index out of the bounds [0, size-1] causes crashing of program.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18pt;&quot;&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: Georgia; mso-fareast-font-family: Georgia;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;5.&lt;span style=&quot;font: 7pt &amp;quot;times new roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Arrays are not initialized by default. Uninitialized arrays contain arbitrary garbage values.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpLast&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18pt;&quot;&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-bidi-font-family: Georgia; mso-fareast-font-family: Georgia;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;6.&lt;span style=&quot;font: 7pt &amp;quot;times new roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Arrays can be multi-dimensional.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3&gt;&lt;b&gt;&lt;span style=&quot;background-color: #eeeeee; color: #0070c0; font-family: Georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Functions&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;A function is a named part of a program that can be invoked from other parts of the program as often as needed. A function is usually useful when we want to use a certain set code many times in a program. It would be a tiring and boring job to write the same set of statements over and over again. Instead, a programmer creates a function consisting of those codes so that he might easily use it whenever he needs it in his program.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;General syntax for a function is :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 200px; overflow: scroll hidden; width: 350px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#2b00fe&quot;&gt;return_type function_name (formal_parameter_list)&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#2b00fe&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#2b00fe&quot;&gt;/* body of the function */&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#2b00fe&quot;&gt;/*return statement, if needed */ &lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#2b00fe&quot;&gt;}&lt;/font&gt;&lt;font color=&quot;#203864&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;Read more &amp;gt;&amp;gt; &lt;a href=&quot;https://www.computercodec.com/search/label/Functions?&amp;amp;max-results=9&quot; target=&quot;_blank&quot;&gt;Functions in C++&lt;/a&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;background-color: #eeeeee; color: #0070c0; font-family: Georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Pointer&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A pointer variable is a variable that holds a memory address. This address is usually the location of another variable in the memory. If one variable contains the address of another variable, the first variable is said to point to the second variable. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If a variable is going to hold a pointer, it must be declared as such. A pointer declaration consists of a base type, an * (asterisk), and the variable name.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;General syntax :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#2b00fe&quot;&gt;data_type * pointer_name ;&lt;/font&gt;&lt;font color=&quot;#203864&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;where &lt;i&gt;&lt;font color=&quot;#2b00fe&quot;&gt;data_type &lt;/font&gt;&lt;/i&gt;is any valid C++ data type.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The base type (i.e. &lt;i&gt;&lt;font color=&quot;#2b00fe&quot;&gt;data_type&lt;/font&gt;&lt;/i&gt;) of the pointer determines what type of values the pointer can point to. Technically any pointer can point anywhere in the memory but the pointer arithmetic is done according to the base type so it becomes compulsory to declare pointers with correct base types.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;font face=&quot;georgia, serif&quot;&gt;&lt;span style=&quot;font-size: 18.6667px;&quot;&gt;Read more &amp;gt;&amp;gt; &lt;a href=&quot;https://www.computercodec.com/search/label/Pointers?&amp;amp;max-results=9&quot; target=&quot;_blank&quot;&gt;Pointers in C++&lt;/a&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;background-color: #eeeeee; color: #0070c0; font-family: Georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Reference&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A reference is an alternative name for an object. A reference variable provides an alias for a previously defined variable. A reference declaration consists of a base type, an &amp;amp; (ampersand), a reference variable name equated to a variable (previously defined). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;General syntax :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 70px; overflow: scroll hidden; width: 400px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#2b00fe&quot;&gt;data_type &amp;amp; ref_var_name = variable_name ;&lt;/font&gt;&lt;font color=&quot;#203864&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;where &lt;font color=&quot;#2b00fe&quot;&gt;&lt;i&gt;data_type&lt;/i&gt; &lt;/font&gt;must be same data type as that of the variable &lt;i&gt;&lt;font color=&quot;#2b00fe&quot;&gt;variable_name&lt;/font&gt;&lt;/i&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A reference variable does not create a new variable and so does not take space in memory. It’s simply another name given to a variable. You can understand it by taking the example of your actual name and all other names that your family members or friends have given you. Whatever be the name, it means only one individual in the real world. This is exactly the case with reference variables.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;background-color: #eeeeee; color: #0070c0; font-family: Georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Const&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The keyword &lt;b&gt;const&lt;/b&gt; can be added to the declaration of an object to make that object a constant rather than a variable. Thus, the value of that variable (called &lt;i&gt;named&lt;/i&gt; &lt;i&gt;constant&lt;/i&gt;) cannot be altered during the program run. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;General syntax :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 70px; overflow: scroll hidden; width: 400px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#2b00fe&quot;&gt;const data_type variable_name = value ;&lt;/font&gt;&lt;font color=&quot;#203864&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Note : A constant variable cannot remain uninitialized. It becomes mandatory to initialize the variable with a value at the time of declaration only. For example, the following code will give error :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;const int a;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;a=54;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;Read more &amp;gt;&amp;gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/data-types-are-means-to-identify-typeof.html&quot; target=&quot;_blank&quot;&gt;Primitive Datatypes&lt;/a&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/user-defined-datatypes-in-cc.html&quot; target=&quot;_blank&quot;&gt;User-defined Datatypes&amp;nbsp;&lt;/a&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Which topics you want an article on? Comment down on this post.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Do not stop here. Read all articles related to C++ &lt;a href=&quot;https://www.computercodec.com&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;&lt;font color=&quot;#ff0000&quot;&gt;here&lt;/font&gt;&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to contribute any article for the website, feel free to share it on &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. We will publish it on the website with your name.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Download the pdf form of this article &lt;a href=&quot;https://drive.google.com/file/d/1QSJfTwSr4vbzd1gGcIQR2nbs5e_1oLRx/view?usp=sharing&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;&lt;font color=&quot;#ff0000&quot;&gt;here&lt;/font&gt;&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/6120111234452245861/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=6120111234452245861&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/6120111234452245861'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/6120111234452245861'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/derived-datatypes.html' title='DERIVED DATATYPES IN C++'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-109144228641501314</id><published>2020-07-16T15:58:00.005+05:30</published><updated>2020-07-28T11:12:17.796+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CPP"/><category scheme="http://www.blogger.com/atom/ns#" term="Pointers"/><title type='text'>POINTERS AND CONST</title><content type='html'>&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Pointers are very interesting aspects of C++ language. If you master this concept, it is useful in all the other topics, specially data structures and algorithms. An interesting part though, is the interaction of pointers with &lt;b&gt;const&lt;/b&gt; keyword.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt; &lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;background-color: #cccccc; color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;&lt;h2&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;span style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #0070c0; font-family: Georgia, serif;&quot;&gt;POINTERS &lt;/span&gt;&lt;span style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; font-family: Georgia, serif;&quot;&gt;&amp;amp; &lt;/span&gt;&lt;span style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #0070c0; font-family: Georgia, serif;&quot;&gt;CONST&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 22pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h2&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;We have learnt to use &lt;/span&gt;&lt;b style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;const&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt; keyword for declaring symbolic constants. Using the same keyword, we can also declare &lt;/span&gt;&lt;i style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;constant pointers&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt; or &lt;/span&gt;&lt;i style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;pointers to constants&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A &lt;i&gt;constant pointer&lt;/i&gt; means that the pointer in consideration will always point to the same address. Its address (to which it is pointing to) cannot be modified. A &lt;i&gt;constant pointer&lt;/i&gt; must be initialized at time of creation. The address stored in that pointer at time of creation becomes its final value and it cannot be changed further. But the value at that location can be modified.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;General syntax&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;int * const iptr = new int ();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;See the use of keyword &lt;/span&gt;&lt;b style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;const&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt; and also that it is mandatory to initialize the constant pointer the moment it is created.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A &lt;i&gt;pointer to a constant&lt;/i&gt; refers to a pointer which is pointing to a symbolic constant. Using a &lt;i&gt;pointer to a constant&lt;/i&gt;, the constant value (to which this pointer is pointing to) can not be modified, however, the pointer can be made to point at some other address. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;General syntax :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;const int * iptr;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;iptr = new int ();&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;See the use of keyword &lt;b&gt;const&lt;/b&gt;. Unlike the previous case, a pointer to a constant need not be initialized at time of creation.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The following examples will make it clearer.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 730px; overflow: scroll hidden; width: 550px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;In the following lines, we shall declare four variables:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;a pointer called &lt;i&gt;&lt;span style=&quot;color: #1f3864; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;ptr&lt;/span&gt;&lt;/i&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;a constant pointer called &lt;i&gt;&lt;span style=&quot;color: #1f3864; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;cptr&lt;/span&gt;&lt;/i&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;a pointer named &lt;i&gt;&lt;span style=&quot;color: #1f3864; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;ptrC&lt;/span&gt;&lt;/i&gt;, pointing to constant&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;a constant pointer &lt;i&gt;&lt;span style=&quot;color: #1f3864; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;cptrC&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #1f3864; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt; &lt;/span&gt;pointing to a constant&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;int n = 44;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;// an int&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;int *ptr = &amp;amp;n;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;// a pointer to an int&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;++(*ptr);&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;// ok : increment int*ptr&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;int *const cptr = &amp;amp;n;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;// a const pointer to an int&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;++ (*cptr);&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;// ok: increments the contents&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;++ cptr;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;// illegal : pointer cptr is constant&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;const int kn = 88;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;// a const int&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;const int *ptrC = &amp;amp;kn;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;// a pointer to a const int&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;++ (*ptrC);&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;// illegal : int *ptrC is constant&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;++ ptrC;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;// ok : increments pointer ptrC&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;const int *const cptrC = &amp;amp;k;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;// a const pointer to a const int&lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;++(*cptrC);&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;// illegal : int *cptrC is const&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 200%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;++cptrC;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;// illegal : pointer cptrC is&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt;&quot;&gt;const&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want articles on a particular topic, comment down on this post.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Do not stop here. Read all articles related to C++ &lt;a href=&quot;https://www.computercodec.com&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;&lt;font color=&quot;#ff0000&quot;&gt;here&lt;/font&gt;&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to contribute any article for the website, feel free to share it on &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. We will publish it on the website with your name.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Download the pdf form of this article &lt;a href=&quot;https://drive.google.com/file/d/1Drn3alPMDac8doymvJVp7ytqwVVwm5gN/view?usp=sharing&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;&lt;font color=&quot;#ff0000&quot;&gt;here&lt;/font&gt;&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Related Topics :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/introduction-to-pointers.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Introduction to pointers&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/memory-allocation.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Static &amp;amp; Dynamic Allocation of memory&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/declaration-and-initialization-of.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Declaration &amp;amp; Initialization of pointers&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/pointer-arithmetic.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Pointer Arithmetic&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/dynamic-allocation-operators.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Dynamic Allocation Operators&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/memory-leak.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Memory Leaks&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/109144228641501314/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=109144228641501314&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/109144228641501314'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/109144228641501314'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/pointers-and-const.html' title='POINTERS AND CONST'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-8596069990668088093</id><published>2020-07-15T22:38:00.006+05:30</published><updated>2020-07-28T11:10:02.723+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CPP"/><category scheme="http://www.blogger.com/atom/ns#" term="Pointers"/><title type='text'>MEMORY LEAK</title><content type='html'>&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;h2 style=&quot;clear: both; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;b&gt;&lt;h2 style=&quot;background-color: #eeeeee; text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;What actually happens when we &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;delete a pointer &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;?&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;&lt;/b&gt;&lt;/h2&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A pointer is like any other variable when it comes to taking space in the memory. But instead of storing any values, it stores the memory address of the block it is pointing to. We know that by using &lt;b&gt;delete&lt;/b&gt; we can free the dynamically allocated memory. But the point to keep in mind is that the pointer itself is not dynamically created. It just holds the address of a dynamically created memory block. This means that the pointer cannot be deleted using &lt;b&gt;delete&lt;/b&gt; keyword, but the memory it’s pointing to can be deleted.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Look at the following code and then see the explanations :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 330px; overflow: scroll hidden; width: 350px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;#include&amp;lt;iostream&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;using namespace std;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;int main()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;int * iptr;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: red;&quot;&gt;// statement 1&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #1f3864; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;iptr = new int(25);&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;// statement 2&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;delete iptr;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;// statement 3&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;iptr = new int(12);&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;// statement 4&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;return 0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Statement 1 creates an integer pointer &lt;b&gt;iptr&lt;/b&gt;. This means the compiler provides a space of 8 bytes to &lt;b&gt;iptr&lt;/b&gt; somewhere in the memory. As it is not initialized, &lt;b&gt;iptr&lt;/b&gt;, at present, doesn’t hold any address.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Statement 2 is the dynamic allocation statement (allocation using &lt;b&gt;new&lt;/b&gt;). It creates a 4 bytes space in memory somewhere, stores the value 25 in it and then returns its address to &lt;b&gt;iptr&lt;/b&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Statement 3 uses the deallocation operator &lt;b&gt;delete&lt;/b&gt;. This does not delete the pointer &lt;b&gt;iptr&lt;/b&gt;, as it may seem from the code. The &lt;b&gt;delete&lt;/b&gt;operator can only deallocate the memory created through &lt;b&gt;new&lt;/b&gt;. By using the pointer, we simply specify the address to be deleted. So, after delete, &lt;b&gt;iptr&lt;/b&gt;is still present in the memory till its scope is over. This is shown in statement 4 where we use the pointer again to create another memory block using &lt;b&gt;new&lt;/b&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Also, when we delete a memory block, we are not talking of actually deleting the value stored in that block. The block is passed back to operating system for reuse, may be with the value still stored in it as a garbage value or clearing it. C++ does not make any guarantees about what will happen to the contents of deallocated memory. All we know is further dynamic creations of memory using new can utilize the deleted memory. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Dangling &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Pointers&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/h3&gt;&lt;div&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;C++ gives no clue as to what value is stored in the pointer after a &lt;/span&gt;&lt;b style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;delete&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt; statement. In most cases, the memory returned to the operating system will contain the same values it had before it was returned, and the pointer will be left pointing to the now deallocated memory.&lt;/span&gt;&lt;/div&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;A pointer that is pointing to a deallocated memory is called dangling pointer. Dereferencing or deleting a dangling pointer will lead to undefined behaviour.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Consider the following program : &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;script src=&quot;https://gist.github.com/Computer-Code-C/970ab531a36b45cea04a68ef9b9ddca3.js&quot;&gt;&lt;/script&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;In the above program, the value of 7 that was previously assigned to the allocated memory will probably still be there, but it’s possible that value at that memory address could have changed. It’s also possible the memory could be allocated to another application (or for the operating system’s own usage), and trying to access that memory will cause the operating system to shut the program down.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Few precautions that will avoid dangling pointer errors &lt;/span&gt;&lt;/b&gt;&lt;/h4&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#7f6000&quot;&gt;&lt;i&gt;&lt;b&gt;First&lt;/b&gt;&lt;/i&gt;&lt;/font&gt;, try to avoid having multiple pointers point to the same memory location. If this is not possible, always be clear about all the pointers accessing the same memory address.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;font color=&quot;#7f6000&quot;&gt;Second&lt;/font&gt;&lt;/i&gt;&lt;/b&gt;, when you delete a pointer, if that pointer is not going out of its scope immediately afterward, set its value as &lt;b&gt;NULL&lt;/b&gt; or &lt;b&gt;nullptr&lt;/b&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 18pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;Memory Leaks&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;span&gt;&lt;/span&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;There is no doubt about the fact that &lt;b&gt;new&lt;/b&gt; and &lt;b&gt;delete&lt;/b&gt;are very useful. But they have an associated problem that it is easy to forget to delete something that was previously allocated with &lt;b&gt;new&lt;/b&gt;, leaving an orphaned memory block – a block that is still allocated but which has nothing referencing it. This means that a memory block which was created is still in use but there’s no way to access it.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Here are the many reasons that might lead to memory leak :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: left;&quot;&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Forgetting to delete something that has been dynamically allocated (using new).&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;There can be a number of instances where you might forget to delete a memory allocated through &lt;b&gt;new&lt;/b&gt;. One such very common example is not deleting a dynamic memory created within a function. Look at the following code :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;void fun ()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int * iptr = new int;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;/*&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;full function body */&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;In the above function, the memory allocated through &lt;b&gt;new&lt;/b&gt; is never freed. Every time this function is called, a new memory is created which is later not deleted. These dynamically allocated memories have a dynamic scope and remain in memory for the entire program run. As a result, there is a continuous memory leak each time the function is called.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;text-indent: 0px;&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;b&gt;Failing to notice that code may bypass a delete statement under certain circumstances :&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Consider the code below :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;void fun()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int n; cin&amp;gt;&amp;gt;n;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int * iptr = new int;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;* iptr = n;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;if (* iptr &amp;lt; 6)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;cout &amp;lt;&amp;lt; “Less than 6” ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;else&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;delete iptr;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The above code is absolutely fine when it comes to syntax. Thus, the compiler shows no error. But if the user inputs a number less than 6, the control never actually passes to the &lt;b&gt;delete&lt;/b&gt;statement. So, every time the function is called and the user inputs a number less than 6, memory is lost.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Assigning a new address to a pointer which was already pointing to an allocated object.&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;See the code below :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;int main()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int a = 5;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int * iptr = new int;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;iptr = &amp;amp;a;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return 0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraphCxSpLast&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Here, &lt;i&gt;&lt;span style=&quot;color: #1f3864; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #1f3864; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt; &lt;/span&gt;is a static variable which has a certain address. A new memory is dynamically allocated which is being pointed to by the pointer &lt;b&gt;iptr&lt;/b&gt;. Now when the address of &lt;i&gt;&lt;span style=&quot;color: #1f3864; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #1f3864; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt; &lt;/span&gt;is assigned to &lt;b&gt;iptr&lt;/b&gt;, the address of the dynamically allocated memory is lost. There is no way to access that memory block. Thus, it results in a memory leak.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;What is the actual meaning of &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 16.0pt; line-height: 107%;&quot;&gt;memory leak &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;?&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;Every program at the time of compilation is sent to the compiler. The compiler reads the program and if it finds no errors it feeds the program to the main memory. Every program is given a certain amount of memory. This is the memory a program can use in its entire run. This memory includes spaces for global variables, local variables and functions; as well as the heap memory for dynamic allocations.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Whenever a new memory block is created using &lt;b&gt;new&lt;/b&gt;, a part of this heap is used. As heap is not infinite, it may happen that all the heap is used up and there is no space left for creation of a new memory block. To reduce this risk, it is important to avoid memory leaks. It is very important to free the memory that is no longer needed so that it may be used again by the program. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Whenever a memory address is leaked, the operating system still considers that memory block to be useful to the program. But once the memory is leaked, we have no way to get back its address in order to modify or delete it. So, that particular memory block becomes completely useless for rest of the program. This memory block remains in the memory until the program completely terminates.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;Which topics you want an article on? Comment down on this post.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Do not stop here. Read all articles related to C++ &lt;a href=&quot;https://www.computercodec.com&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;&lt;i&gt;here&lt;/i&gt;&lt;/font&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to contribute any article for the website, feel free to share it on &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. We will publish it on the website with your name.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Download the pdf form of this article &lt;a href=&quot;https://drive.google.com/file/d/1N567BGM07WSG6PVsQFlXAFiqLtPSlZ9G/view?usp=sharing&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;&lt;font color=&quot;#ff0000&quot;&gt;here&lt;/font&gt;&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Related Topics :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/introduction-to-pointers.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Introduction to pointers&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/memory-allocation.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Static &amp;amp; Dynamic memory allocation&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/declaration-and-initialization-of.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Declaration and Initialization of pointers&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/pointer-arithmetic.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Pointer Arithmetic&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/dynamic-allocation-operators.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Dynamic Allocation Operators&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/pointers-and-const.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Pointers &amp;amp; Constants&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #1f3864; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 128;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/8596069990668088093/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=8596069990668088093&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/8596069990668088093'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/8596069990668088093'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/memory-leak.html' title='MEMORY LEAK'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-6970191869659510120</id><published>2020-07-14T19:03:00.007+05:30</published><updated>2020-07-28T11:00:18.382+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CPP"/><category scheme="http://www.blogger.com/atom/ns#" term="Pointers"/><title type='text'>DYNAMIC ALLOCATION OPERATORS</title><content type='html'>&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Computer&#39;s memory is an interesting thing. The way it works is so complex yet highly interesting.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-IF-jcUb_1fk/Xw2piIcWx2I/AAAAAAAAAIo/MDfr5hnztwwESJXGGp4wg7FHKHjQ6ukBwCLcBGAsYHQ/s2048/Memory.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Dynamic Allocation Operators&quot; border=&quot;0&quot; data-original-height=&quot;1379&quot; data-original-width=&quot;2048&quot; height=&quot;336&quot; src=&quot;https://1.bp.blogspot.com/-IF-jcUb_1fk/Xw2piIcWx2I/AAAAAAAAAIo/MDfr5hnztwwESJXGGp4wg7FHKHjQ6ukBwCLcBGAsYHQ/w500-h336/Memory.jpg&quot; title=&quot;Dynamic Allocation Operators&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Pointers provide necessary support for C++’s powerful dynamic memory allocation system. As you know, dynamic allocation is the means by which a program can obtain memory during runtime. The global and the local variables are allocated memory during compile-time. However, you cannot add any global or local variables during runtime. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;What if, your program needs to use variable amount of memory space? In such case, you would need to allocate memory during runtime, as and when required. This can be done using the dynamic allocation operators.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;h2&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;span style=&quot;color: #2f5597; font-family: &amp;quot;Georgia&amp;quot;,serif;&quot;&gt;DYNAMIC ALLOCATION OPERATORS &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,serif;&quot;&gt;IN C++&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 22pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h2&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;C++ dynamic allocation routines obtain memory for allocation from the free store (the pool of unallocated heap memory provided to the program). C++ defines two unary operators &lt;b&gt;new&lt;/b&gt; and &lt;b&gt;delete&lt;/b&gt; that perform the task of allocating and freeing (deallocating) memory during runtime. In addition to these two operators, the C language functions &lt;b&gt;malloc()&lt;/b&gt;and &lt;b&gt;calloc()&lt;/b&gt; are also defined in C++. Since all these operate on the free memory, they are collectively called &lt;i&gt;free store operators &amp;amp; functions&lt;/i&gt;. We will focus on &lt;b&gt;new&lt;/b&gt; and &lt;b&gt;delete&lt;/b&gt;. However, here’s a brief about &lt;b&gt;malloc()&lt;/b&gt;and &lt;b&gt;calloc()&lt;/b&gt; :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;background-color: #eeeeee; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;malloc()&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;&lt;div&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;It is a C based dynamic memory allocator used to allocate memory from heap region during runtime. It is included in the header &lt;span style=&quot;color: #843c0c; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #843C0C; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent2; mso-themecolor: accent2; mso-themeshade: 128;&quot;&gt;cstdlib&lt;/span&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The general syntax for malloc() is :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 250px; overflow: scroll hidden; width: 580px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2e75b6; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2e75b6; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;pointer_name = (* data_type) malloc (size) ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2e75b6; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2e75b6; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;pointer_name &lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #2e75b6; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;is a pointer to type &lt;i&gt;&lt;span style=&quot;color: #2e75b6; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;data_type&lt;/span&gt;&lt;/i&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2e75b6; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;data_type&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #2e75b6; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;is the type of values you want to store in the memory.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2e75b6; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;size&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #2e75b6; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;is the total number of memory blocks of type &lt;i&gt;&lt;span style=&quot;color: #2e75b6; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;data_type&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #2e75b6; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt; &lt;/span&gt;you want.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;malloc()&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; is generally used to create dynamic arrays. It searches the memory for a suitable address where the array of proper size can be created and returns the base address of the first memory block. If it fails to allocate memory, it returns &lt;b&gt;NULL&lt;/b&gt;. It is important to note that &lt;b&gt;malloc()&lt;/b&gt; only allocates memory but does not initialize it. Therefore, all the allocated memory contains garbage value.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;background-color: #eeeeee; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;calloc()&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;div&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;It is also an inbuilt function included in the header file &lt;span style=&quot;color: #7f6000; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #7F6000; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent4; mso-themecolor: accent4; mso-themeshade: 128;&quot;&gt;cstdlib&lt;/span&gt;. It is used to allocate memory from heap region during runtime.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The general syntax is :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 280px; overflow: scroll hidden; width: 650px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;pointer_name = (*data_type) calloc (no_of_blocks , size_of_each_block) ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;pointer_name&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;is a pointer of type &lt;i&gt;&lt;span style=&quot;color: #1f4e79; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;data_type&lt;/span&gt;&lt;/i&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;data_type&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;is the type of values to be stored in the memory&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;no_of_blocks&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; is an integer denoting the number of continuous memory blocks required&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;size_of_each_block&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; denotes size of each memory block in bytes.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If &lt;b&gt;calloc()&lt;/b&gt; fails to allocate memory, it returns a &lt;b&gt;NULL&lt;/b&gt;. Also, unlike &lt;b&gt;malloc()&lt;/b&gt;, it allocates and also initializes the memory blocks with legal default value depending on the &lt;i&gt;&lt;span style=&quot;color: #1f4e79; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;data_type&lt;/span&gt;&lt;/i&gt;.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Learn all about &lt;b&gt;malloc()&lt;/b&gt; and &lt;b&gt;calloc()&lt;/b&gt; here.&lt;i&gt;&lt;font color=&quot;#c6dafc&quot;&gt; &lt;/font&gt;&lt;font color=&quot;#ba67c8&quot;&gt;(link will be ready shortly.)&lt;/font&gt;&lt;/i&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: windowtext; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 16.0pt; line-height: 107%;&quot;&gt;The ‘&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 16.0pt; line-height: 107%;&quot;&gt;new’ &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;color: windowtext; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 16.0pt; line-height: 107%;&quot;&gt;operator&lt;/span&gt;&lt;span style=&quot;mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The operator &lt;b&gt;new&lt;/b&gt; can be used to create objects of all kinds, including user defined data types such as class or structures.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The general syntax for object creation using new :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 100px; overflow: scroll hidden; width: 350px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;pointer_name = new data_type ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;where &lt;i&gt;&lt;span style=&quot;color: #1f4e79; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;data_type&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #1f4e79; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt; &lt;/span&gt;is any valid C++ data type and the &lt;i&gt;&lt;span style=&quot;color: #1f4e79; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;pointer_name&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #1f4e79; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt; &lt;/span&gt;is a pointer variable of type &lt;i&gt;&lt;span style=&quot;color: #1f4e79; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;data_type&lt;/span&gt;&lt;/i&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The operator &lt;b&gt;new&lt;/b&gt; will allocate memory of size equal&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;to the size of given &lt;i&gt;&lt;span style=&quot;color: #1f4e79; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;data_type&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #1f4e79; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt; &lt;/span&gt;and return a pointer (of that specified &lt;i&gt;&lt;span style=&quot;color: #1f4e79; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;data_type&lt;/span&gt;&lt;/i&gt;) pointing to the base address of the newly allocated area.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;For instance, the following code snippet&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;iptr = new int ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;This will allocate sufficient amount of memory from free storage to hold a value of specified &lt;/span&gt;&lt;i style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;color: #1f4e79; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;data_type&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;and store the starting address of the newly allocated memory in &lt;/span&gt;&lt;b style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;iptr&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;. Since new is allocating the memory for &lt;/span&gt;&lt;i style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;int&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt; type, the receiving pointer must be of &lt;/span&gt;&lt;i style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;int&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt; type i.e. &lt;/span&gt;&lt;b style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;iptr&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt; must be an &lt;/span&gt;&lt;i style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;int&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;pointer.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Declaration and allocation can be combined in one statement as :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;int * iptr = new int ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Once a pointer points to a legal memory, we can access that memory using the “value at” operator &lt;b&gt;*&lt;/b&gt; of pointers as shown below :&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;*iptr = 12 ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The above assignment will assign the integer value 12 into the newly allocated memory block. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;This assignment can also be done at the time of allocation as :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 100px; overflow: scroll hidden; width: 350px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;pointer_name = new data_type (value);&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;where &lt;i&gt;&lt;span style=&quot;color: #1f4e79; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;value&lt;/span&gt;&lt;/i&gt; is the initial value to be stored in the newly allocated memory. The value must also be of the specified &lt;i&gt;&lt;span style=&quot;color: #1f4e79; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;data_type&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #1f4e79; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt; &lt;/span&gt;type .&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Consider the following statements&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 130px; overflow: scroll hidden; width: 350px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#3367d6&quot;&gt;&lt;i&gt;char *cptr = new char (‘a’);&lt;/i&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;// statement 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;font color=&quot;#3367d6&quot;&gt;float *fptr = new float (17.33);&lt;/font&gt;&lt;/i&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&lt;i&gt;&lt;font color=&quot;#4285f4&quot;&gt;&amp;nbsp;&lt;/font&gt;&lt;/i&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;// statement 2&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The above given statement 1 will allocate sufficient memory from free pool to hold a character, then store ‘a’ inside this newly allocated memory, and make character pointer &lt;b&gt;cptr&lt;/b&gt; point to this memory address.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Similarly, the statement 2 will allocate sufficient memory from free pool to hold a floating point value, then store 17.33 inside that newly allocated memory, and make float pointer &lt;b&gt;fptr&lt;/b&gt; point to that memory address.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;h3&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: windowtext; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 16.0pt; line-height: 107%;&quot;&gt;Creating &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;color: #1f4e79; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 16.0pt; line-height: 107%;&quot;&gt;Dynamic Array&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 14pt; line-height: 107%;&quot;&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The operator &lt;b&gt;new&lt;/b&gt; can also allocate memory for user defined types like structures and classes as well as for derived data types like arrays. To allocate memory for a one-dimensional array, new may be used in the following form :&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 100px; overflow: scroll hidden; width: 350px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;pointer_name = new data_type [size] ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;where &lt;i&gt;&lt;span style=&quot;color: #1f4e79; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;size&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #1f4e79; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt; &lt;/span&gt;is an integer representing the number of elements in the array.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;For instance, to allocate memory for an array having 10 integer elements we need to use new as :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;int * a = new int [10] ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;This will create an array of size 10 with &lt;i&gt;&lt;span style=&quot;color: #1f4e79; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #1f4e79; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt; &lt;/span&gt;pointing to the base address of the first element. Now all these array elements can be accessed as &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;a[0] for the first element&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;a[1] for the second element&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;a[2] for the third element….and so on.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Before C++11 standards, no initializations were possible at the time of creation of array but now we can also initialize the array with some initial values as&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 80px; overflow: scroll hidden; width: 350px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;int * a = new int [5] {2, 5, 3, 8, 10} ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;This creates an array a with a[0] = 2, a[1] = 5 and so on.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The &lt;b&gt;new&lt;/b&gt; operator does not initialize the newly created memory unless explicitly forced by the programmer. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;See the following code and its output :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 350px; overflow: scroll hidden; width: 250px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;#include&amp;lt;iostream&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;using namespace std;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;int main()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;int * a= new int;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;cout&amp;lt;&amp;lt; *a;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;return 0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;b&gt;Output :&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;font color=&quot;#7f6000&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;1448160&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The output is certainly a garbage value which is at present stored in the newly created memory.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Now see this code :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 350px; overflow: scroll hidden; width: 450px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;#include&amp;lt;iostream&amp;gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;using namespace std;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;int main()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;int * a= new int ();&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;// &lt;font color=&quot;#ff0000&quot;&gt;explicitly forcing initialization &lt;/font&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;cout&amp;lt;&amp;lt; *a;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;return 0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;b&gt;Output :&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#783f04&quot;&gt;0&lt;/font&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;As evident from above examples, to initialize memory allocated through new, the program needs to force this initialization explicitly. Also, arrays can be initialized with legal default values in the same way.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;int * a= new int [5]();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;This code creates an array of 5 elements and initializes the elements with the default value of int type, i.e. 0.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;In older versions of C++, it was not possible to create a static array of variable size. For example,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;int n;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;cin&amp;gt;&amp;gt;n;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;int a[n];&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The above code would generate error as a variable has been passed as the size of array. But the new standards allow such creations and so the use of dynamic creation of arrays has now reduced.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;An important note :&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Since the program’s free store (heap) is not infinite, during the course of program execution, it may become exhausted i.e. the program may run out of heap memory and more memory may not be allocated further. To be on the safer side in such a situation, whenever you allocate memory, you must check the value returned by &lt;b&gt;new&lt;/b&gt; operator to make sure it is not &lt;b&gt;NULL&lt;/b&gt; or zero before using the pointer. Using a &lt;b&gt;NULL&lt;/b&gt; pointer will almost certainly crash the system.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;int *val = new int;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;if(val)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;&amp;nbsp;&amp;nbsp; *val=7;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;else&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;”Out of memory !!” ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Even if, the initial value is given in the expression, initialization is done only if the value returned by operator &lt;b&gt;new&lt;/b&gt; is nonzero (or non-&lt;b&gt;NULL&lt;/b&gt;). If the value returned by &lt;b&gt;new&lt;/b&gt; is 0 (&lt;b&gt;NULL&lt;/b&gt;), the value of entire expression becomes 0 (i.e. false).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;The ‘delete’ operator &lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;&lt;div&gt;&lt;b&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;When an object, created through &lt;b&gt;new&lt;/b&gt;, is no longer needed, it must be destroyed so that the memory space occupied by it may be released for reuse. This can be done with the help of &lt;b&gt;delete&lt;/b&gt; operator, the memory deallocation operator of C++.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The general form of delete is as shown below :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;delete pointer_name ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;where&amp;nbsp;&lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-ansi-language: EN-IN; mso-bidi-font-family: Mangal; mso-bidi-language: HI; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;pointer_name&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;is the pointer that points to a data object created through new.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;For deleting dynamic arrays created by new, we use the following syntax :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #1f4e79; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1F4E79; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 128;&quot;&gt;delete [] pointer_name ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;                                   &lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Note : When we apply &lt;b&gt;delete&lt;/b&gt; to a pointer, it essentially deletes that memory which the pointer is pointing to. It does not mean that the pointer itself is deleted. Any pointer is first a static variable itself and it remains in memory for its entire scope.&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you like this article share with your friends.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Do not stop here. Read all articles related to C++ &lt;a href=&quot;https://www.computercodec.com/search/label/CPP?&amp;amp;max-results=9&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#b51200&quot;&gt;&lt;i&gt;here&lt;/i&gt;&lt;/font&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you have any doubts, queries or suggestions for the website, please comment on this post.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to contribute any article for the website, feel free to share it on &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. We will publish it on the website with your name.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Download the pdf form of this article &lt;a href=&quot;https://drive.google.com/file/d/1RU7BfmS64K7OK0LRt7LgUIBO2zZPdXpY/view?usp=sharing&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#b51200&quot;&gt;&lt;i&gt;here&lt;/i&gt;&lt;/font&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Related Topics :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/introduction-to-pointers.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#b51200&quot;&gt;Introduction to Pointers&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/memory-allocation.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#b51200&quot;&gt;Static &amp;amp; Dynamic Memory Allocations&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/declaration-and-initialization-of.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#b51200&quot;&gt;Declaration and Initialization of pointers&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/pointer-arithmetic.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#b51200&quot;&gt;Pointer Arithmetic&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/memory-leak.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Memory Leaks&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/pointers-and-const.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Pointers &amp;amp; Constants&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/6970191869659510120/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=6970191869659510120&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/6970191869659510120'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/6970191869659510120'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/dynamic-allocation-operators.html' title='DYNAMIC ALLOCATION OPERATORS'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-1686118039658044800</id><published>2020-07-13T23:54:00.005+05:30</published><updated>2020-07-28T09:59:49.028+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CPP"/><category scheme="http://www.blogger.com/atom/ns#" term="Pointers"/><title type='text'>POINTER ARITHMETIC</title><content type='html'>&lt;p class=&quot;MsoNormal&quot;&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;In this article we will see which operators work with pointers and how they operate on them. The study of this topic is termed as &lt;b&gt;Pointer Arithmetic&lt;/b&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h2&gt;&lt;span style=&quot;background-color: #eeeeee; font-family: Georgia, serif;&quot;&gt;POINTER &lt;span style=&quot;color: #0070c0;&quot;&gt;ARITHMETIC&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 22.0pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h2&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;Before we start discussing about the arithmetic of operators, it is important that we understand how pointers store memory address. As we know, pointers are variables that hold memory address of other variables, any modification in the value of a pointer means changing the memory address to which it is pointing.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;How does &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 16.0pt; line-height: 107%;&quot;&gt;Computer Memory &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;look like?&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;Visualize the computer memory as a table consisting of number of rows &amp;amp; columns depending on the memory capacities of the computer. Each of the boxes formed by the intersection of rows and columns has a size of 1 byte. Now each of these boxes have a memory address which are sequential (say 1,2,3, ……. and so on).&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-TipQUlHLPLo/XwykrboQnCI/AAAAAAAAAH8/Snwo9D0rNOck2bGX83Hj_sGA6nQfbH0vACLcBGAsYHQ/s791/memory.png&quot; style=&quot;clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Pointer Arithmetic&quot; border=&quot;0&quot; data-original-height=&quot;556&quot; data-original-width=&quot;791&quot; height=&quot;445&quot; src=&quot;https://1.bp.blogspot.com/-TipQUlHLPLo/XwykrboQnCI/AAAAAAAAAH8/Snwo9D0rNOck2bGX83Hj_sGA6nQfbH0vACLcBGAsYHQ/w633-h445/memory.png&quot; title=&quot;Pointer Arithmetic&quot; width=&quot;633&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;i&gt;A general representation of computer memory&lt;/i&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;Now, when a variable is created, a number of these sequential memory boxes merge to give rise to a new box of required size. For instance,&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Suppose we create an integer variable.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2f5597; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2F5597; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent1; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;int a;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;As soon as the compiler reads this variable, it merges 4 sequential memory boxes to give rise to a new memory box of size 4 bytes (i.e. size of int variable). This new memory box is given the same address as its first constituting box. Suppose &lt;span style=&quot;color: #2f5597; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2F5597; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent1; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;&lt;b&gt;a &lt;/b&gt;&lt;/span&gt;is at address 117.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;See the figure below to understand how the memory looks now :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-W4IiCGr60dY/Xwyk8a9k8jI/AAAAAAAAAIE/e_eNdE17p0c65_VEA_WJ-07iI1mAnG2kACLcBGAsYHQ/s791/variable.png&quot; style=&quot;clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Pointer Arithmetic&quot; border=&quot;0&quot; data-original-height=&quot;556&quot; data-original-width=&quot;791&quot; height=&quot;445&quot; src=&quot;https://1.bp.blogspot.com/-W4IiCGr60dY/Xwyk8a9k8jI/AAAAAAAAAIE/e_eNdE17p0c65_VEA_WJ-07iI1mAnG2kACLcBGAsYHQ/w633-h445/variable.png&quot; title=&quot;Pointer Arithmetic&quot; width=&quot;633&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;i&gt;Variable created at Base address 117&lt;/i&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;i style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;&lt;br /&gt;&lt;/i&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;i style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;Note that the address of variable is saved as 117 (i.e. the starting position box). &lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;The location of first box is termed as &lt;/span&gt;&lt;b style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;Base Address &lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;for that variable.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Similarly, a char variable takes just 1 box(1 byte), a float variable takes 4 boxes, a double variable takes 8 boxes and so on!&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 16.0pt; line-height: 107%;&quot;&gt;Operators &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;working on pointers&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;Only two arithmetic operations, addition and subtraction, may be performed on a pointer. When you add 1 to a pointer, you are actually adding the size of whatever the pointer is pointing at. That is, each time a pointer is incremented by 1, it points to the memory location of the next element of its base type. To understand it more clearly, let us take the previous figure.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Now consider the following code :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 160px; overflow: auto hidden; width: 310px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;int * iptr;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;// create an &lt;i&gt;int&lt;/i&gt; pointer&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;iptr = &amp;amp; a;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;// make &lt;b&gt;iptr&lt;/b&gt; point to &lt;b&gt;a&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;iptr++;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;// increment &lt;b&gt;iptr&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Let’s visualize and discuss every step:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Statement 1&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; :&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;It creates an integer pointer (i.e. a pointer pointing to an integer). As its not initialized, at present it is not pointing at anything. But being a variable, it does take space in the memory (8 bytes). Say it’s address is 100.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Look at the memory now.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-WHxiCVXrYD0/XwylY1g8AII/AAAAAAAAAIM/j3LHA7SZYMILjUXFjpHQwON3ma3dS3PfgCLcBGAsYHQ/s791/pointer%2Bvariable.png&quot; style=&quot;clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Pointer Arithmetic&quot; border=&quot;0&quot; data-original-height=&quot;556&quot; data-original-width=&quot;791&quot; height=&quot;445&quot; src=&quot;https://1.bp.blogspot.com/-WHxiCVXrYD0/XwylY1g8AII/AAAAAAAAAIM/j3LHA7SZYMILjUXFjpHQwON3ma3dS3PfgCLcBGAsYHQ/w633-h445/pointer%2Bvariable.png&quot; title=&quot;Pointer Arithmetic&quot; width=&quot;633&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;i&gt;Pointer variable created at Base Address 100&amp;nbsp;&lt;/i&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Statement 2&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; : It stores the address of variable ‘&lt;b&gt;a&lt;/b&gt;’ in the pointer &lt;b&gt;iptr&lt;/b&gt;.&lt;/span&gt;&lt;/p&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-QyaQlADvJ48/XwylvvQUuII/AAAAAAAAAIU/UYX4-RcJtHw5sarbsd6cYNf_Hc03_flZwCLcBGAsYHQ/s791/statement%2B2.png&quot; style=&quot;clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Pointer Arithmetic&quot; border=&quot;0&quot; data-original-height=&quot;556&quot; data-original-width=&quot;791&quot; height=&quot;445&quot; src=&quot;https://1.bp.blogspot.com/-QyaQlADvJ48/XwylvvQUuII/AAAAAAAAAIU/UYX4-RcJtHw5sarbsd6cYNf_Hc03_flZwCLcBGAsYHQ/w633-h445/statement%2B2.png&quot; title=&quot;Pointer Arithmetic&quot; width=&quot;633&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;i&gt;Base address of variable stored in pointer&lt;/i&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Statement 3&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; : Now this is the important step. What happens when the pointer value is incremented? As one might think, the value stored in &lt;b&gt;iptr&lt;/b&gt; is increased by one. So, it should point to the next memory block. But, after 117 the next three addresses (viz. 118, 119 &amp;amp; 120) are not free. They are integrated together to form the variable &lt;b&gt;a&lt;/b&gt;. So, the pointer sees 121 as the next memory block. Being an &lt;i&gt;int&lt;/i&gt; type pointer, &lt;b&gt;iptr&lt;/b&gt; readily converts the box at 121 into an integer by including the next 3 boxes.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;So, the value stored in &lt;b&gt;iptr&lt;/b&gt; is 121 and the memory looks like the figure below:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-X8Ik6dTeAKs/XwymAOiJ8xI/AAAAAAAAAIY/8sSQhZZUhAsIS6jzJrCAh3cKOKAtqBeNwCLcBGAsYHQ/s791/statement%2B3.png&quot; style=&quot;clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Pointer Arithmetic&quot; border=&quot;0&quot; data-original-height=&quot;556&quot; data-original-width=&quot;791&quot; height=&quot;445&quot; src=&quot;https://1.bp.blogspot.com/-X8Ik6dTeAKs/XwymAOiJ8xI/AAAAAAAAAIY/8sSQhZZUhAsIS6jzJrCAh3cKOKAtqBeNwCLcBGAsYHQ/w633-h445/statement%2B3.png&quot; title=&quot;Pointer Arithmetic&quot; width=&quot;633&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;i&gt;Memory after incrementation&lt;/i&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;I hope the concepts are clear now. Also decrement operator works the similar way. Suppose an int pointer holds the address 100 then after decrementing once, it will point at 96 and not 99.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;When a character pointer is incremented, its value increase by one or whatever the size of character on your machine; an integer pointer when incremented, its value increases by four (or whatever the size of integer on your machine); a float pointer when incremented, its value increases by four; and so on.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2f5597; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2F5597; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent1; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;In pointer arithmetic, all pointers increase and decrease by the length of the data type they point to.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Not just 1 but other integers may also be added to or subtracted from pointers. When you give the following expression:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2f5597; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2F5597; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent1; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2f5597; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2F5597; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent1; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;iptr += 2;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;it will make &lt;b&gt;iptr&lt;/b&gt; point to the 2&lt;sup&gt;nd&lt;/sup&gt; element of &lt;b&gt;iptr&lt;/b&gt;’s type (&lt;i&gt;int&lt;/i&gt; here) beyond the one it is currently pointing to. That is, if &lt;b&gt;iptr&lt;/b&gt; is currently pointing to memory location 1001, then &lt;b&gt;iptr&lt;/b&gt; +2 will make it point to address 1009, which is the result of 1001 + size of (2 integers)=1001 + 8 = 1009.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Other arithmetic operations like multiplication and division are &lt;b&gt;not&lt;/b&gt; permitted on pointers. Also, you may not add two pointers and &lt;i&gt;only integers can be added or subtracted from pointers&lt;/i&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;When we say that it is a char pointer or int pointer or float pointer, we mean to say that this pointer is holding address of a memory location that can hold char, or int or float value respectively. However, for char value, the memory location is 1 byte wide; for int it is 4 bytes; and 4 bytes for float. Whatever may be the pointer type, the pointer holds the address of the very first byte (known as the &lt;b&gt;Base Address&lt;/b&gt;) of the memory location it points to.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;Do &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 16.0pt; line-height: 107%;&quot;&gt;relational operators &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;act on pointers?&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;Yes, the relational operators &lt;/span&gt;&lt;b style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;==&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt; and &lt;/span&gt;&lt;b style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;!=&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt; act on pointers. These operators can be used to check the pointer value against some other values, like checking if the pointer points to &lt;/span&gt;&lt;b style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;NULL&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt; or not.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;See the following code for example :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 400px; overflow: scroll hidden; width: 450px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2f5597; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2F5597; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent1; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;#include&amp;lt;iostream&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2f5597; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2F5597; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent1; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;using namespace std;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2f5597; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2F5597; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent1; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;int main()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2f5597; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2F5597; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent1; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2f5597; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2F5597; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent1; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;int * iptr = NULL;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #2f5597; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2F5597; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent1; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;// initializing iptr with NULL&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2f5597; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2F5597; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent1; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;if(iptr == NULL)&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #2f5597; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2F5597; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent1; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;// Using relational operator&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2f5597; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2F5597; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent1; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;cout &amp;lt;&amp;lt; “It is NULL ”;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #2f5597; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2F5597; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent1; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;// Output statement&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2f5597; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2F5597; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent1; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;return 0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2f5597; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2F5597; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent1; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Output:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: #002060; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;It is NULL&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Here another thing can be understood that dereferencing a &lt;b&gt;NULL&lt;/b&gt; pointer causes error. This is due to the fact that a &lt;b&gt;NULL&lt;/b&gt; pointer is not pointing at any valid memory address. So, dereferencing it doesn’t mean anything logical.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Do not stop here. Read all articles related to C++ &lt;a href=&quot;https://www.computercodec.com/search/label/CPP?&amp;amp;max-results=9&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#b51200&quot;&gt;here&lt;/font&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you have any doubts, queries or suggestions for the website, please comment on this post.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to contribute any article for the website, feel free to share it on &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. We will publish it on the website with your name.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Download the pdf form of this article &lt;a href=&quot;https://drive.google.com/file/d/1z2giADB8gJIfUopUUbdl05lMplIGJgax/view?usp=sharing&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;&lt;font color=&quot;#ff0000&quot;&gt;here&lt;/font&gt;&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Related Topics :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/introduction-to-pointers.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Introduction to pointers&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/memory-allocation.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Static and Dynamic Allocation of memory&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/declaration-and-initialization-of.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Declaration and Initialization of pointers&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/dynamic-allocation-operators.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Dynamic Allocation Operators&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/memory-leak.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Memory Leaks&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 18.6667px;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/pointers-and-const.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Pointers &amp;amp; Constants&lt;/font&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/1686118039658044800/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=1686118039658044800&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/1686118039658044800'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/1686118039658044800'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/pointer-arithmetic.html' title='POINTER ARITHMETIC'/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1963654198922371192.post-2416553435883137759</id><published>2020-07-12T23:18:00.027+05:30</published><updated>2020-07-28T09:54:32.031+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CPP"/><category scheme="http://www.blogger.com/atom/ns#" term="Pointers"/><title type='text'>DECLARATION AND INITIALIZATION OF POINTERS   </title><content type='html'>&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;In this article we will look in details of &lt;b&gt;declaration&amp;nbsp;&lt;/b&gt;and &lt;b&gt;initialization&amp;nbsp;&lt;/b&gt;of a pointer variable. As we know, pointers are one of the most important and strongest features of C++, it becomes necessary to know about them in details.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h2&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;span style=&quot;color: #0070c0; font-family: &amp;quot;Georgia&amp;quot;,serif;&quot;&gt;DECLARATION &lt;/span&gt;&lt;span style=&quot;font-family: Georgia, serif;&quot;&gt;AND &lt;/span&gt;&lt;span style=&quot;color: #0070c0; font-family: &amp;quot;Georgia&amp;quot;,serif;&quot;&gt;INITIALIZATION &lt;/span&gt;&lt;span style=&quot;font-family: Georgia, serif;&quot;&gt;OF POINTERS&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 22pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h2&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Pointer variables are declared like normal variables except for the addition of the unary &lt;b&gt;* character&lt;/b&gt;. The general form of a pointer declaration is as follows :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: left;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2f5496; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;data_type&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;*var_name;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2f5496; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Here &lt;i&gt;data_type&lt;/i&gt; is any valid C++ data type and &lt;i&gt;var_name &lt;/i&gt;is the name of the pointer variable. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;See some examples of declarations :&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 150px; overflow: scroll hidden; width: 500px;&quot;&gt;&lt;p style=&quot;width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2f5496; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;int * iptr;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #2f5496; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;// creates an integer pointer iptr&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2f5496; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;char * cptr;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #2f5496; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;// creates a character pointer cptr&lt;/font&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2f5496; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;float * fptr;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #2f5496; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;// creates a float pointer fptr&lt;/font&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;When we say that &lt;b&gt;iptr&lt;/b&gt; is an integer pointer, it mea&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;ns that the memory location being pointed to by the pointer can hold only integers values. In other words, it can be stated that &lt;/span&gt;&lt;b style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;iptr &lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;is a pointer to integer. Similarly, in the above given declarations, &lt;/span&gt;&lt;b style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;cptr &lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;is a pointer to a character and &lt;/span&gt;&lt;b style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;fptr &lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;is a pointer to floating point value.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Thus, the base type of the pointer defines what type of variables the pointer can point to.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Note: Technically, any kind of pointer can point anywhere in the memory. However, all pointer arithmetic is done relative to its base type, so it is important to declare the pointers correctly. This is the reason why compiler shows error when we try to assign variable of a different data type to a pointer of different base type.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;How much &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 16.0pt; line-height: 107%;&quot;&gt;space &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;does a pointer take?&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;As a pointer is also a proper data type (derived), it takes space in the memory just like any primitive data type. But the size of a pointer variable is not dependent on its base type. &lt;/span&gt;&lt;span style=&quot;color: #2f5496; font-family: georgia, serif; font-size: 14pt; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;Every pointer, irrespective of its base type, takes 8 bytes of space in memory(64 bit system)&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;h3&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;Does an &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 16.0pt; line-height: 107%;&quot;&gt;empty pointer &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;take space?&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;Well, yes. As soon as a pointer is created, it is given an 8 bytes space in the memory. When we assign the address of another variable to it, it simply stores the address value. It is similar to creating, say an &lt;/span&gt;&lt;i style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;color: #2f5496; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;int&lt;/span&gt; &lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;variable and then storing a value to it. Even if no value was assigned to that &lt;/span&gt;&lt;i style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;color: #2f5496; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;int&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;variable, it would still take up the space. &lt;/span&gt;&lt;b style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;&lt;span style=&quot;color: #2f5496; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;The memory allocating statement is the declaration and not initialization&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 16.0pt; line-height: 107%;&quot;&gt;Special Operators &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;for Pointer handling&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;Two special operators &lt;/span&gt;&lt;b style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;*&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt; and &lt;/span&gt;&lt;b style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;&amp;amp;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt; are used with pointers.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The &lt;b&gt;&amp;amp;&lt;/b&gt; is a unary operator that returns the memory address of its operand.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;For example,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;  &lt;div style=&quot;border: 1px solid white; height: 130px; overflow: auto hidden; width: 350px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: left; width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2f5496; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;int i = 25; &lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #2f5496; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;// declares an&lt;i&gt; int&lt;/i&gt; variable &lt;b&gt;i&lt;/b&gt;&lt;/font&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: left; width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2f5496; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;int * iptr;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;// declares an&lt;i&gt; int&lt;/i&gt; pointer &lt;b&gt;iptr&lt;/b&gt;&lt;/font&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: left; width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2f5496; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;iptr = &amp;amp;i&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=&quot;#ff0000&quot;&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#ff0000&quot;&gt;// stores the memory address of &lt;b&gt;i&lt;/b&gt; into &lt;/font&gt;&lt;b&gt;&lt;font color=&quot;#ff0000&quot;&gt;iptr&lt;/font&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The above given assignment statement stores the memory address if &lt;b&gt;i&lt;/b&gt; (&lt;b&gt;&amp;amp;&lt;/b&gt; returns address of its operand) into &lt;b&gt;iptr&lt;/b&gt; so that &lt;b&gt;iptr&lt;/b&gt; is now pointing to the memory location of &lt;b&gt;i&lt;/b&gt;. The expression &lt;b&gt;&amp;amp;i&lt;/b&gt; will return an &lt;i&gt;int&lt;/i&gt; pointer value because &lt;b&gt;i &lt;/b&gt;is integer type. Similarly, if &lt;b&gt;ch&lt;/b&gt; is a character type variable, &lt;b&gt;&amp;amp;ch&lt;/b&gt;will return a character pointer.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;To understand the above assignment better, assume that variable &lt;b&gt;i&lt;/b&gt; uses memory location 1000 to store its value. And the value stored in &lt;b&gt;i&lt;/b&gt; is 25, then after the statement &lt;i&gt;&lt;span style=&quot;color: #2f5496; mso-themecolor: accent1; mso-themeshade: 191;&quot;&gt;iptr = &amp;amp;i&lt;/span&gt;&lt;/i&gt;, &lt;b&gt;iptr&lt;/b&gt;will have the value 1000.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Following figure illustrates this concept.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-XJoB7Nr8Ok0/XwtMEpK8TXI/AAAAAAAAAHw/608ZoZfct-0SoF5UGyC9MdeF0BvFt0MXQCLcBGAsYHQ/s1971/b79b5156-2321-44d9-b725-548e8dda7553.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;DECLARATION AND INITIALIZATION OF POINTERS&quot; border=&quot;0&quot; data-original-height=&quot;1424&quot; data-original-width=&quot;1971&quot; height=&quot;466&quot; src=&quot;https://1.bp.blogspot.com/-XJoB7Nr8Ok0/XwtMEpK8TXI/AAAAAAAAAHw/608ZoZfct-0SoF5UGyC9MdeF0BvFt0MXQCLcBGAsYHQ/w646-h466/b79b5156-2321-44d9-b725-548e8dda7553.png&quot; title=&quot;DECLARATION AND INITIALIZATION OF POINTERS&quot; width=&quot;646&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 14pt;&quot;&gt;The second pointer operator,&amp;nbsp;&lt;b&gt;*&lt;/b&gt;, does the reverse of&amp;nbsp;&lt;b&gt;&amp;amp;&lt;/b&gt;. The unary operator&amp;nbsp;&lt;b&gt;*&lt;/b&gt;&amp;nbsp;returns the value of the variable located at the address following it.&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;, serif; font-size: 13.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 14pt;&quot;&gt;For example, if&amp;nbsp;&lt;b&gt;iptr&lt;/b&gt;&amp;nbsp;contains the memory address 1000, then&amp;nbsp;&lt;b&gt;* iptr&lt;/b&gt;&amp;nbsp;will return the value stored at location 1000.&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;, serif; font-size: 13.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 14pt;&quot;&gt;Following figure illustrates this concept.&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;, serif; font-size: 13.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 14pt;&quot;&gt;Using ‘&lt;b&gt;*&lt;/b&gt;’ operator to change or access the value being pointed to by pointer is called&amp;nbsp;&lt;b&gt;Dereferencing&lt;/b&gt;.&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;, serif; font-size: 13.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Notes:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The pointer operator &lt;b&gt;* &lt;/b&gt;(called “&lt;b&gt;value at&lt;/b&gt;” sign) is the same symbol as multiply operator &lt;b&gt;* &lt;/b&gt;and the pointer operator &lt;b&gt;&amp;amp;&lt;/b&gt; (called “&lt;b&gt;address of&lt;/b&gt;” sign) is same as bitwise &lt;b&gt;AND&lt;/b&gt;operator &lt;b&gt;&amp;amp;&lt;/b&gt;. But these operators have no relationship to each other. Both pointer operators &lt;b&gt;*&lt;/b&gt; and &lt;b&gt;&amp;amp;&lt;/b&gt; have a higher precedence than all other arithmetic operators except &lt;b&gt;unary minus&lt;/b&gt;, with which they have equal precedence.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The operand of &lt;b&gt;&amp;amp;&lt;/b&gt; operator can be any variable or object whose address we need, but the operand of &lt;b&gt;*&lt;/b&gt;operator can only be a pointer variable&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;.&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;Pointers pointing to &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 16.0pt; line-height: 107%;&quot;&gt;incorrect data types&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;The pointer variables must always point to the correct type of data. For instance, when a pointer is declared to be of type int, the compiler assumes that the address being pointed to by this pointer, will hold integer values.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Consider the following code fragment :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 200px; overflow: scroll hidden; width: 350px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: left; width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;double a,b ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: left; width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;int * iptr;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: left; width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;cin&amp;gt;&amp;gt;a;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;// read float value for&lt;b&gt; a&lt;/b&gt;&lt;/font&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: left; width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;iptr = &amp;amp; a;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;// store the address of &lt;b&gt;a&lt;/b&gt; into &lt;b&gt;iptr&lt;/b&gt;&lt;/font&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: left; width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;b = *iptr;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;// store the value being pointed to by &lt;b&gt;iptr&lt;/b&gt; into &lt;/font&gt;&lt;b&gt;&lt;font color=&quot;#ff0000&quot;&gt;b&lt;/font&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The above code is intended to assign the value of &lt;b&gt;a&lt;/b&gt; to &lt;b&gt;b&lt;/b&gt;through the use of pointers, but it will not produce the desired result. Because &lt;b&gt;iptr&lt;/b&gt; is an integer pointer, only 4 bytes (int size is generally 4 bytes) of information will be transferred to &lt;b&gt;b&lt;/b&gt;, not the 8 bytes that normally make up a double type value. Thus, &lt;i&gt;making a pointer point to incorrect type of data may lead to loss of information&lt;/i&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;The “&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 16.0pt; line-height: 107%;&quot;&gt;NULL&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;” Pointer Value&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 16pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;A pointer variable must not remain uninitialized since dereferencing uninitialized pointers cause the system crashing. Even if you do not have any legal pointer value to initialize a pointer, you can initialize it with &lt;/span&gt;&lt;b style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;NULL&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;pointer value. Assigning &lt;/span&gt;&lt;b style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;NULL&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt; to a pointer initializes it to a value which is not a legal pointer but it saves you from the ‘Big’ problem of uninitialized pointers. A program can later test a pointer against &lt;/span&gt;&lt;b style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;NULL&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;(the zero pointer) to see whether it contains a legal pointer or not.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;For example, consider the following code snippet :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border: 1px solid white; height: 200px; overflow: scroll hidden; width: 350px;&quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: left; width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;int * iptr = NULL;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;// &lt;b&gt;iptr&lt;/b&gt;gets initialized with &lt;b&gt;NULL&lt;/b&gt;&lt;/font&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: left; width: 250%;&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0;&quot;&gt;…………………. ;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: left; width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;if(iptr != NULL)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: left; width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;{….&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;font color=&quot;#ff0000&quot;&gt;// use the pointer if it points to some legal address&lt;/font&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: left; width: 250%;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #0070c0; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;/div&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Important :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The expression &lt;/span&gt;&lt;/i&gt;&lt;i&gt;&lt;span style=&quot;color: #2e75b6; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;(iptr != NULL)&lt;/span&gt;&lt;/i&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; is equivalent to expression &lt;/span&gt;&lt;/i&gt;&lt;i&gt;&lt;span style=&quot;color: #2e75b6; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;(iptr)&lt;/span&gt;&lt;/i&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. The zero pointer &lt;b&gt;NULL&lt;/b&gt; is defined in the standard header file &lt;/span&gt;&lt;/i&gt;&lt;i&gt;&lt;span style=&quot;color: #7f6000; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #7F6000; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent4; mso-themecolor: accent4; mso-themeshade: 128;&quot;&gt;stddef.h&lt;/span&gt;&lt;/i&gt;&lt;i&gt;&lt;span style=&quot;color: red; font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. &lt;b&gt;NULL&lt;/b&gt; is internally mapped as int 0 (zero).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #0070c0; font-family: &amp;quot;Georgia&amp;quot;,serif; font-size: 16.0pt; line-height: 107%;&quot;&gt;nullptr &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia, serif; font-size: 16pt; line-height: 107%;&quot;&gt;– New addition in C++11 standard&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;Before the release of C++11 standard, defined as &lt;/span&gt;&lt;b style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;NULL&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;filled the role of null pointer. But in C++11, a new keyword namely &lt;/span&gt;&lt;b style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;nullptr&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;has been introduced, which is a distinguished null-point constant. So, now on (provided you are using C++11 standard compilers), you can initialize your pointers with &lt;/span&gt;&lt;b style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;nullptr&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt;&quot;&gt;.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;For example,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: left;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2e75b6; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;char * cptr = nullptr;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: left;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2e75b6; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;int * iptr = nullptr;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Difference between &lt;b&gt;NULL&lt;/b&gt; and &lt;b&gt;nullptr&lt;/b&gt; is that – &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;NULL&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; is not defined by C++, it is programmer or compiler defined whereas &lt;b&gt;nullptr&lt;/b&gt; has been defined by C++ as a legal null pointer.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;NULL&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt; is internally mapped as int 0 (zero) whereas &lt;b&gt;nullptr&lt;/b&gt; is a legal empty pointer which is implicitly convertible and comparable to any pointer-type.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;The inclusion of &lt;b&gt;nullptr&lt;/b&gt; also removes a major problem.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Suppose you have two overloaded functions&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: left;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2e75b6; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;int f1 (char *) ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: left;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2e75b6; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;int f1 (int) &lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;And we have two pointers as&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: left;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2e75b6; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;char * cptr1 = NULL ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: left;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2e75b6; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;char * cptr2 = nullptr ;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Now the function call &lt;i&gt;&lt;span style=&quot;color: #2e75b6; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;f1(cptr1)&lt;/span&gt;&lt;/i&gt; would always map to &lt;i&gt;&lt;span style=&quot;color: #2e75b6; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;f1(int)&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #2e75b6; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt; &lt;/span&gt;and not &lt;i&gt;&lt;span style=&quot;color: #2e75b6; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;f1(char *)&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #2e75b6; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt; &lt;/span&gt;as &lt;b&gt;NULL&lt;/b&gt; is internally mapped as an int.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;But &lt;i&gt;&lt;span style=&quot;color: #2e75b6; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;f1(cptr2)&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #2e75b6; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt; &lt;/span&gt;will always map to the function &lt;i&gt;&lt;span style=&quot;color: #2e75b6; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;f1(char *).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2e75b6; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2e75b6; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #2e75b6; font-family: georgia, serif; font-size: 14pt; line-height: 107%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Do not stop here. Read all articles related to C++ &lt;a href=&quot;https://www.computercodec.com/search/label/CPP?&amp;amp;max-results=9&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#b51200&quot;&gt;&lt;i&gt;here&lt;/i&gt;&lt;/font&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you have any doubts, queries or suggestions for the website, please comment on this post.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;If you want to contribute any article for the website, feel free to share it on &lt;/span&gt;&lt;a href=&quot;mailto:coding.nkcoder@gmail.com&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;coding.nkcoder@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;. We will publish it on the website with your name.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Download the pdf form of this article &lt;a href=&quot;https://drive.google.com/file/d/1uU4cV_2txcDUtVuKscdwMMLt5isA9COw/view?usp=sharing&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;&lt;font color=&quot;#b51200&quot;&gt;here&lt;/font&gt;&lt;/i&gt;&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;Related Topics :&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/introduction-to-pointers.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Introduction to Pointers&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/memory-allocation.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Static and Dynamic Allocation of Memory&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/pointer-arithmetic.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Pointer Arithmetic&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/dynamic-allocation-operators.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Dynamic Allocation Operators&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/memory-leak.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Memory Leaks&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;a href=&quot;https://www.computercodec.com/2020/07/pointers-and-const.html&quot; target=&quot;_blank&quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;Pointers &amp;amp; Constants&lt;/font&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: georgia, serif; font-size: 14pt; line-height: 107%;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.computercodec.com/feeds/2416553435883137759/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1963654198922371192&amp;postID=2416553435883137759&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/2416553435883137759'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1963654198922371192/posts/default/2416553435883137759'/><link rel='alternate' type='text/html' href='https://www.computercodec.com/2020/07/declaration-and-initialization-of.html' title='DECLARATION AND INITIALIZATION OF POINTERS   '/><author><name>NKCoder</name><uri>http://www.blogger.com/profile/02587207840499023721</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//3.bp.blogspot.com/-h8y2CI2y2N4/XwgY3o2y9sI/AAAAAAAAAFk/LpybNgRx48QV-dn44DxNlDdZxNWQ-KcPACK4BGAYYCw/s220/IMG-20200320-WA0005.jpg'/></author><thr:total>0</thr:total></entry></feed>