<?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-2036600381616701985</id><updated>2014-04-10T15:08:26.561+05:30</updated><category term="C"/><category term="Digital Signal Processing"/><category term="MATLAB"/><category term="Artificial Intelligence"/><category term="Java"/><category term="Prolog"/><category term="C++"/><category term="Linux"/><category term="Data Structure"/><category term="Computer Network"/><category term="Apache"/><category term="Bit-wise Operation"/><category term="Computer Architecture"/><category term="GATE Special"/><category term="MySql"/><category term="Php"/><category term="Port"/><category term="Wamp"/><category term="Web"/><title type='text'>ProgrammingBlue</title><subtitle type='html'>One stop for all your programming practices</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>ProgNinja Blue</name><uri>https://plus.google.com/103025513032526183728</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>54</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-7019744354574226848</id><published>2014-04-10T15:08:00.001+05:30</published><updated>2014-04-10T15:08:26.575+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>Difference between throw and throws in Java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;strong style=&quot;background-color: white; border: 0px; color: #333333; font-family: Georgia, &#39;Bitstream Charter&#39;, serif; font-size: 16px; line-height: 24px; margin: 0px; padding: 0px; text-align: justify; vertical-align: baseline;&quot;&gt;Throws:&amp;nbsp;&lt;/strong&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Georgia, &#39;Bitstream Charter&#39;, serif; font-size: 16px; line-height: 24px; text-align: justify;&quot;&gt;Throws declares that your method is capable of throwing an exception but it does not handle the exception that must be specified by using “throws” class.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Georgia, &#39;Bitstream Charter&#39;, serif; font-size: 16px; line-height: 24px; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Georgia, &#39;Bitstream Charter&#39;, serif; font-size: 16px; line-height: 24px; text-align: justify;&quot;&gt;When programmer defines a method and he knows that some part of code can raise an exception, and he don’t want to handle that exception within that function, then the method is defined with throws keyword.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Georgia, &#39;Bitstream Charter&#39;, serif; font-size: 16px; line-height: 24px; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Georgia, &#39;Bitstream Charter&#39;, serif; font-size: 16px; line-height: 24px; text-align: justify;&quot;&gt;Let us understand this with following example:&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Georgia, &#39;Bitstream Charter&#39;, serif; font-size: 16px; line-height: 24px; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;Imagine you have been assigned a task of finding a specific book, and then reading and explaining its contents to a class of students. The required sequence may look like:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, &#39;Bitstream Charter&#39;, serif; line-height: 24px;&quot;&gt;Get the specified book&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, &#39;Bitstream Charter&#39;, serif; line-height: 24px;&quot;&gt;Read aloud its contents&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, &#39;Bitstream Charter&#39;, serif; line-height: 24px;&quot;&gt;Explain the contents to a class of students.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;background-color: white; line-height: 24px; text-align: justify;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;But what happens if you can&#39;t find the specified book? You can&#39;t proceed with the rest of the action without it so you need to report back to the person who assigned the task to you. This unexpected event (missing book) prevents you from completing your task. By reporting it back, you want the originator of this request to take corrective or alternate steps.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;Let&#39;s code the above task as method teachClass, as shown in figure 1 and use it to compare the throw and throws statement. This example code is for demonstration purpose only because it uses methods locateBook, readBook, and explainContents, which aren&#39;t defined.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;void teachclass () throws BookNotFoundException&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; boolean bookFound = locateBook();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if(!bookFound)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; throw new BookNotFoundException();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;Code in figure 1 is simple to follow. On execution of code throw new BookNotFoundException, execution of teachClass() halts. The JVM creates an instance of BookNotFoundException and sends it to off to the caller of teachClass() so that alternate arrangements can be made.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;The throw statement is used to throw an instance of exception—BookNotFoundException. The throws statement is used in the signature of method teachClass to signal that it can throw exception BookNotFoundException.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;Why does a method choose to throw an exception as opposed to handling it itself? It&#39;s a contract between the calling method and the called method. Referring back to the method teachClass, as shown in figure 1, the caller of teachClass would like to be informed if teachClass is unable to find the specified book. The method teachClass doesn&#39;t handle BookNotFoundException itself because its responsibilities don&#39;t include how to work around a missing book.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #333333; font-family: Georgia, Bitstream Charter, serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/7019744354574226848/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2014/04/difference-between-throw-and-throws-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/7019744354574226848'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/7019744354574226848'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2014/04/difference-between-throw-and-throws-in.html' title='Difference between throw and throws in Java'/><author><name>ProgNinja Blue</name><uri>https://plus.google.com/103025513032526183728</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-5673285029861706359</id><published>2013-12-05T14:22:00.004+05:30</published><updated>2013-12-05T14:24:16.983+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><title type='text'>Finding the missing term of an A.P.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;An Arithmetic Progression is defined as one in which there is a constant  difference between the consecutive terms of a given series of numbers.  You are provided with consecutive elements of an Arithmetic Progression.  There is however one hitch: Exactly one term from the original series  is missing from the set of numbers which have been given to you. The  rest of the given series is the same as the original AP. &amp;nbsp;Find the  missing term. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;int main() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; unsigned int N,i;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; N = 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int *M;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; scanf(&quot;%u&quot;,&amp;amp;N);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; M = (int*)malloc(sizeof(int)*N);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(i = 0; i&amp;lt;N; i++)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; scanf(&quot;%d&quot;,&amp;amp;M[i]);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int diff1 = 0, diff2 = 0, diff3 = 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; diff1 = M[1] - M[0];&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; diff2 = M[2] - M[1];&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int cd = 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (diff1 &amp;gt; diff2)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cd = diff2;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cd = diff1;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(i = 0;i&amp;lt;N-1;i++)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(M[i+1] - M[i] == cd)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; continue;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if(M[i+1] - M[i] == cd*2)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;%d&quot;,M[i]+cd);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Any question? Please mail on 27it08@gmail.com &lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/5673285029861706359/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2013/12/n-arithmetic-progression-is-defined-as.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/5673285029861706359'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/5673285029861706359'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2013/12/n-arithmetic-progression-is-defined-as.html' title='Finding the missing term of an A.P.'/><author><name>ProgNinja Blue</name><uri>https://plus.google.com/103025513032526183728</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-8441886430394200246</id><published>2013-11-19T10:12:00.000+05:30</published><updated>2013-11-19T10:18:58.929+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Apache"/><category scheme="http://www.blogger.com/atom/ns#" term="MySql"/><category scheme="http://www.blogger.com/atom/ns#" term="Php"/><category scheme="http://www.blogger.com/atom/ns#" term="Port"/><category scheme="http://www.blogger.com/atom/ns#" term="Wamp"/><category scheme="http://www.blogger.com/atom/ns#" term="Web"/><title type='text'>Running Wamp server on on port different than default port 80</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;!--[if !mso]&gt;&lt;style&gt;v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} &lt;/style&gt;&lt;![endif]--&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt; &lt;o:OfficeDocumentSettings&gt;  &lt;o:AllowPNG/&gt; &lt;/o:OfficeDocumentSettings&gt;&lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt; &lt;w:WordDocument&gt;  &lt;w:View&gt;Normal&lt;/w:View&gt;  &lt;w:Zoom&gt;0&lt;/w:Zoom&gt;  &lt;w:TrackMoves&gt;false&lt;/w:TrackMoves&gt;  &lt;w:TrackFormatting/&gt;  &lt;w:PunctuationKerning/&gt;  &lt;w:ValidateAgainstSchemas/&gt;  &lt;w:SaveIfXMLInvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;  &lt;w:IgnoreMixedContent&gt;false&lt;/w:IgnoreMixedContent&gt;  &lt;w:AlwaysShowPlaceholderText&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;  &lt;w:DoNotPromoteQF/&gt;  &lt;w:LidThemeOther&gt;EN-IN&lt;/w:LidThemeOther&gt;  &lt;w:LidThemeAsian&gt;X-NONE&lt;/w:LidThemeAsian&gt;  &lt;w:LidThemeComplexScript&gt;X-NONE&lt;/w:LidThemeComplexScript&gt;  &lt;w:Compatibility&gt;   &lt;w:BreakWrappedTables/&gt;   &lt;w:SnapToGridInCell/&gt;   &lt;w:WrapTextWithPunct/&gt;   &lt;w:UseAsianBreakRules/&gt;   &lt;w:DontGrowAutofit/&gt;   &lt;w:SplitPgBreakAndParaMark/&gt;   &lt;w:EnableOpenTypeKerning/&gt;   &lt;w:DontFlipMirrorIndents/&gt;   &lt;w:OverrideTableStyleHps/&gt;  &lt;/w:Compatibility&gt;  &lt;m:mathPr&gt;   &lt;m:mathFont m:val=&quot;Cambria Math&quot;/&gt;   &lt;m:brkBin m:val=&quot;before&quot;/&gt;   &lt;m:brkBinSub m:val=&quot;&amp;#45;-&quot;/&gt;   &lt;m:smallFrac m:val=&quot;off&quot;/&gt;   &lt;m:dispDef/&gt;   &lt;m:lMargin m:val=&quot;0&quot;/&gt;   &lt;m:rMargin m:val=&quot;0&quot;/&gt;   &lt;m:defJc m:val=&quot;centerGroup&quot;/&gt;   &lt;m:wrapIndent m:val=&quot;1440&quot;/&gt;   &lt;m:intLim m:val=&quot;subSup&quot;/&gt;   &lt;m:naryLim m:val=&quot;undOvr&quot;/&gt;  &lt;/m:mathPr&gt;&lt;/w:WordDocument&gt;&lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt; &lt;w:LatentStyles DefLockedState=&quot;false&quot; DefUnhideWhenUsed=&quot;true&quot;   DefSemiHidden=&quot;true&quot; DefQFormat=&quot;false&quot; DefPriority=&quot;99&quot;   LatentStyleCount=&quot;267&quot;&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;0&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;Normal&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;9&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;heading 1&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;9&quot; QFormat=&quot;true&quot; Name=&quot;heading 2&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;9&quot; QFormat=&quot;true&quot; Name=&quot;heading 3&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;9&quot; QFormat=&quot;true&quot; Name=&quot;heading 4&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;9&quot; QFormat=&quot;true&quot; Name=&quot;heading 5&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;9&quot; QFormat=&quot;true&quot; Name=&quot;heading 6&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;9&quot; QFormat=&quot;true&quot; Name=&quot;heading 7&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;9&quot; QFormat=&quot;true&quot; Name=&quot;heading 8&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;9&quot; QFormat=&quot;true&quot; Name=&quot;heading 9&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;39&quot; Name=&quot;toc 1&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;39&quot; Name=&quot;toc 2&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;39&quot; Name=&quot;toc 3&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;39&quot; Name=&quot;toc 4&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;39&quot; Name=&quot;toc 5&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;39&quot; Name=&quot;toc 6&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;39&quot; Name=&quot;toc 7&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;39&quot; Name=&quot;toc 8&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;39&quot; Name=&quot;toc 9&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;35&quot; QFormat=&quot;true&quot; Name=&quot;caption&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;10&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;Title&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;1&quot; Name=&quot;Default Paragraph Font&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;11&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;Subtitle&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;22&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;Strong&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;20&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;Emphasis&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;59&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Table Grid&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; UnhideWhenUsed=&quot;false&quot; Name=&quot;Placeholder Text&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;1&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;No Spacing&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;60&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Shading&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;61&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Light List&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;62&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Grid&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;63&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 1&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;64&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 2&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;65&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 1&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;66&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 2&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;67&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 1&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;68&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 2&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;69&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 3&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;70&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Dark List&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;71&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Shading&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;72&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful List&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;73&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Grid&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;60&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Shading Accent 1&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;61&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Light List Accent 1&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;62&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Grid Accent 1&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;63&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 1 Accent 1&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;64&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 2 Accent 1&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;65&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 1 Accent 1&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; UnhideWhenUsed=&quot;false&quot; Name=&quot;Revision&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;34&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;List Paragraph&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;29&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;Quote&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;30&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;Intense Quote&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;66&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 2 Accent 1&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;67&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 1 Accent 1&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;68&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 2 Accent 1&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;69&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 3 Accent 1&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;70&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Dark List Accent 1&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;71&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Shading Accent 1&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;72&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful List Accent 1&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;73&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Grid Accent 1&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;60&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Shading Accent 2&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;61&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Light List Accent 2&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;62&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Grid Accent 2&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;63&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 1 Accent 2&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;64&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 2 Accent 2&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;65&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 1 Accent 2&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;66&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 2 Accent 2&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;67&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 1 Accent 2&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;68&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 2 Accent 2&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;69&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 3 Accent 2&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;70&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Dark List Accent 2&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;71&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Shading Accent 2&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;72&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful List Accent 2&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;73&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Grid Accent 2&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;60&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Shading Accent 3&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;61&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Light List Accent 3&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;62&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Grid Accent 3&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;63&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 1 Accent 3&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;64&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 2 Accent 3&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;65&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 1 Accent 3&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;66&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 2 Accent 3&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;67&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 1 Accent 3&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;68&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 2 Accent 3&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;69&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 3 Accent 3&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;70&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Dark List Accent 3&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;71&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Shading Accent 3&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;72&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful List Accent 3&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;73&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Grid Accent 3&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;60&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Shading Accent 4&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;61&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Light List Accent 4&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;62&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Grid Accent 4&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;63&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 1 Accent 4&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;64&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 2 Accent 4&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;65&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 1 Accent 4&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;66&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 2 Accent 4&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;67&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 1 Accent 4&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;68&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 2 Accent 4&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;69&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 3 Accent 4&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;70&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Dark List Accent 4&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;71&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Shading Accent 4&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;72&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful List Accent 4&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;73&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Grid Accent 4&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;60&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Shading Accent 5&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;61&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Light List Accent 5&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;62&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Grid Accent 5&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;63&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 1 Accent 5&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;64&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 2 Accent 5&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;65&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 1 Accent 5&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;66&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 2 Accent 5&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;67&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 1 Accent 5&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;68&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 2 Accent 5&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;69&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 3 Accent 5&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;70&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Dark List Accent 5&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;71&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Shading Accent 5&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;72&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful List Accent 5&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;73&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Grid Accent 5&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;60&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Shading Accent 6&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;61&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Light List Accent 6&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;62&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Grid Accent 6&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;63&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 1 Accent 6&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;64&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 2 Accent 6&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;65&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 1 Accent 6&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;66&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 2 Accent 6&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;67&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 1 Accent 6&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;68&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 2 Accent 6&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;69&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 3 Accent 6&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;70&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Dark List Accent 6&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;71&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Shading Accent 6&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;72&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful List Accent 6&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;73&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Grid Accent 6&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;19&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;Subtle Emphasis&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;21&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;Intense Emphasis&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;31&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;Subtle Reference&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;32&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;Intense Reference&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;33&quot; SemiHidden=&quot;false&quot;    UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;Book Title&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;37&quot; Name=&quot;Bibliography&quot;/&gt;  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;39&quot; QFormat=&quot;true&quot; Name=&quot;TOC Heading&quot;/&gt; &lt;/w:LatentStyles&gt;&lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 10]&gt;&lt;style&gt; /* Style Definitions */  table.MsoNormalTable  {mso-style-name:&quot;Table Normal&quot;;  mso-tstyle-rowband-size:0;  mso-tstyle-colband-size:0;  mso-style-noshow:yes;  mso-style-priority:99;  mso-style-parent:&quot;&quot;;  mso-padding-alt:0cm 5.4pt 0cm 5.4pt;  mso-para-margin-top:0cm;  mso-para-margin-right:0cm;  mso-para-margin-bottom:10.0pt;  mso-para-margin-left:0cm;  line-height:115%;  mso-pagination:widow-orphan;  font-size:11.0pt;  font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;  mso-ascii-font-family:Calibri;  mso-ascii-theme-font:minor-latin;  mso-hansi-font-family:Calibri;  mso-hansi-theme-font:minor-latin;  mso-bidi-font-family:&quot;Times New Roman&quot;;  mso-bidi-theme-font:minor-bidi;  mso-fareast-language:EN-US;} &lt;/style&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt; &lt;o:shapedefaults v:ext=&quot;edit&quot; spidmax=&quot;1027&quot;/&gt;&lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt; &lt;o:shapelayout v:ext=&quot;edit&quot;&gt;  &lt;o:idmap v:ext=&quot;edit&quot; data=&quot;1&quot;/&gt; &lt;/o:shapelayout&gt;&lt;/xml&gt;&lt;![endif]--&gt; &lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Monotype Corsiva&amp;quot;; font-size: 14.0pt; line-height: 115%; mso-bidi-font-size: 11.0pt;&quot;&gt;You have developed a system that is written using windows-apache-mysql-php. One day you open the system, launches the wamp server and here you g , you are finding that localhost is no longer responding and it becomes a nightmare for you to figure it out why it is not working. The reason is you have installed some other server like IIS, Glassfish or any other server that is by default configured on port 80. With the installation of glassfish you may not encounter the problem but when it is IIS, you are in trouble. As IIS is made to run forever on system by default, port 80 is always in use and you cannot open another socket connection on same port. &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=2036600381616701985&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=2036600381616701985&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=2036600381616701985&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=2036600381616701985&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=2036600381616701985&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: &amp;quot;Monotype Corsiva&amp;quot;; font-size: 14.0pt; line-height: 115%; mso-bidi-font-size: 11.0pt;&quot;&gt;I think problem is clear enough. Now let us proceed to rescue the thing that is haunting you for weeks. Simple solution is to change the port number. There is funny part associated with this. Once someone asked if he should format the computer. Lol. You do not need to format your computer to solve just port related problems. Just change the configuration file in the installation directory of wamp and problem is solved.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Monotype Corsiva&amp;quot;; font-size: 14.0pt; line-height: 115%; mso-bidi-font-size: 11.0pt;&quot;&gt;Here is the steps you need to follow:&lt;/span&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=2036600381616701985&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=2036600381616701985&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=2036600381616701985&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=2036600381616701985&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=2036600381616701985&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=2036600381616701985&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=2036600381616701985&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=2036600381616701985&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=2036600381616701985&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=2036600381616701985&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-cDDArMBj75w/Uorr1qF8IhI/AAAAAAAAASk/sI-P3UW25Lo/s1600/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-cDDArMBj75w/Uorr1qF8IhI/AAAAAAAAASk/sI-P3UW25Lo/s1600/1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-sAxVz6sziUI/UorsDmhMcVI/AAAAAAAAASs/ol1iPPVggN0/s1600/Untitled.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://3.bp.blogspot.com/-sAxVz6sziUI/UorsDmhMcVI/AAAAAAAAASs/ol1iPPVggN0/s1600/Untitled.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;ol&gt;&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;Monotype Corsiva&amp;quot;; font-size: 14.0pt; line-height: 115%; mso-bidi-font-size: 11.0pt;&quot;&gt;Go to &amp;lt;Installation directory&amp;gt;\wamp&lt;/span&gt;\&lt;span style=&quot;font-family: &amp;quot;Monotype Corsiva&amp;quot;; font-size: 14.0pt; line-height: 115%; mso-bidi-font-family: &amp;quot;Monotype Corsiva&amp;quot;; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: &amp;quot;Monotype Corsiva&amp;quot;;&quot;&gt;bin\apache\apache2.2.22\conf .&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;Monotype Corsiva&amp;quot;; font-size: 14.0pt; line-height: 115%; mso-bidi-font-family: &amp;quot;Monotype Corsiva&amp;quot;; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: &amp;quot;Monotype Corsiva&amp;quot;;&quot;&gt;Open httpd.conf and look for 80 by ctrl+F.&lt;br /&gt; &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;Monotype Corsiva&amp;quot;; font-size: 14.0pt; line-height: 115%; mso-bidi-font-family: &amp;quot;Monotype Corsiva&amp;quot;; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: &amp;quot;Monotype Corsiva&amp;quot;;&quot;&gt;Replace 80 by the port you want wamp to listen to. Now you are done. But wait. This is only half way done.&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;Because when you launch wamp from tray icon it will open &lt;a href=&quot;http://localhost/&quot;&gt;http://localhost/&lt;/a&gt; in your default browser. But it is supposed to open &lt;a href=&quot;http://www.blogger.com/null&quot;&gt;http://localhost:&amp;lt;you new port&amp;gt;/&lt;/a&gt; . &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;Monotype Corsiva&amp;quot;; font-size: 14.0pt; line-height: 115%; mso-bidi-font-family: &amp;quot;Monotype Corsiva&amp;quot;; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: &amp;quot;Monotype Corsiva&amp;quot;;&quot;&gt;Obviously you can always type &lt;a href=&quot;http://www.blogger.com/null&quot;&gt;http://localhost:&amp;lt;you new port&amp;gt;/&lt;/a&gt; &lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;manually in your favourite browser but if this could have worked by clicking localhost in tray icon menu of wamp, wouldnot that be easier for you! Okay then keep reading to know how it is getting done. &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;Monotype Corsiva&amp;quot;; font-size: 14.0pt; line-height: 115%; mso-bidi-font-family: &amp;quot;Monotype Corsiva&amp;quot;; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: &amp;quot;Monotype Corsiva&amp;quot;;&quot;&gt;In &amp;lt;Installation directory&amp;gt;\wamp you will find wampmanager.tpl. Open it and search for localhost. Replace &lt;a href=&quot;http://localhost/&quot;&gt;http://localhost/&lt;/a&gt; by &lt;a href=&quot;http://www.blogger.com/null&quot;&gt;http://localhost:&amp;lt;your new port&amp;gt;/&lt;/a&gt;. &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;Monotype Corsiva&amp;quot;; font-size: 14.0pt; line-height: 115%; mso-bidi-font-family: &amp;quot;Monotype Corsiva&amp;quot;; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: &amp;quot;Monotype Corsiva&amp;quot;;&quot;&gt;S&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Monotype Corsiva&amp;quot;; font-size: 14.0pt; line-height: 115%; mso-bidi-font-family: &amp;quot;Monotype Corsiva&amp;quot;; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: &amp;quot;Monotype Corsiva&amp;quot;;&quot;&gt;ame thing you do with wampmanager.ini found in &amp;lt;Installation directory&amp;gt;\wamp. &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;Monotype Corsiva&amp;quot;; font-size: 14.0pt; line-height: 115%; mso-bidi-font-family: &amp;quot;Monotype Corsiva&amp;quot;; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: &amp;quot;Monotype Corsiva&amp;quot;;&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Monotype Corsiva&amp;quot;; font-size: 14.0pt; line-height: 115%; mso-bidi-font-size: 11.0pt;&quot;&gt;ou are done. Restart wamp. And Launch your localhost wamp home page.&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/8441886430394200246/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2013/11/running-wamp-server-on-on-port.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/8441886430394200246'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/8441886430394200246'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2013/11/running-wamp-server-on-on-port.html' title='Running Wamp server on on port different than default port 80'/><author><name>ProgNinja Blue</name><uri>https://plus.google.com/103025513032526183728</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-cDDArMBj75w/Uorr1qF8IhI/AAAAAAAAASk/sI-P3UW25Lo/s72-c/1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-6559797186272934490</id><published>2012-12-15T02:18:00.000+05:30</published><updated>2012-12-15T02:18:43.710+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Data Structure"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>Write a Java Program to implement Counting Sort.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Counting Sort assumes that each of the n input elements is an integer range from 0 to &lt;i&gt;k &lt;/i&gt;for some integer &lt;i&gt;k. &lt;/i&gt;When &lt;i&gt;k &lt;/i&gt;is in order of uper bound &lt;i&gt;n&lt;/i&gt; then sort runs in order of &lt;i&gt;n&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;package counting.sort;&lt;br /&gt;public class CountingSort&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; public static void main(String[ ] args)&lt;br /&gt;&amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;int [ ]A = {-1, 19,20,23,48,19,34,34,19,0,2};&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;int [ ]C = new int[50];&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//Frequency of each element&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for(int i = 1;i&amp;lt;A.length;i++)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C[A[i]] = C[A[i]]+1;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//Cumulative Frequency&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for(int i = 1;i&amp;lt;C.length;i++)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C[i] = C[i]+C[i-1];&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;int [ ]B= new int[A.length];&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for(int i = A.length -1 ;i&amp;gt;=1;i--)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B[C[A[i]]] = A[i];&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C[A[i]] = C[A[i]] - 1;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;print(B); &amp;nbsp;//B is sorted array&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; static void print(int [ ]A)&lt;br /&gt;&amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for(int i=0;i&amp;lt;A.length;i++)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(i!=A.length-1)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.print(A[i]+ &quot;,&quot;);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.print(A[i]);;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;}&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/6559797186272934490/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/12/write-java-program-to-implement.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/6559797186272934490'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/6559797186272934490'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/12/write-java-program-to-implement.html' title='Write a Java Program to implement Counting Sort.'/><author><name>ProgNinja Blue</name><uri>https://plus.google.com/103025513032526183728</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-4714086366489348404</id><published>2012-12-15T02:13:00.001+05:30</published><updated>2012-12-15T02:13:13.920+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Data Structure"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>Write Java Program to implement Quick Sort.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;This Sorting Algorithm is based on Divide and Conquer approach.&lt;br /&gt;&lt;br /&gt;package quicksort;&lt;br /&gt;public class QuickSort {&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; public static void main(String[ ] args) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int [ ]A = {6, 9, 18, 4, 3, 15};&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Sort qs = new Sort();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; qs.sort(A,0,A.length-1);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; qs.print(A);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;br /&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-pDgIAt_sggs/UMuPHdEhz5I/AAAAAAAAAPA/FVdzjoLBrPU/s1600/Untitled-1.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;161&quot; src=&quot;http://1.bp.blogspot.com/-pDgIAt_sggs/UMuPHdEhz5I/AAAAAAAAAPA/FVdzjoLBrPU/s200/Untitled-1.jpg&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;}&lt;br /&gt;class Sort&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; void sort(int [ ]A, int p, int r)&lt;br /&gt;&amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int q = 0;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(p&amp;lt;r)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; q = this.partition(A, p, r);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sort(A,p, q -1);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sort(A,q+1,r);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; int partition(int [ ]A,int a, int b)&lt;br /&gt;&amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int x =A[b];&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int i = a -1;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for (int j = a;j&amp;lt;=b -1; j++)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(A[j]&amp;lt;=x)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;i++;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//Swap&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(A[i]!=A[j])&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A[i] = A[i] ^ A[j];&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A[j] = A[i] ^ A[j];&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A[i] = A[i] ^ A[j];&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A[i+1] = A[i+1] ^ A[b];&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A[b] = A[i+1] ^ A[b];&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A[i+1] = A[i+1] ^ A[b];&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return i+1;&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; void print(int [ ]A)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;System.out.println();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for(int i=0;i&amp;lt;A.length;i++)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(i!=A.length-1)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;System.out.print(A[i]+ &quot;,&quot;);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;System.out.print(A[i]);;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/4714086366489348404/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/12/write-java-program-to-implement-quick.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/4714086366489348404'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/4714086366489348404'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/12/write-java-program-to-implement-quick.html' title='Write Java Program to implement Quick Sort.'/><author><name>ProgNinja Blue</name><uri>https://plus.google.com/103025513032526183728</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-pDgIAt_sggs/UMuPHdEhz5I/AAAAAAAAAPA/FVdzjoLBrPU/s72-c/Untitled-1.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-8256333167335490101</id><published>2012-12-02T16:54:00.008+05:30</published><updated>2012-12-02T23:44:32.671+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Data Structure"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>Write a Java Program to implement heap and heap sort.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div&gt;I am assuming that actual index of array for purpose of implementing heap starts with 1 and whatever value is in index no. 0 will treated as garbage.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;package heap;&lt;br /&gt;public class Heap&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; public static void main(String[ ] args)&lt;br /&gt;&amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int [ ]A = {-9999, 67, 28, 2, 23, 5 ,93, 98, -37};&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; HeapData myHeap = new HeapData(A);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&quot;Heap formed is:&quot;);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; myHeap.printHeap();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(myHeap.checkHeap(A));&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; myHeap.HeapSort();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; myHeap.printHeap();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //test case 1&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int [ ]B = {-9999, 162, 32, 92, 2, 22, 12, 42}; &amp;nbsp;//This is a Heapified Array .. must return true.&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(myHeap.checkHeap(B));&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //test case 2&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int [ ]C = {-9999, 12, 32, 2, 32, 29, 122, 43};&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(myHeap.checkHeap(C));&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;iframe frameborder=&quot;0&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;http://rcm.amazon.com/e/cm?t=httpprogram01-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=B007FHX9OK&amp;amp;ref=qf_br_asin_til&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr&quot; style=&quot;height: 270px; width: 120px;&quot;&gt;&lt;/iframe&gt; &lt;br /&gt;class HeapData&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; int [ ] Data;&lt;br /&gt;&amp;nbsp; &amp;nbsp; HeapData(int [ ]A)&lt;br /&gt;&amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int i = 1, k = 1;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for(i =2 ; i&amp;lt;A.length; i++)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; k =i;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; do&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; { &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(A[k] &amp;gt; A[(k&amp;gt;&amp;gt;1)])&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* SWAP */&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A[k] = A[k] ^ A[k&amp;gt;&amp;gt;1];&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A[k&amp;gt;&amp;gt;1] = A[k] ^ A[k&amp;gt;&amp;gt;1];&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A[k] = A[k] ^ A[k&amp;gt;&amp;gt;1];&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; k = k&amp;gt;&amp;gt;1;&lt;br /&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;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }while(k&amp;gt;1);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Data = A;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; void printHeap()&lt;br /&gt;&amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for(int i = 1 ; i&amp;lt;Data.length;i++)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.print(Data[i]);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (i &amp;lt; Data.length -1)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.print(&quot;, &quot;);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println();&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; boolean checkHeap(int A[ ])&lt;br /&gt;&amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (int i = 1; i&amp;lt; A.length/2;i++)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(!(A[i]&amp;gt;A[2*i] &amp;amp;&amp;amp; A[i]&amp;gt;A[(2*i) +1]))&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return false;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return true;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; void HeapSort()&lt;br /&gt;&amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int i, j, k = 0;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for(i = Data.length - 1;i&amp;gt;0;i--)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Swap Data[1] with ith element&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Data[i] = Data[i] ^ Data[1];&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Data[1] = Data[i] ^ Data[1];&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Data[i] = Data[i] ^ Data[1];&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for(j =2 ; j&amp;lt;i; j++)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; k =j;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; do&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; { &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(Data[k] &amp;gt; Data[(k&amp;gt;&amp;gt;1)])&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&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; /* SWAP */&lt;br /&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; Data[k] = Data[k] ^ Data[k&amp;gt;&amp;gt;1];&lt;br /&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; Data[k&amp;gt;&amp;gt;1] = Data[k] ^ Data[k&amp;gt;&amp;gt;1];&lt;br /&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; Data[k] = Data[k] ^ Data[k&amp;gt;&amp;gt;1];&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; k = k&amp;gt;&amp;gt;1;&lt;br /&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;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }while(k&amp;gt;1);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &lt;br /&gt;}&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/8256333167335490101/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/12/write-java-program-to-implement-heap.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/8256333167335490101'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/8256333167335490101'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/12/write-java-program-to-implement-heap.html' title='Write a Java Program to implement heap and heap sort.'/><author><name>ProgNinja Blue</name><uri>https://plus.google.com/103025513032526183728</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-7103481109877214685</id><published>2012-12-01T17:09:00.004+05:30</published><updated>2012-12-01T17:09:51.218+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Bit-wise Operation"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>Write a Java program to convert positive decimal integer to binary equivalent using bit-wise operators.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;package decimaltobinary;&lt;br /&gt;import java.io.BufferedReader;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.io.InputStreamReader;&lt;br /&gt;&lt;br /&gt;public class DecimalToBinary {&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; public static void main(String[ ] args) throws IOException {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.print(&quot;Enter The Decimal numbber:&quot;);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String input = reader.readLine();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int deci = Integer.parseInt(input);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Convert toConvert = new Convert();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; toConvert.deciTobinary(deci);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;iframe frameborder=&quot;0&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;http://rcm.amazon.com/e/cm?t=httpprogram01-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=B003VNKNF0&amp;amp;ref=qf_br_asin_til&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr&quot; style=&quot;height: 240px; width: 120px;&quot;&gt;&lt;/iframe&gt; &lt;br /&gt;&lt;br /&gt;class Convert&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; Convert()&lt;br /&gt;&amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; void deciTobinary(int decimal)&lt;br /&gt;&amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&quot;Binary Equivalent of &quot;+decimal+&quot; is:&quot; );&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int mask = 1073741824;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;/* Binary Value of&amp;nbsp;1073741824&amp;nbsp;is 1000000000000000000000000000000 which is used as masking for logical bit-wise ANDing. Note: int in Java is of 32 bit */&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; while(mask &amp;gt; 0)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if((decimal &amp;amp; mask) &amp;gt; 0)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.print(&quot;1&quot;);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.print(&quot;0&quot;);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mask = mask &amp;gt;&amp;gt; 1;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/7103481109877214685/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/12/write-java-program-to-convert-positive.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/7103481109877214685'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/7103481109877214685'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/12/write-java-program-to-convert-positive.html' title='Write a Java program to convert positive decimal integer to binary equivalent using bit-wise operators.'/><author><name>ProgNinja Blue</name><uri>https://plus.google.com/103025513032526183728</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-471523442678180127</id><published>2012-11-29T01:50:00.002+05:30</published><updated>2012-12-01T00:06:22.879+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>Write a Java Program to check two string if they are anagram of each other</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;package AnaGram;&lt;br /&gt;import java.io.BufferedReader;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.io.InputStreamReader;&lt;br /&gt;public class myAnagram&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; public static void main(String[] args) throws IOException&lt;br /&gt;&amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // TODO code application logic her&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BufferedReader reader1= new BufferedReader(new InputStreamReader(System.in));&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&quot;\nEnter first string:&quot;);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String s1= reader1.readLine();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BufferedReader reader2= new BufferedReader(new InputStreamReader(System.in));&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&quot;\nEnter first string:&quot;);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String s2= reader2.readLine();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Anagram ana = new Anagram();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(ana.check(s1,s2)==true)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&quot; String &quot;+s1+&quot; is anagram of &quot;+s2);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&quot; String &quot;+s1+&quot; is not anagram of &quot;+s2);&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;iframe src=&quot;http://rcm.amazon.com/e/cm?t=httpprogram01-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=B007VCRRNS&amp;ref=qf_sp_asin_til&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;m=amazon&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr&quot; style=&quot;width:120px;height:240px;&quot; scrolling=&quot;no&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; frameborder=&quot;0&quot;&gt;&lt;/iframe&gt;  &lt;br/&gt;class Anagram&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; boolean check(String s1,String s2)&lt;br /&gt;&amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; char a1[]= s1.toCharArray();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; char a2[]= s2.toCharArray();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int []index1= new int[26];&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int []index2= new int[26];&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int i = 0;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for(i=0;i&amp;lt;a1.length;i++)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; index1[a1[i]-&#39;a&#39;]++;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for(i=0;i&amp;lt;a2.length;i++)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; index2[a2[i]-&#39;a&#39;]++;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for(i=0;i&amp;lt;26;i++)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(index1[i]!=index2[i])&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return false;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return true;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/471523442678180127/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/11/write-java-program-to-check-two-string.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/471523442678180127'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/471523442678180127'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/11/write-java-program-to-check-two-string.html' title='Write a Java Program to check two string if they are anagram of each other'/><author><name>ProgNinja Blue</name><uri>https://plus.google.com/103025513032526183728</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-2349434182485565456</id><published>2012-11-29T00:50:00.000+05:30</published><updated>2012-12-01T00:10:54.383+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>Write a Java Program to find second smallest element of an array.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;package Small2;&lt;br /&gt;public class small2 {&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; public static void main(String[] args) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int []A = {10,2,8,15,-2};&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SecondSmall slg = new SecondSmall();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int y = slg.findsecondsmall(A);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&quot;Second Smallest element of Array A is &quot;+ y);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int []B = {10,15,30,5,7};&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; y = slg.findsecondsmall(B);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&quot;Second Smallest element of Array B is &quot;+ y);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int []C = {13,74,29,30,31,73,62,22};&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; y = slg.findsecondsmall(C);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&quot;Second Smallest element of Array C is &quot;+ y);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int []D = {1,2,3,4,5,6,7};&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; y = slg.findsecondsmall(D);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&quot;Second Smallest element of Array D is &quot;+ y);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int []E = {7,6,5,4,3,2,1};&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; y = slg.findsecondsmall(E);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&quot;Second Smallest element of Array E is &quot;+ y);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int []F = {7,6,5,4,3,2,1,-1,-2,-3,-4,-5,-6,-7};&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; y = slg.findsecondsmall(F);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&quot;Second Smallest element of Array F is &quot;+ y);&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;iframe src=&quot;http://rcm.amazon.com/e/cm?t=httpprogram01-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=B0042FV2SI&amp;ref=qf_br_asin_til&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;m=amazon&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr&quot; style=&quot;width:120px;height:240px;&quot; scrolling=&quot;no&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; frameborder=&quot;0&quot;&gt;&lt;/iframe&gt; &lt;br /&gt;class SecondSmall&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; int findsecondsmall(int A[])&lt;br /&gt;&amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int first1 = A[0];&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int first2 = A[1];&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int i = 1;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for(;i&amp;lt;A.length;i++)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(A[i]&amp;lt;first1)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; first2 = first1 ;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; first1 = A[i];&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else if(A[i]&amp;lt;first2)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; first2 = A[i];&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return first2;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/2349434182485565456/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/11/write-java-program-to-find-second.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/2349434182485565456'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/2349434182485565456'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/11/write-java-program-to-find-second.html' title='Write a Java Program to find second smallest element of an array.'/><author><name>ProgNinja Blue</name><uri>https://plus.google.com/103025513032526183728</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-8040908515785859899</id><published>2012-11-28T23:57:00.001+05:30</published><updated>2012-12-01T00:12:54.087+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>Write a Java Program to find Nth Fibonacci number.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;&lt;span style=&quot;color: #073763;&quot;&gt;package Fibonacci;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #073763;&quot;&gt;import java.io.BufferedReader;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #073763;&quot;&gt;import java.io.IOException;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #073763;&quot;&gt;import java.io.InputStreamReader;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #073763;&quot;&gt;import java.util.logging.Level;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #073763;&quot;&gt;import java.util.logging.Logger;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;public class Fibonacci {&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; public static void main(String[] args) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&quot;\nEnter FIbonaci Index:&quot;);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String input= reader.readLine();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int i = Integer.parseInt(input);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Fibo f = new Fibo();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int y = f.fibo(i);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&quot;Fibonaci number index &quot;+i+&quot; is &quot;+y);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } catch (IOException ex) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&quot;IO Exception Error&quot;);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;iframe src=&quot;http://rcm.amazon.com/e/cm?t=httpprogram01-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=B0083Q04IQ&amp;ref=qf_br_asin_til&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;m=amazon&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr&quot; style=&quot;width:120px;height:240px;&quot; scrolling=&quot;no&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; frameborder=&quot;0&quot;&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;class Fibo&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; public int fibo(int n)&lt;br /&gt;&amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(n &amp;lt;=0)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return -1;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(n == 1)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 0;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(n == 2)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 1;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return (fibo(n-1)+fibo(n-2));&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;}&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/8040908515785859899/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/11/write-java-program-to-find-nth.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/8040908515785859899'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/8040908515785859899'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/11/write-java-program-to-find-nth.html' title='Write a Java Program to find Nth Fibonacci number.'/><author><name>ProgNinja Blue</name><uri>https://plus.google.com/103025513032526183728</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-5015182551688593185</id><published>2012-11-21T16:51:00.004+05:30</published><updated>2012-11-21T16:51:55.954+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Computer Architecture"/><category scheme="http://www.blogger.com/atom/ns#" term="GATE Special"/><title type='text'>Assessing System Performance</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;i&gt;System/Application performance depends not just on the raw speed of the processor,but on the instruction set, choice of implementation language, efficiency of the compiler, and skill of the programming done to implement the application.&amp;nbsp;&lt;/i&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;System Clock&lt;/b&gt; plays most important role in measuring system performance. Operations such as fetching instructions, decoding it, performing arithmetic operations and so on are governed by system clock. At most primitive level speed of clock is dictated by frequency pulse produced by clock. Clock pulse is measured in cycles per second or Hertz (Hz). 1 GHz processor means processor receives 1 billion instructions per second. This is called as clock rate or clock pulse.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The execution of an instruction involves a number of discrete steps, such as&amp;nbsp;fetching the instruction from memory, decoding the various portions of the instruction, loading and storing data, and performing arithmetic and logical operations.&amp;nbsp;Thus, most instructions on most processors require multiple clock cycles to complete. Some instructions may take only a few cycles, while others require dozens. In&amp;nbsp;addition, when pipelining is used, multiple instructions are being executed simultaneously.Thus, a straight comparison of clock speeds on different processors does not&amp;nbsp;tell the whole story about performance.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;A processor is driven by a clock at constant execution rate at frequency &lt;i&gt;&lt;b&gt;f &lt;/b&gt;&lt;/i&gt;&amp;nbsp;or time&amp;nbsp;&lt;span style=&quot;background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19.200000762939453px; text-align: start;&quot;&gt;&lt;b&gt;τ = 1/&lt;/b&gt;&lt;i&gt;f &lt;/i&gt;&lt;/span&gt;.The instruction count, &lt;b&gt;Ic&lt;/b&gt;, for a program is the number of machine instructions executed&amp;nbsp;for that program until it runs to completion or for some defined time interval.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;i&gt;&lt;b&gt;Hence,&amp;nbsp;The processor time T needed to execute a given program can be expressed as&amp;nbsp;&lt;/b&gt;&lt;/i&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;i&gt;&lt;b&gt;T = Ic* CPI *&amp;nbsp;&lt;span style=&quot;font-family: sans-serif; font-size: 13px; line-height: 19.200000762939453px;&quot;&gt;τ&lt;/span&gt;&lt;/b&gt;&lt;/i&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-mzmecDHE_sw/UKy5KhHqL4I/AAAAAAAABg4/AJD5kkIY4VQ/s1600/clock.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-mzmecDHE_sw/UKy5KhHqL4I/AAAAAAAABg4/AJD5kkIY4VQ/s1600/clock.png&quot; height=&quot;363&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;text-align: left;&quot;&gt;Here, CPI is clock cycle per instructions.&amp;nbsp;&lt;/span&gt;If all instructions required the same number of clock&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;cycles, then CPI would be a constant value for a processor.&amp;nbsp;However, on any give&amp;nbsp;processor, the number of clock cycles required varies for different types of instructions, such as load, store, branch, and so on. Let &lt;b&gt;CPI&lt;/b&gt;i&amp;nbsp;be the number of cycles required for instruction type i. and &lt;b&gt;I&lt;/b&gt;i&amp;nbsp;be the number of executed instructions of type i&amp;nbsp;for a given program. Then we can calculate an overall CPI as follows:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;b&gt;&lt;i&gt;SUM(CPIi * Ii)&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;b&gt;&lt;i&gt;CPI = ----------------------&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;b&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Ic&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;We can refine the formulation by recognizing that during the execution of an&amp;nbsp;instruction, part of the work is done by the processor, and part of the time a word is&amp;nbsp;being transferred to or from memory. In this latter case, the time to transfer depends&amp;nbsp;on the memory cycle time, which may be greater than equal to the processor cycle time. We&amp;nbsp;can rewrite the preceding equation as&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;b&gt;&lt;i&gt;T = Ic * [&amp;nbsp;p + (m * k)] * t&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;where p is the number of processor cycles needed to decode and execute the instruction, m is the number of memory references needed, and k is the ratio between memory cycle time and processor cycle time.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The five performance factors in the preceding&amp;nbsp;equation &lt;b&gt;(Ic, p, m, k,&amp;nbsp;&lt;i style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-family: sans-serif; font-size: 13px; line-height: 19.200000762939453px;&quot;&gt;τ&lt;/span&gt;&lt;/i&gt;)&lt;/b&gt; are influenced by four system attributes:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;1. The design of the instruction set (known as instruction set architecture),&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;2. Compiler technology (how effective the compiler is in producing an efficient machine language program from a&amp;nbsp;high-level language program),&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;3. Processor implementation, and&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;4. Cache and memory hierarchy.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;A common measure of performance for a processor is the rate at which instructions are executed, expressed as millions of instructions per second (MIPS), referred to as the MIPS rate. We can express the MIPS rate in terms of the clock rate&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;i&gt;&lt;b&gt;f&lt;/b&gt;&lt;/i&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;b&gt;__________&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;b&gt;CPI * 10^6&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/5015182551688593185/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/11/assessing-system-performance.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/5015182551688593185'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/5015182551688593185'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/11/assessing-system-performance.html' title='Assessing System Performance'/><author><name>Rahul Kumar Bhadani</name><uri>http://www.blogger.com/profile/06501936712694830820</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://2.bp.blogspot.com/-wOCzhuFIvsE/TmGeLZ6RR9I/AAAAAAAAAGQ/-gGr9taE9HI/s220/s.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-mzmecDHE_sw/UKy5KhHqL4I/AAAAAAAABg4/AJD5kkIY4VQ/s72-c/clock.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-6416540686456745265</id><published>2012-08-03T01:37:00.004+05:30</published><updated>2012-12-13T18:02:46.941+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><title type='text'>Stringifying the MACRO!!!!!!!</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;Do you know that you can also stringify the MACRO?&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;Sometimes you want to convert a MACRO arguments into string constant. This is achieved by stringification of MACRO.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&quot;Stringification&quot; means turning a code fragment into a string&amp;nbsp;constant whose contents are the text for the code fragment. &amp;nbsp;For&amp;nbsp;example, stringifying `foo (z)&#39; results in `&quot;foo (z)&quot;&#39;.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;In the C &amp;amp; C++ preprocessor, stringification is an option available when&amp;nbsp;macro arguments are substituted into the macro definition. &amp;nbsp;In the body&amp;nbsp;of the definition, when an argument name appears, the character `#&#39;&amp;nbsp;before the name specifies stringification of the corresponding actual&amp;nbsp;argument when it is substituted at that point in the definition. &amp;nbsp;The&amp;nbsp;same argument may be substituted in other places in the definition&amp;nbsp;without stringification if the argument name appears in those places&amp;nbsp;with no `#&#39;.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&lt;i&gt;But note that t&lt;/i&gt;&lt;span style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;i&gt;here is no way to combine an argument with surrounding text and stringify it all together. Instead, you can write a series of adjacent string constants and stringified arguments. The preprocessor will replace the stringified arguments with string constants. The C compiler will then combine all the adjacent string constants into one long strin&lt;/i&gt;g.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;b style=&quot;font-family: inherit;&quot;&gt;Here is an example of a macro definition that uses stringification:&lt;/b&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;span style=&quot;font-size: smaller; text-align: -webkit-auto;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: smaller; text-align: -webkit-auto;&quot;&gt; #define WARN_IF(EXP) \&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;pre class=&quot;smallexample&quot; style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;pre style=&quot;font-size: smaller;&quot;&gt;     do { if (EXP) \&lt;br /&gt;             fprintf (stderr, &quot;Warning: &quot; #EXP &quot;\n&quot;); } \&lt;br /&gt;     while (0)&lt;/pre&gt;&lt;pre style=&quot;font-size: smaller;&quot;&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-size: smaller;&quot;&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;All leading and trailing whitespace in text being stringified is ignored. &lt;/span&gt;&lt;/pre&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;Any sequence of whitespace in the middle of the text is converted to a single space in the stringified result.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;Comments are replaced by white space long before stringification happens,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;so they never appear in stringified text.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;There is no way to convert a macro argument into a character constant.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif; text-align: justify;&quot;&gt;If you want to stringify the result of expansion of a macro argument, you have to use two levels of macros.&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;Stringification in C involves more than putting double-quote characters around the fragment.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif; text-align: justify;&quot;&gt;The preprocessor backslash-escapes the quotes surrounding embedded string constants, and all backslashes within string and character constants, in order to get a valid C string constant with the proper contents. Thus, stringifying p = &quot;foo\n&quot;; results in &quot;p = \&quot;foo\\n\&quot;;&quot;. However, backslashes that are not inside string or character constants are not duplicated: `\n&#39; by itself stringifies to &quot;\n&quot;.&lt;/span&gt;&lt;br /&gt;&lt;pre style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; text-align: justify;&quot;&gt;The following example prints the text &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; text-align: justify;&quot;&gt;[now is the time]&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;now&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt; then&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;is&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt; was&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;print(stuf&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;f)&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt; std::cout&amp;lt;&amp;lt;&quot;[&quot;#stuff &quot;]\n&quot;&lt;/span&gt;&lt;/pre&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;print(now is the time)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/6416540686456745265/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/08/stringifying-macro.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/6416540686456745265'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/6416540686456745265'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/08/stringifying-macro.html' title='Stringifying the MACRO!!!!!!!'/><author><name>ProgNinja Blue</name><uri>https://plus.google.com/103025513032526183728</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-7611261266950345567</id><published>2012-07-13T17:22:00.004+05:30</published><updated>2012-12-13T18:07:34.020+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><title type='text'>enum in C and C++</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;The C/C++ enumeration syntax exists to support the use of human readable character names to support a specific list of available values for the specified variable. This is enabled in C and C++ as a set of named integer constants. This can be expressed as a C or C++ enumerated type &quot;enum&quot;. Both C and C++ use the same enumeration syntax.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-align: -webkit-auto;&quot;&gt;You could use&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;text-align: -webkit-auto;&quot;&gt;enum&lt;/span&gt;&lt;span style=&quot;text-align: -webkit-auto;&quot;&gt;&amp;nbsp;as below.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;        enum week { Mon=1, Tue, Wed, Thu, Fri Sat, Sun} days;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Here is a code snippets in C++ that define a variable of type enum.&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;main()&lt;br /&gt;{&lt;br /&gt;   enum&lt;br /&gt;   {&lt;br /&gt;      monday, tuesday, wednesday, thursday, friday, saturday, sunday&lt;br /&gt;   } day;&lt;br /&gt;&lt;br /&gt;   day = wednesday;&lt;br /&gt;&lt;br /&gt;   if(day == saturday || day == sunday)&lt;br /&gt;      cout &amp;lt;&amp;lt; &quot;Day is a weekend day&quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;   else if(day == wednesday)&lt;br /&gt;      cout &amp;lt;&amp;lt; &quot;Day is hump day - middle of the work week&quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;You can access enum members directly by writing&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;printf(&quot;%d&quot;,monday);&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;in C&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;or &lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;cout&amp;lt;&amp;lt;monday;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;in C++.&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;We can also create a enum type of which we can declare variables as and when desired:&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;main()&lt;br /&gt;{&lt;br /&gt;   enum TEENS&lt;br /&gt;   {&lt;br /&gt;      thirteen = 10,&lt;br /&gt;      fourteen,&lt;br /&gt;      fifteen,&lt;br /&gt;      sixteen,&lt;br /&gt;      seventeen,&lt;br /&gt;      eighteen,&lt;br /&gt;      nineteen&lt;br /&gt;   } ;&lt;br /&gt;&lt;br /&gt;   TEENS teen = seventeen;&lt;br /&gt;&lt;br /&gt;   if(teen == seventeen)&lt;br /&gt;      cout &amp;lt;&amp;lt; seventeen &amp;lt;&amp;lt; endl;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;or&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;#include &amp;lt;iostream&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;using namespace std;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;main()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&amp;nbsp; &amp;nbsp;typedef enum&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&amp;nbsp; &amp;nbsp;{&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; thirteen = 10,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; fourteen,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; fifteen,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; sixteen,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; seventeen,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; eighteen,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; nineteen&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&amp;nbsp; &amp;nbsp;} TEENS;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&amp;nbsp; &amp;nbsp;TEENS teen = seventeen;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&amp;nbsp; &amp;nbsp;if(teen == seventeen)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; seventeen &amp;lt;&amp;lt; endl;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Now question is why to prefer enum over #define.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Here are few reasons :&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;1.&amp;nbsp;&lt;span style=&quot;text-align: left;&quot;&gt;&lt;i&gt;Prefer Enums Over #define Macros When You Need a Fixed Set of Values&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-align: left;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;#define JAN 1&lt;br /&gt;#define FEB 2&lt;br /&gt;//...&lt;br /&gt;#define DEC 12&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-align: left;&quot;&gt;Enum types are a significantly better choice:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt; //file enums.h&lt;br /&gt;enum Months {&lt;br /&gt;//a list of enumerators:&lt;br /&gt;Jan,&lt;br /&gt;Feb,&lt;br /&gt;//...&lt;br /&gt;Dec };&lt;br /&gt;enum Days {&lt;br /&gt;Sun,&lt;br /&gt;Mon,&lt;br /&gt;//...&lt;br /&gt;};&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;One more point to note is that C++ compiler has strong type check for enum where as C compiler doesnt.&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;Here in our example below: &lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;//using namespace std;&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;   typedef enum&lt;br /&gt;   {&lt;br /&gt;      thirteen = 10,&lt;br /&gt;      fourteen,&lt;br /&gt;      fifteen,&lt;br /&gt;      sixteen,&lt;br /&gt;      seventeen,&lt;br /&gt;      eighteen,&lt;br /&gt;      nineteen&lt;br /&gt;   } TEENS;&lt;br /&gt;&lt;br /&gt;   TEENS teen=10;&lt;br /&gt;      printf(&quot;%d\n%d&quot;,seventeen,teen);&lt;br /&gt;        return 0;&lt;br /&gt;}&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;we are directly assigning 10 to teen and C compiler compiles it without giving an error and gives output &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;14&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;10&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;where as in C++ with similar code: &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;i&gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;   typedef enum&lt;br /&gt;   {&lt;br /&gt;      thirteen = 10,&lt;br /&gt;      fourteen,&lt;br /&gt;      fifteen,&lt;br /&gt;      sixteen,&lt;br /&gt;      seventeen,&lt;br /&gt;      eighteen,&lt;br /&gt;      nineteen&lt;br /&gt;   } TEENS;&lt;br /&gt;&lt;br /&gt;   TEENS teen=10;&lt;br /&gt;   cout&amp;lt;&amp;lt;seventeen&amp;lt;&amp;lt;teen;&lt;br /&gt;   return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;gives error : &lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;enum.cpp:17: error: invalid conversion from int to main()::TEENS&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;With C++ &amp;nbsp;Compiler, strong type check gives much advantage.&amp;nbsp;&lt;span style=&quot;text-align: -webkit-auto;&quot;&gt;The compiler checks that an enum is always assigned a valid value (one of the enumerators in the enum&#39;s definition and no other). Enum types behave like any other built-in type so you can use them to overload functions:&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-align: -webkit-auto;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-align: -webkit-auto;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-align: -webkit-auto;&quot;&gt;#include enums.h&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-align: -webkit-auto;&quot;&gt;bool func(Months month); //1&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-align: -webkit-auto;&quot;&gt;bool func(Days day);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//2&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-align: -webkit-auto;&quot;&gt;void main() {&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-align: -webkit-auto;&quot;&gt;Days day = Sun; //Type Safety. Mind that day = 1 is illegal&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-align: -webkit-auto;&quot;&gt;&lt;/span&gt;&lt;div style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-align: -webkit-auto;&quot;&gt;Months month = Feb;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-align: -webkit-auto;&quot;&gt;&lt;div style=&quot;text-align: -webkit-auto;&quot;&gt;bool b = func(day); // func() #1 is called&lt;/div&gt;&lt;div style=&quot;text-align: -webkit-auto;&quot;&gt;b = func(month); //now func() #2 is called&lt;/div&gt;&lt;div style=&quot;text-align: -webkit-auto;&quot;&gt;}&lt;/div&gt;&lt;div style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: -webkit-auto;&quot;&gt;This feature also eliminates silly mistakes like this:&lt;/div&gt;&lt;div style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: -webkit-auto;&quot;&gt;bool b= func(50); //If we used #defines, this would pass unnoticed.&lt;/div&gt;&lt;div style=&quot;text-align: -webkit-auto;&quot;&gt;//Enums ensure that this mistake is detected at&lt;/div&gt;&lt;div style=&quot;text-align: -webkit-auto;&quot;&gt;//compile time&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-align: -webkit-auto;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif;&quot;&gt;&lt;span style=&quot;text-align: -webkit-auto; white-space: normal;&quot;&gt;2.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;i&gt;C++ enums are very efficient because they are automatically converted by the compiler to plain ints. Furthermore, an enum in C++ needn&#39;t be identical in size to sizeof(int). As a result, the compiler may optimize memory usage by storing the enumerators list in units smaller than int, e.g., short or char. There is also the possibility of storing the enum&#39;s value on a machine register, which may considerably increase performance even more.&lt;/i&gt;&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Georgia, Times New Roman, serif; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/7611261266950345567/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/07/enum-in-c-and-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/7611261266950345567'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/7611261266950345567'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/07/enum-in-c-and-c.html' title='enum in C and C++'/><author><name>ProgNinja Blue</name><uri>https://plus.google.com/103025513032526183728</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-7096505429615278217</id><published>2012-07-11T18:07:00.001+05:30</published><updated>2012-07-11T18:07:19.222+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><title type='text'>Do you know about  #pragma pack()   ?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;&lt;h3 style=&quot;border-bottom-color: rgb(0, 0, 128); border-bottom-style: solid; border-bottom-width: 1px; font-family: verdana, arial, helvetica, sans-serif; margin-bottom: 5px; text-align: justify;&quot;&gt;&lt;span style=&quot;color: #999999; font-size: x-small;&quot;&gt;Pragma directive (#pragma)&lt;/span&gt;&lt;/h3&gt;&lt;span style=&quot;color: #999999;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;This directive is used to specify diverse options to the compiler. These options are specific for the platform and the compiler you use. Consult the manual or the reference of your compiler for more information on the possible parameters that you can define with&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;background-color: white; font-size: 12px; text-align: -webkit-auto;&quot;&gt;#pragma&lt;/tt&gt;&lt;span style=&quot;background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;If the compiler does not support a specific argument for&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;background-color: white; font-size: 12px; text-align: -webkit-auto;&quot;&gt;#pragma&lt;/tt&gt;&lt;span style=&quot;background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;, it is ignored - no error is generated.&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;Basically the compiler unless otherwise directed will line up structure members on&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;2 byte or 4 byte boundaries - this makes it easier and faster for the processor to handle.&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;So the structure contains secret padding bytes to make this happen.&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;The pragma pack directive allows you to change this alignment scheme.&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Some things (particularly in relation to hardware) do not have the luxury to waste bytes like&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;this and they send their data in an exact fit.&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;This means that it is not wise to read data from a hardware device directly into a normal structure.&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;If you have want to read data that is an exact fit into a structure - you can tell the compiler&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;to make the structure an exact fit;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;table class=&quot;snippet&quot; style=&quot;color: black; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: justify;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rownum&quot; style=&quot;color: #a0a0a0; min-width: 20px; text-align: right; vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;2&lt;br /&gt;3&lt;br /&gt;4&lt;br /&gt;5&lt;br /&gt;6&lt;br /&gt;7&lt;br /&gt;8&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;source&quot; style=&quot;background-color: #efefff; background-position: initial initial; background-repeat: initial initial; border: 1px solid rgb(192, 192, 208); vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#pragma pack(push, 1) &lt;/dfn&gt;&lt;cite style=&quot;color: #007000; font-style: normal;&quot;&gt;// exact fit - no padding&lt;/cite&gt;&lt;br /&gt;&lt;var style=&quot;color: #0000b0; font-style: normal;&quot;&gt;struct&lt;/var&gt; MyStruct&lt;br /&gt;{&lt;br /&gt;  &lt;var style=&quot;color: #0000b0; font-style: normal;&quot;&gt;char&lt;/var&gt; b; &lt;br /&gt;  &lt;var style=&quot;color: #0000b0; font-style: normal;&quot;&gt;int&lt;/var&gt; a; &lt;br /&gt;  &lt;var style=&quot;color: #0000b0; font-style: normal;&quot;&gt;int&lt;/var&gt; array[2];&lt;br /&gt;};&lt;br /&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#pragma pack(pop) &lt;/dfn&gt;&lt;cite style=&quot;color: #007000; font-style: normal;&quot;&gt;//back to whatever the previous packing mode was &lt;/cite&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;Without the pragma directive, the size of the structure is 16 bytes - with the packing of 1 - the size is 13 bytes.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/7096505429615278217/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/07/do-you-know-about-pragma-pack.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/7096505429615278217'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/7096505429615278217'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/07/do-you-know-about-pragma-pack.html' title='Do you know about  #pragma pack()   ?'/><author><name>ProgNinja Blue</name><uri>https://plus.google.com/103025513032526183728</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-9082475515321902514</id><published>2012-07-11T12:04:00.000+05:30</published><updated>2012-07-11T12:04:35.950+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><title type='text'>Preprocessor directives : #ifdef, #ifndef, #if, #endif, #else and #elif</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white; font-family: verdana, arial, helvetica, sans-serif; text-align: -webkit-auto;&quot;&gt;&lt;b&gt;Conditional inclusions (#ifdef, #ifndef, #if, #endif, #else and #elif)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white; font-family: verdana, arial, helvetica, sans-serif; text-align: -webkit-auto;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;These directives allow to include or discard part of the code of a program if a certain condition is met.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;tt style=&quot;font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;tt style=&quot;background-color: white;&quot;&gt;#ifdef&lt;/tt&gt;&lt;span style=&quot;background-color: white; font-family: verdana, arial, helvetica, sans-serif;&quot;&gt;&amp;nbsp;allows a section of a program to be compiled only if the macro that is specified as the parameter has been defined, no matter which its value is. For example:&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;/tt&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;auto&quot; style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; margin: 0px; text-align: -webkit-auto;&quot;&gt;&lt;table class=&quot;snippet&quot; style=&quot;color: black; font-size: 12px; text-align: justify;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rownum&quot; style=&quot;color: #a0a0a0; min-width: 20px; text-align: right; vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;1&lt;br /&gt;2&lt;br /&gt;3&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;source&quot; style=&quot;background-color: #efefff; background-position: initial initial; background-repeat: initial initial; border: 1px solid rgb(192, 192, 208); vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;&lt;span style=&quot;color: #274e13;&quot;&gt;&lt;dfn style=&quot;font-style: normal;&quot;&gt;#ifdef TABLE_SIZE&lt;/dfn&gt;&lt;br /&gt;&lt;var style=&quot;font-style: normal;&quot;&gt;int&lt;/var&gt; table[TABLE_SIZE];&lt;br /&gt;&lt;dfn style=&quot;font-style: normal;&quot;&gt;#endif  &lt;/dfn&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;In this case, the line of code&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;background-color: white;&quot;&gt;int table[TABLE_SIZE];&lt;/tt&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;is only compiled if&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;background-color: white;&quot;&gt;TABLE_SIZE&lt;/tt&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;was previously defined with&lt;/span&gt;&lt;tt style=&quot;background-color: white;&quot;&gt;#define&lt;/tt&gt;&lt;span style=&quot;background-color: white;&quot;&gt;, independently of its value. If it was not defined, that line will not be included in the program compilation.&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;tt style=&quot;font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;tt style=&quot;background-color: white;&quot;&gt;#ifndef&lt;/tt&gt;&lt;span style=&quot;background-color: white; font-family: verdana, arial, helvetica, sans-serif;&quot;&gt;&amp;nbsp;serves for the exact opposite: the code between&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;background-color: white;&quot;&gt;#ifndef&lt;/tt&gt;&lt;span style=&quot;background-color: white; font-family: verdana, arial, helvetica, sans-serif;&quot;&gt;&amp;nbsp;and&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;background-color: white;&quot;&gt;#endif&lt;/tt&gt;&lt;span style=&quot;background-color: white; font-family: verdana, arial, helvetica, sans-serif;&quot;&gt;&amp;nbsp;directives is only compiled if the specified identifier has not been previously defined. For example:&lt;/span&gt;&lt;/div&gt;&lt;/tt&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;auto&quot; style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; margin: 0px; text-align: -webkit-auto;&quot;&gt;&lt;table class=&quot;snippet&quot; style=&quot;color: black; font-size: 12px; text-align: justify;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rownum&quot; style=&quot;color: #a0a0a0; min-width: 20px; text-align: right; vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;1&lt;br /&gt;2&lt;br /&gt;3&lt;br /&gt;4&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;source&quot; style=&quot;background-color: #efefff; background-position: initial initial; background-repeat: initial initial; border: 1px solid rgb(192, 192, 208); vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;&lt;span style=&quot;color: #741b47;&quot;&gt;&lt;dfn style=&quot;font-style: normal;&quot;&gt;#ifndef TABLE_SIZE&lt;/dfn&gt;&lt;br /&gt;&lt;dfn style=&quot;font-style: normal;&quot;&gt;#define TABLE_SIZE 100&lt;/dfn&gt;&lt;br /&gt;&lt;dfn style=&quot;font-style: normal;&quot;&gt;#endif&lt;/dfn&gt;&lt;br /&gt;&lt;var style=&quot;font-style: normal;&quot;&gt;int&lt;/var&gt; table[TABLE_SIZE];&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;In this case, if when arriving at this piece of code, the&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;background-color: white;&quot;&gt;TABLE_SIZE&lt;/tt&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;macro has not been defined yet, it would be defined to a value of 100. If it already existed it would keep its previous value since the&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;background-color: white;&quot;&gt;#define&lt;/tt&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;directive would not be executed.&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;The&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;font-size: 12px; text-align: -webkit-auto;&quot;&gt;#if&lt;/tt&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;font-size: 12px; text-align: -webkit-auto;&quot;&gt;#else&lt;/tt&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;and&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;font-size: 12px; text-align: -webkit-auto;&quot;&gt;#elif&lt;/tt&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;(i.e., &quot;else if&quot;) directives serve to specify some condition to be met in order for the portion of code they surround to be compiled. The condition that follows&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;font-size: 12px; text-align: -webkit-auto;&quot;&gt;#if&lt;/tt&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;or&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;font-size: 12px; text-align: -webkit-auto;&quot;&gt;#elif&lt;/tt&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;can only evaluate constant expressions, including macro expressions. For example:&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;auto&quot; style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; margin: 0px; text-align: -webkit-auto;&quot;&gt;&lt;table class=&quot;snippet&quot; style=&quot;color: black; font-size: 12px; text-align: justify;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rownum&quot; style=&quot;color: #a0a0a0; min-width: 20px; text-align: right; vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;1&lt;br /&gt;2&lt;br /&gt;3&lt;br /&gt;4&lt;br /&gt;5&lt;br /&gt;6&lt;br /&gt;7&lt;br /&gt;8&lt;br /&gt;9&lt;br /&gt;10&lt;br /&gt;11&lt;br /&gt;12&lt;br /&gt;13&lt;br /&gt;14&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;source&quot; style=&quot;background-color: #efefff; background-position: initial initial; background-repeat: initial initial; border: 1px solid rgb(192, 192, 208); vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#if TABLE_SIZE&amp;gt;200&lt;/dfn&gt;&lt;br /&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#undef TABLE_SIZE&lt;/dfn&gt;&lt;br /&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#define TABLE_SIZE 200&lt;/dfn&gt;&lt;br /&gt; &lt;br /&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#elif TABLE_SIZE&amp;lt;50&lt;/dfn&gt;&lt;br /&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#undef TABLE_SIZE&lt;/dfn&gt;&lt;br /&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#define TABLE_SIZE 50&lt;/dfn&gt;&lt;br /&gt; &lt;br /&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#else&lt;/dfn&gt;&lt;br /&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#undef TABLE_SIZE&lt;/dfn&gt;&lt;br /&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#define TABLE_SIZE 100&lt;/dfn&gt;&lt;br /&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#endif&lt;/dfn&gt;&lt;br /&gt; &lt;br /&gt;&lt;var style=&quot;color: #0000b0; font-style: normal;&quot;&gt;int&lt;/var&gt; table[TABLE_SIZE]; &lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Notice how the whole structure of&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;background-color: white;&quot;&gt;#if&lt;/tt&gt;&lt;span style=&quot;background-color: white;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;background-color: white;&quot;&gt;#elif&lt;/tt&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;and&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;background-color: white;&quot;&gt;#else&lt;/tt&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;chained directives ends with&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;background-color: white;&quot;&gt;#endif&lt;/tt&gt;&lt;span style=&quot;background-color: white;&quot;&gt;.&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;The behavior of&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;background-color: white;&quot;&gt;#ifdef&lt;/tt&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;and&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;background-color: white;&quot;&gt;#ifndef&lt;/tt&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;can also be achieved by using the special operators&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;background-color: white;&quot;&gt;defined&lt;/tt&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;and&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;background-color: white;&quot;&gt;!defined&lt;/tt&gt;&lt;span style=&quot;background-color: white;&quot;&gt;respectively in any&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;background-color: white;&quot;&gt;#if&lt;/tt&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;or&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;background-color: white;&quot;&gt;#elif&lt;/tt&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;directive:&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;auto&quot; style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; margin: 0px; text-align: -webkit-auto;&quot;&gt;&lt;table class=&quot;snippet&quot; style=&quot;color: black; font-size: 12px; text-align: justify;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rownum&quot; style=&quot;color: #a0a0a0; min-width: 20px; text-align: right; vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;1&lt;br /&gt;2&lt;br /&gt;3&lt;br /&gt;4&lt;br /&gt;5&lt;br /&gt;6&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;source&quot; style=&quot;background-color: #efefff; background-position: initial initial; background-repeat: initial initial; border: 1px solid rgb(192, 192, 208); vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#if !defined TABLE_SIZE&lt;/dfn&gt;&lt;br /&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#define TABLE_SIZE 100&lt;/dfn&gt;&lt;br /&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#elif defined ARRAY_SIZE&lt;/dfn&gt;&lt;br /&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#define TABLE_SIZE ARRAY_SIZE&lt;/dfn&gt;&lt;br /&gt;&lt;var style=&quot;color: #0000b0; font-style: normal;&quot;&gt;int&lt;/var&gt; table[TABLE_SIZE];&lt;br /&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#endif &lt;/dfn&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3 style=&quot;border-bottom-color: rgb(0, 0, 128); border-bottom-style: solid; border-bottom-width: 1px; font-family: verdana, arial, helvetica, sans-serif; margin-bottom: 5px; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Line control (#line)&lt;/span&gt;&lt;/h3&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;When we compile a program and some error happens during the compiling process, the compiler shows an error message with references to the name of the file where the error happened and a line number, so it is easier to find the code generating the error.&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;The&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;background-color: white;&quot;&gt;#line&lt;/tt&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;directive allows us to control both things, the line numbers within the code files as well as the file name that we want that appears when an error takes place. Its format is:&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;tt style=&quot;font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;#line number &quot;filename&quot;&lt;/span&gt;&lt;/div&gt;&lt;/tt&gt;&lt;span style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Where&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;background-color: white;&quot;&gt;number&lt;/tt&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;is the new line number that will be assigned to the next code line. The line numbers of successive lines will be increased one by one from this point on.&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;tt style=&quot;font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;tt style=&quot;background-color: white;&quot;&gt;&quot;filename&quot;&lt;/tt&gt;&lt;span style=&quot;background-color: white; font-family: verdana, arial, helvetica, sans-serif;&quot;&gt;&amp;nbsp;is an optional parameter that allows to redefine the file name that will be shown. For example:&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;/tt&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;auto&quot; style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; margin: 0px; text-align: -webkit-auto;&quot;&gt;&lt;table class=&quot;snippet&quot; style=&quot;color: black; font-size: 12px; text-align: justify;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rownum&quot; style=&quot;color: #a0a0a0; min-width: 20px; text-align: right; vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;1&lt;br /&gt;2&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;source&quot; style=&quot;background-color: #efefff; background-position: initial initial; background-repeat: initial initial; border: 1px solid rgb(192, 192, 208); vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#line 20 &quot;assigning variable&quot;&lt;/dfn&gt;&lt;br /&gt;&lt;var style=&quot;color: #0000b0; font-style: normal;&quot;&gt;int&lt;/var&gt; a?; &lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;This code will generate an error that will be shown as error in file&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;background-color: white;&quot;&gt;&quot;assigning variable&quot;&lt;/tt&gt;&lt;span style=&quot;background-color: white;&quot;&gt;, line 20.&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;h3 style=&quot;border-bottom-color: rgb(0, 0, 128); border-bottom-style: solid; border-bottom-width: 1px; font-family: verdana, arial, helvetica, sans-serif; margin-bottom: 5px; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Error directive (#error)&lt;/span&gt;&lt;/h3&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;This directive aborts the compilation process when it is found, generating a compilation the error that can be specified as its parameter:&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;auto&quot; style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; margin: 0px; text-align: -webkit-auto;&quot;&gt;&lt;table class=&quot;snippet&quot; style=&quot;color: black; font-size: 12px; text-align: justify;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rownum&quot; style=&quot;color: #a0a0a0; min-width: 20px; text-align: right; vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;1&lt;br /&gt;2&lt;br /&gt;3&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;source&quot; style=&quot;background-color: #efefff; background-position: initial initial; background-repeat: initial initial; border: 1px solid rgb(192, 192, 208); vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#ifndef __cplusplus&lt;/dfn&gt;&lt;br /&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#error A C++ compiler is required!&lt;/dfn&gt;&lt;br /&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#endif &lt;/dfn&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;This example aborts the compilation process if the macro name&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;background-color: white;&quot;&gt;__cplusplus&lt;/tt&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;is not defined (this macro name is defined by default in all C++ compilers).&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/9082475515321902514/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/07/preprocessor-directives-ifdef-ifndef-if.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/9082475515321902514'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/9082475515321902514'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/07/preprocessor-directives-ifdef-ifndef-if.html' title='Preprocessor directives : #ifdef, #ifndef, #if, #endif, #else and #elif'/><author><name>ProgNinja Blue</name><uri>https://plus.google.com/103025513032526183728</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-5775886348610029486</id><published>2012-07-11T11:36:00.001+05:30</published><updated>2012-07-11T11:38:49.731+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><title type='text'>Preprocessor directives : #define and #undef</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;Preprocessor directives are lines included in the code of our programs that are not program statements but directives for the preprocessor. These lines are always preceded by a hash sign (&lt;/span&gt;&lt;tt style=&quot;font-size: 12px; text-align: -webkit-auto;&quot;&gt;#&lt;/tt&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;). The preprocessor is executed before the actual compilation of code begins, therefore the preprocessor digests all these directives before any code is generated by the statements.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;These preprocessor directives extend only across a single line of code. As soon as a newline character is found, the preprocessor directive is considered to end. No semicolon (;) is expected at the end of a preprocessor directive. The only way a preprocessor directive can extend through more than one line is by preceding the newline character at the end of the line by a backslash (&lt;/span&gt;&lt;tt style=&quot;font-size: 12px; text-align: -webkit-auto;&quot;&gt;\&lt;/tt&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;).&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3 style=&quot;border-bottom-color: rgb(0, 0, 128); border-bottom-style: solid; border-bottom-width: 1px; font-family: verdana, arial, helvetica, sans-serif; margin-bottom: 5px; text-align: -webkit-auto;&quot;&gt;  macro definitions (#define, #undef)&lt;/h3&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;To define preprocessor macros we can use&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;font-size: 12px; text-align: -webkit-auto;&quot;&gt;#define&lt;/tt&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;. Its format is:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;tt style=&quot;font-size: 12px; text-align: -webkit-auto;&quot;&gt;#define identifier replacement&lt;/tt&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;When the preprocessor encounters this directive, it replaces any occurrence of&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;font-size: 12px; text-align: -webkit-auto;&quot;&gt;identifier&lt;/tt&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;in the rest of the code by&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;font-size: 12px; text-align: -webkit-auto;&quot;&gt;replacement&lt;/tt&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;. This&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;font-size: 12px; text-align: -webkit-auto;&quot;&gt;replacement&lt;/tt&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;can be an expression, a statement, a block or simply anything. The preprocessor does not understand C++, it simply replaces any occurrence of&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;font-size: 12px; text-align: -webkit-auto;&quot;&gt;identifier&lt;/tt&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;by&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;font-size: 12px; text-align: -webkit-auto;&quot;&gt;replacement&lt;/tt&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;auto&quot; style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; margin: 0px; text-align: -webkit-auto;&quot;&gt;&lt;table class=&quot;snippet&quot; style=&quot;color: black; font-size: 12px;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rownum&quot; style=&quot;color: #a0a0a0; min-width: 20px; text-align: right; vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;1&lt;br /&gt;2&lt;br /&gt;3&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;source&quot; style=&quot;background-color: #efefff; background-position: initial initial; background-repeat: initial initial; border: 1px solid rgb(192, 192, 208); vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#define TABLE_SIZE 100&lt;/dfn&gt;&lt;br /&gt;&lt;var style=&quot;color: #0000b0; font-style: normal;&quot;&gt;int&lt;/var&gt; table1[TABLE_SIZE];&lt;br /&gt;&lt;var style=&quot;color: #0000b0; font-style: normal;&quot;&gt;int&lt;/var&gt; table2[TABLE_SIZE]; &lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;After the preprocessor has replaced&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;font-size: 12px; text-align: -webkit-auto;&quot;&gt;TABLE_SIZE&lt;/tt&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;, the code becomes equivalent to:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;auto&quot; style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; margin: 0px; text-align: -webkit-auto;&quot;&gt;&lt;table class=&quot;snippet&quot; style=&quot;color: black; font-size: 12px;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rownum&quot; style=&quot;color: #a0a0a0; min-width: 20px; text-align: right; vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;1&lt;br /&gt;2&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;source&quot; style=&quot;background-color: #efefff; background-position: initial initial; background-repeat: initial initial; border: 1px solid rgb(192, 192, 208); vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;&lt;var style=&quot;color: #0000b0; font-style: normal;&quot;&gt;int&lt;/var&gt; table1[100];&lt;br /&gt;&lt;var style=&quot;color: #0000b0; font-style: normal;&quot;&gt;int&lt;/var&gt; table2[100]; &lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;This use of #define as constant definer is already known by us from previous tutorials, but&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;font-size: 12px; text-align: -webkit-auto;&quot;&gt;#define&lt;/tt&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;can work also with parameters to define function macros:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;auto&quot; style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; margin: 0px; text-align: -webkit-auto;&quot;&gt;&lt;table class=&quot;snippet&quot; style=&quot;color: black; font-size: 12px;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rownum&quot; style=&quot;color: #a0a0a0; min-width: 20px; text-align: right; vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;source&quot; style=&quot;background-color: #efefff; background-position: initial initial; background-repeat: initial initial; border: 1px solid rgb(192, 192, 208); vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#define getmax(a,b) a&amp;gt;b?a:b &lt;/dfn&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;This would replace any occurrence of&amp;nbsp;&lt;/span&gt;&lt;tt style=&quot;font-size: 12px; text-align: -webkit-auto;&quot;&gt;getmax&lt;/tt&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;followed by two arguments by the replacement expression, but also replacing each argument by its identifier, exactly as you would expect if it was a function:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;auto&quot; style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; margin: 0px; text-align: -webkit-auto;&quot;&gt;&lt;table class=&quot;split&quot; style=&quot;color: black; font-size: 12px; width: 728px;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rownum&quot; style=&quot;color: #a0a0a0; min-width: 20px; text-align: right; vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;1&lt;br /&gt;2&lt;br /&gt;3&lt;br /&gt;4&lt;br /&gt;5&lt;br /&gt;6&lt;br /&gt;7&lt;br /&gt;8&lt;br /&gt;9&lt;br /&gt;10&lt;br /&gt;11&lt;br /&gt;12&lt;br /&gt;13&lt;br /&gt;14&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;source&quot; style=&quot;background-color: #efefff; background-position: initial initial; background-repeat: initial initial; border: 1px solid rgb(192, 192, 208); vertical-align: top; width: 351px;&quot;&gt;&lt;pre&gt;&lt;code&gt;&lt;cite style=&quot;color: #007000; font-style: normal;&quot;&gt;// function macro&lt;/cite&gt;&lt;br /&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#include &amp;lt;iostream&amp;gt;&lt;/dfn&gt;&lt;br /&gt;&lt;var style=&quot;color: #0000b0; font-style: normal;&quot;&gt;using&lt;/var&gt; &lt;var style=&quot;color: #0000b0; font-style: normal;&quot;&gt;namespace&lt;/var&gt; std;&lt;br /&gt;&lt;br /&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#define getmax(a,b) ((a)&amp;gt;(b)?(a):(b))&lt;/dfn&gt;&lt;br /&gt;&lt;br /&gt;&lt;var style=&quot;color: #0000b0; font-style: normal;&quot;&gt;int&lt;/var&gt; main()&lt;br /&gt;{&lt;br /&gt;  &lt;var style=&quot;color: #0000b0; font-style: normal;&quot;&gt;int&lt;/var&gt; x=5, y;&lt;br /&gt;  y= getmax(x,2);&lt;br /&gt;  cout &amp;lt;&amp;lt; y &amp;lt;&amp;lt; endl;&lt;br /&gt;  cout &amp;lt;&amp;lt; getmax(7,x) &amp;lt;&amp;lt; endl;&lt;br /&gt;  &lt;var style=&quot;color: #0000b0; font-style: normal;&quot;&gt;return&lt;/var&gt; 0;&lt;br /&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;output&quot; style=&quot;background-color: #e7e7e7; background-position: initial initial; background-repeat: initial initial; border: 1px solid rgb(192, 192, 192); vertical-align: top; width: 339px;&quot;&gt;&lt;pre&gt;&lt;samp&gt;5&lt;br /&gt;7&lt;/samp&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;i&gt;&lt;u&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;Defined macros are not affected by block structure. A macro lasts until it is undefined with the #undef preprocessor directive:&lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;&lt;div class=&quot;auto&quot; style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; margin: 0px; text-align: -webkit-auto;&quot;&gt;&lt;table class=&quot;snippet&quot; style=&quot;color: black; font-size: 12px;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rownum&quot; style=&quot;color: #a0a0a0; min-width: 20px; text-align: right; vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;1&lt;br /&gt;2&lt;br /&gt;3&lt;br /&gt;4&lt;br /&gt;5&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;source&quot; style=&quot;background-color: #efefff; background-position: initial initial; background-repeat: initial initial; border: 1px solid rgb(192, 192, 208); vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#define TABLE_SIZE 100&lt;/dfn&gt;&lt;br /&gt;&lt;var style=&quot;color: #0000b0; font-style: normal;&quot;&gt;int&lt;/var&gt; table1[TABLE_SIZE];&lt;br /&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#undef TABLE_SIZE&lt;/dfn&gt;&lt;br /&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#define TABLE_SIZE 200&lt;/dfn&gt;&lt;br /&gt;&lt;var style=&quot;color: #0000b0; font-style: normal;&quot;&gt;int&lt;/var&gt; table2[TABLE_SIZE];&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: -webkit-auto;&quot;&gt;This would generate the same code as:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;auto&quot; style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; margin: 0px; text-align: -webkit-auto;&quot;&gt;&lt;table class=&quot;snippet&quot; style=&quot;color: black; font-size: 12px;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rownum&quot; style=&quot;color: #a0a0a0; min-width: 20px; text-align: right; vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;1&lt;br /&gt;2&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;source&quot; style=&quot;background-color: #efefff; background-position: initial initial; background-repeat: initial initial; border: 1px solid rgb(192, 192, 208); vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;&lt;var style=&quot;color: #0000b0; font-style: normal;&quot;&gt;int&lt;/var&gt; table1[100];&lt;br /&gt;&lt;var style=&quot;color: #0000b0; font-style: normal;&quot;&gt;int&lt;/var&gt; table2[200];&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;auto&quot; style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; margin: 0px; text-align: -webkit-auto;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;auto&quot; style=&quot;font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; margin: 0px; text-align: -webkit-auto;&quot;&gt;&lt;b&gt;&lt;i&gt;Function macro definitions accept two special operators (&lt;tt&gt;#&lt;/tt&gt;&amp;nbsp;and&amp;nbsp;&lt;tt&gt;##&lt;/tt&gt;) in the replacement sequence:&lt;br /&gt;If the operator&amp;nbsp;&lt;tt&gt;#&lt;/tt&gt;&amp;nbsp;is used before a parameter is used in the replacement sequence, that parameter is replaced by a string literal (as if it were enclosed between double quotes)&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;auto&quot; style=&quot;margin: 0px;&quot;&gt;&lt;table class=&quot;snippet&quot; style=&quot;color: black; font-size: 12px;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rownum&quot; style=&quot;color: #a0a0a0; min-width: 20px; text-align: right; vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;1&lt;br /&gt;2&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;source&quot; style=&quot;background-color: #efefff; background-position: initial initial; background-repeat: initial initial; border: 1px solid rgb(192, 192, 208); vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#define str(x) #x&lt;/dfn&gt;&lt;br /&gt;cout &amp;lt;&amp;lt; str(test);&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;This would be translated into:&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;auto&quot; style=&quot;margin: 0px;&quot;&gt;&lt;table class=&quot;snippet&quot; style=&quot;color: black; font-size: 12px;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rownum&quot; style=&quot;color: #a0a0a0; min-width: 20px; text-align: right; vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;source&quot; style=&quot;background-color: #efefff; background-position: initial initial; background-repeat: initial initial; border: 1px solid rgb(192, 192, 208); vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;cout &amp;lt;&amp;lt; &lt;kbd style=&quot;color: #600030;&quot;&gt;&quot;test&quot;&lt;/kbd&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;The operator&amp;nbsp;&lt;tt&gt;##&lt;/tt&gt;&amp;nbsp;concatenates two arguments leaving no blank spaces between them:&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;auto&quot; style=&quot;margin: 0px;&quot;&gt;&lt;table class=&quot;snippet&quot; style=&quot;color: black; font-size: 12px;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rownum&quot; style=&quot;color: #a0a0a0; min-width: 20px; text-align: right; vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;1&lt;br /&gt;2&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;source&quot; style=&quot;background-color: #efefff; background-position: initial initial; background-repeat: initial initial; border: 1px solid rgb(192, 192, 208); vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;&lt;dfn style=&quot;color: #500070; font-style: normal;&quot;&gt;#define glue(a,b) a ## b&lt;/dfn&gt;&lt;br /&gt;glue(c,out) &amp;lt;&amp;lt; &lt;kbd style=&quot;color: #600030;&quot;&gt;&quot;test&quot;&lt;/kbd&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;This would also be translated into:&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;auto&quot; style=&quot;margin: 0px;&quot;&gt;&lt;table class=&quot;snippet&quot; style=&quot;color: black; font-size: 12px;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rownum&quot; style=&quot;color: #a0a0a0; min-width: 20px; text-align: right; vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;source&quot; style=&quot;background-color: #efefff; background-position: initial initial; background-repeat: initial initial; border: 1px solid rgb(192, 192, 208); vertical-align: top;&quot;&gt;&lt;pre&gt;&lt;code&gt;cout &amp;lt;&amp;lt; &lt;kbd style=&quot;color: #600030;&quot;&gt;&quot;test&quot;&lt;/kbd&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;auto&quot; style=&quot;margin: 0px;&quot;&gt;Because preprocessor replacements happen before any C++ syntax check, macro definitions can be a tricky feature, but be careful: code that relies heavily on complicated macros may seem obscure to other programmers, since the syntax they expect is on many occasions different from the regular expressions programmers expect in C.&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/5775886348610029486/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/07/preprocessor-directives-define-amd.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/5775886348610029486'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/5775886348610029486'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/07/preprocessor-directives-define-amd.html' title='Preprocessor directives : #define and #undef'/><author><name>ProgNinja Blue</name><uri>https://plus.google.com/103025513032526183728</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-6106730012263902411</id><published>2012-06-28T16:39:00.000+05:30</published><updated>2012-12-01T00:14:27.152+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><title type='text'>Methodology to crack pattern problems like constructing a pyramid of stars or  diamond made up of stars.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Have you wondered how to crack problems like generating patterns from C code or Java code ?? Here, I am presenting a methodology to crack simple pattern problems.&lt;br /&gt;&lt;br /&gt;Write an algorithm to generate following pattern:&lt;br /&gt;&amp;nbsp;&lt;span style=&quot;color: magenta;&quot;&gt; &amp;nbsp; &amp;nbsp;*&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: magenta;&quot;&gt;&amp;nbsp; * &amp;nbsp; &amp;nbsp; *&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: magenta;&quot;&gt;* &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;*&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: magenta;&quot;&gt;&amp;nbsp; * &amp;nbsp; &amp;nbsp; *&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: magenta;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; *&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;for n=any odd number say 5.&lt;br /&gt;&lt;br /&gt;To understand the behavior of pattern put them inside grid a follows:&lt;br /&gt;&lt;table border=&quot;1&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&amp;nbsp;&amp;nbsp;&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;4&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;table border=&quot;1&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;*&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;*&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;*&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;*&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;*&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;*&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;*&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;*&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;Now we will check what trend above pattern is following. On close observation we find out that&lt;br /&gt;&lt;br /&gt;upper left edge of pattern follows :&lt;br /&gt;&lt;span &gt;print * if &amp;nbsp;i&amp;lt;=2 and j&amp;lt;=2 and i+j=2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;upper right edge of pattern follows :&lt;br /&gt;&lt;span &gt;print * if &amp;nbsp;i&amp;lt;=2 and j&amp;gt;=2 and j-i=2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;lower left edge of pattern follows :&lt;br /&gt;&lt;span &gt;print * if &amp;nbsp;i&amp;gt;=2 and j&amp;lt;=2 and i-j=2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;upper left edge of pattern follows :&lt;br /&gt;&lt;span &gt;print * if &amp;nbsp;i&amp;gt;=2 and j&amp;gt;=2 and i+j=6&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now following code-snippets can be written to generate above pattern:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;for(j=0;j&amp;lt;n;j++)&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;for(i=0;i&amp;lt;n;i++)&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;if((i&amp;lt;=n/2 &amp;amp;&amp;amp; j&amp;lt;=n/2 &amp;amp;&amp;amp; i+j==n/2)||(i&amp;lt;=n/2 &amp;amp;&amp;amp; j&amp;gt;=n/2 &amp;amp;&amp;amp; j-i==n/2)||(i&amp;gt;=n/2 &amp;amp;&amp;amp; j&amp;lt;=n/2 &amp;amp;&amp;amp; i-j==n/2)||(i&amp;gt;=n/2&amp;amp;&amp;amp; j&amp;gt;=n/2 &amp;amp;&amp;amp; i+j==((n-1)/2)*3))&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;{&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;printf(&quot;*&quot;);&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;else&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;printf(&quot; &quot;);&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;printf(&quot;\n&quot;);&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;Hope you have understood essence of pattern generation. As a assignment, you can generate following pattern :&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;table border=&quot;1&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;*&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;*&lt;/td&gt;&lt;td&gt;*&lt;/td&gt;&lt;td&gt;*&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;*&lt;/td&gt;&lt;td&gt;*&lt;/td&gt;&lt;td&gt;*&lt;/td&gt;&lt;td&gt;*&lt;/td&gt;&lt;td&gt;*&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/6106730012263902411/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/06/methodology-to-crack-pattern-problems.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/6106730012263902411'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/6106730012263902411'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/06/methodology-to-crack-pattern-problems.html' title='Methodology to crack pattern problems like constructing a pyramid of stars or  diamond made up of stars.'/><author><name>Rahul Kumar Bhadani</name><uri>http://www.blogger.com/profile/06501936712694830820</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://2.bp.blogspot.com/-wOCzhuFIvsE/TmGeLZ6RR9I/AAAAAAAAAGQ/-gGr9taE9HI/s220/s.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-2980247511724974084</id><published>2012-06-18T18:19:00.001+05:30</published><updated>2012-06-18T18:19:26.457+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><title type='text'>main( ) function explained</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;A C program starts execution with a function called main( ). The prototype for the main function is&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;int main(int argc , char **argv)&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&amp;nbsp;where argc is the number of command line arguments and argv is an array of pointers to the arguments.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;When a C program is executed by the kernel - by one of the exec functions, a special start up routine is called before the main function is called. The executable program file specifies this routine as the starting address of the program; this is set up the link editor when it is invoked by C compiler. This start up routine takes values from the kernel - the command line arguments and the environment&amp;nbsp; and sets this up so that main function is called.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;A note about exec function:&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;When a process calls the exec functions, that process is completely replaced by a new program and the new program starts executing at its main function. The process ID doesn&#39;t change across exec because a new process is not created; exec mere replaces the current process - its text, data, heap and stack segments with a brand new program from disk.&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/2980247511724974084/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/06/main-function-explained.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/2980247511724974084'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/2980247511724974084'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/06/main-function-explained.html' title='main( ) function explained'/><author><name>ProgNinja Blue</name><uri>https://plus.google.com/103025513032526183728</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-8048443706252285333</id><published>2012-06-18T13:33:00.002+05:30</published><updated>2012-06-18T13:33:30.965+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><title type='text'>Signal Handling in C</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Signals are ways by which a process notify that some conditon(s) has/have occurred. For example divding by zero or segmentation fault are some of events that occurr and it is required to be notified by the process.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;There are three ways to handle signals:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;1. Ignore the signal, though this action is not recommended for signals related with hardware actions such as referncing memory outside address space of memory etc.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;2. Let default action takes place.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;3. Provide a function that gets called as soon as some signal occurrs. This kind of function is known as signal handler.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Note:&amp;nbsp; The signals SIGKILL and SIGSTOP cannot be caught or ignored.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;If the signal signum is delivered to the process, then one of the following happens:&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *a* If the disposition is set to SIG_IGN, then the signal is ignored.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *b*&amp;nbsp; If the disposition is set to SIG_DFL, then the default action associated with the signal (see signal(7)) occurs.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *c*&amp;nbsp; If the disposition is set to a function, then first either the disposition is reset to SIG_DFL, or the signal is blocked and then handler is called with argument signum.&amp;nbsp; If invocation of the handler caused the&amp;nbsp; signal to be blocked, then the signal is unblocked upon return from the handler.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1. Ignoring the signal:&lt;br /&gt;&lt;br /&gt;#include&amp;lt;stdio.h&amp;gt;&lt;br /&gt;#include&amp;lt;stdlib.h&amp;gt;&lt;br /&gt;#include&amp;lt;string.h&amp;gt;&lt;br /&gt;#include&amp;lt;sys/wait.h&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;int main(int argc, char **argv)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(signal(SIGINT,SIG_IGN)==SIG_ERR)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&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; perror(&quot;signal error&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while(1)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&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; printf(&quot;\nHello!! You cant terminate me by pressing ctrl-C !! ;) \n&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. Handling the signal&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#include&amp;lt;stdio.h&amp;gt;&lt;br /&gt;#include&amp;lt;stdlib.h&amp;gt;&lt;br /&gt;#include&amp;lt;string.h&amp;gt;&lt;br /&gt;#include&amp;lt;sys/wait.h&amp;gt;&lt;br /&gt;int flag=0;&lt;br /&gt;void sighandler(int signum)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;\nSignal Handled ....\n Exiting...\n&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; flag=1;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int main(int argc, char **argv)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(signal(SIGINT,sighandler)==SIG_ERR)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&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; perror(&quot;signal error&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while(flag!=1)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&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; printf(&quot;\nHello!! Press ctrl-C to be caught by Handler!! ;) \n&quot;);&lt;br /&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; sleep(1);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3. If we dont state signal( ) function or write SIG_DFL instead of SIG_IGN then default action takes place. &lt;br /&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/8048443706252285333/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/06/signal-handling-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/8048443706252285333'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/8048443706252285333'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/06/signal-handling-in-c.html' title='Signal Handling in C'/><author><name>ProgNinja Blue</name><uri>https://plus.google.com/103025513032526183728</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-2183811454360324186</id><published>2012-06-18T12:53:00.001+05:30</published><updated>2012-06-18T12:53:12.642+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><title type='text'>Error Hadling in C using linux system calls</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;C being a system programming language allows you handle error at lower levels or system levels. Most functions return -1 or NULL on error and set &lt;i&gt;errno &lt;/i&gt;with an error code which is a global variable defined in #include&amp;lt;errno.h&amp;gt;.&lt;br /&gt;&lt;br /&gt;As a good C programmer, we can always check errors and take appropriate actions as and when required. As a good practice, developer should set errno to 0 at the time of  initialization of the program. A value of 0 indicates that there is no  error in the program.&lt;br /&gt;&lt;br /&gt;There are two functions defined in C to get error messages associated with &lt;i&gt;errno&lt;/i&gt; .&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000;&quot;&gt;1. perror( string ): &lt;/span&gt;perror return text message containing string passed to it as an argument followed by colon followed by textual message associated with an &lt;i&gt;errno &lt;/i&gt;value.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000;&quot;&gt;2. strerror(int errnum ): &lt;/span&gt;It returns pointer to textual represent of current errno value.&lt;br /&gt;&lt;br /&gt;#include&amp;lt;stdio.h&amp;gt;&lt;br /&gt;#include&amp;lt;string.h&amp;gt;&lt;br /&gt;#include&amp;lt;errno.h&amp;gt;&lt;br /&gt;int main(int argc,char **argv)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fprintf(stderr,&quot;EACCES:%s\n&quot;,strerror(EACCES));&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; errno=ENOENT;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; perror(argv[0]);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/2183811454360324186/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/06/error-hadling-in-c-using-linux-system.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/2183811454360324186'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/2183811454360324186'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/06/error-hadling-in-c-using-linux-system.html' title='Error Hadling in C using linux system calls'/><author><name>ProgNinja Blue</name><uri>https://plus.google.com/103025513032526183728</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-4649350174088602993</id><published>2012-06-08T13:33:00.001+05:30</published><updated>2012-06-08T14:29:54.175+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><category scheme="http://www.blogger.com/atom/ns#" term="Computer Network"/><title type='text'>Steps to write a UDP client (Unicast).</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;1. Declare all necessary variables such as buffer, socket descriptor, socket address structure etc.&lt;br /&gt;2. Now Configure socket API with proper parameters.&lt;br /&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;i&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; s=socket(AF_INET,SOCK_DGRAM,0)&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;3. Then configure socket address with proper assignments&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;i&gt; saddr.sin_family=AF_INET&lt;/i&gt;&lt;br /&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; saddr.sin_port=htons(PORT)&lt;/i&gt;&lt;br /&gt;4. Then check for address format and convert it into numeric format.&lt;br /&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; if(inet_pton(AF_INET,argv[1],&amp;amp;saddr.sin_addr)&amp;lt;=0)&lt;br /&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;br /&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; printf(&quot;Error. Invalid IP adress\n&quot;);&lt;br /&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; exit(0);&lt;br /&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;br /&gt;&lt;br /&gt;&lt;br /&gt;5.&amp;nbsp; Then send request to server by using buffer&lt;br /&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; if(sendto(s,buffer,strlen(buffer),0,(struct sockaddr*)&amp;amp;saddr,sizeof(sadd))&amp;lt;0)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; printf(&quot;\n Send Error&quot;);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; exit(0);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; }&lt;br /&gt;6. After sending buffer request , i waits for some receiving data.&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;printf(&quot;\nWaiting for response...\n&quot;);&lt;br /&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; n=recvfrom(s,buffer,sizeof(buffer)-1,0,NULL,NULL);&lt;br /&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; if(n&amp;lt;0)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&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; printf(&quot;\n Recieve error\n&quot;);&lt;br /&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; exit(0);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;7. Close Socket.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; close(s);&lt;br /&gt;Full program is as follows:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;iframe border=&quot;0&quot; frameborder=&quot;0&quot; height=&quot;90&quot; marginwidth=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;http://rcm.amazon.com/e/cm?t=httpprogram01-20&amp;amp;o=1&amp;amp;p=20&amp;amp;l=ur1&amp;amp;category=wireless&amp;amp;banner=1RWF4VASSX63F46H0702&amp;amp;f=ifr&quot; style=&quot;border: medium none;&quot; width=&quot;120&quot;&gt;&lt;/iframe&gt;&lt;br /&gt;&amp;nbsp; &lt;br /&gt;#define PORT 1300&lt;br /&gt;int main(int argc, char *argv[])&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int s,n;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; char buffer[100];&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct sockaddr_in saddr;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(argc!=2)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&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; printf(&quot;Usage::&amp;lt;%s&amp;gt;&amp;lt;Serv_IP&amp;gt;\n&quot;,argv[0]);&lt;br /&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; exit(0);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; s=socket(AF_INET,SOCK_DGRAM,0);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(s&amp;lt;0)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&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; printf(&quot;Socket Error&quot;);&lt;br /&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; exit(0);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; saddr.sin_family=AF_INET;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; saddr.sin_port=htons(PORT);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(inet_pton(AF_INET,argv[1],&amp;amp;saddr.sin_addr)&amp;lt;=0)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&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; printf(&quot;Error. Invalid IP adress\n&quot;);&lt;br /&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; exit(0);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strcpy(buffer,&quot;Hello Server!! I am Client !!&quot;);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;Sending request to server %s\n&quot;,argv[1]);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(sendto(s,buffer,strlen(buffer),0,(struct sockaddr*)&amp;amp;saddr,sizeof(saddr))&amp;lt;0)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&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; printf(&quot;\nSend error\n&quot;);&lt;br /&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; exit(0);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;\nWaiting for response...\n&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n=recvfrom(s,buffer,sizeof(buffer)-1,0,NULL,NULL);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(n&amp;lt;0)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&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; printf(&quot;\n Recieve error\n&quot;);&lt;br /&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; exit(0);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; buffer[n]=0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;\nReply from server %s is %s\n&quot;,argv[1],buffer);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; close(s);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/4649350174088602993/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/06/steps-to-write-udp-client-unicast.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/4649350174088602993'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/4649350174088602993'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/06/steps-to-write-udp-client-unicast.html' title='Steps to write a UDP client (Unicast).'/><author><name>ProgNinja Blue</name><uri>https://plus.google.com/103025513032526183728</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-4568840183261293279</id><published>2012-05-16T15:42:00.003+05:30</published><updated>2012-12-15T00:56:25.410+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><title type='text'>Write a C program that will write input into a file, then it will return frequency of each letter occurred in the file.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;&lt;i&gt;Underlying Concept: File Handling&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;b&gt;Note: Pr&lt;/b&gt;&lt;b&gt;ess CTRL-D for taking EOF as input&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;color: #990000;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;#include&amp;lt;stdio.h&amp;gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;#include&amp;lt;stdlib.h&amp;gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;#include&amp;lt;string.h&amp;gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;int main()&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;{&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FILE *f1,*f2;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; char ch,bh;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;\n write to file INPUT.txt:\n&quot;);&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f1=fopen(&quot;FREQUENCY.txt&quot;,&quot;w&quot;);&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while((ch=getchar())!=EOF)&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&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; putc(ch,f1);&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fclose(f1);&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int n=0;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; f2=fopen(&quot;histogram.txt&quot;,&quot;w&quot;);&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; unsigned char r;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;\n\n&quot;);&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(r=97;r&amp;lt;122;r++)&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; n=0;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if(r%5==0)&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;\n&quot;);&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; f1=fopen(&quot;FREQUENCY.txt&quot;,&quot;r&quot;);&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; while((ch=getc(f1))!=EOF)&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if(ch==r)&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&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; n++;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot; Frequency of %c is %d\t&quot;,r,n);&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; fprintf(f2,&quot;%d&quot;,n);&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; fprintf(f2,&quot;\n&quot;);&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; fclose(f1);&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fclose(f2);&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;} &lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/4568840183261293279/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/05/write-c-program-that-will-write-input.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/4568840183261293279'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/4568840183261293279'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/05/write-c-program-that-will-write-input.html' title='Write a C program that will write input into a file, then it will return frequency of each letter occurred in the file.'/><author><name>ProgNinja Blue</name><uri>https://plus.google.com/103025513032526183728</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-3753993406965552899</id><published>2012-05-16T15:33:00.003+05:30</published><updated>2012-12-15T00:55:34.328+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><category scheme="http://www.blogger.com/atom/ns#" term="Data Structure"/><title type='text'>Write  a C program to generate a list and divide into two sublist one contating elements at odd index and other elements at even index.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;i&gt;&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Underlying concept to demonstrate: Self-referential structure, linked list.&lt;/span&gt;&lt;/b&gt;&lt;/i&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;#include&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;#include&amp;lt;stdlib.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;struct node&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int data;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct node *next;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;};&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;typedef struct node LL;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;void display(LL *p)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;\n The linked list is: &quot;);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while(p!=NULL)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&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; printf(&quot; %d&quot;,p-&amp;gt;data);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&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; p=p-&amp;gt;next;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;void insert(LL **head,int n)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LL *temp,*current;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp=(LL *)malloc(sizeof(LL));&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp-&amp;gt;data=n;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp-&amp;gt;next=NULL;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(*head==NULL)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&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; *head=temp;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&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;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&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; current=*head;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&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; while(current-&amp;gt;next!=NULL)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&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; current=current-&amp;gt;next;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&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; current-&amp;gt;next=temp;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&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;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;int main()&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LL *head,*odd,*even;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; head=NULL;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; odd=NULL;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; even=NULL;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int num;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;\n Linked list:\n&quot;);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&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; printf(&quot;\n Enter the no. to insert(Enter -ve to stop inserting):&quot;);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&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; scanf(&quot;%d&quot;,&amp;amp;num);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if(num&amp;lt;0)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&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; insert(&amp;amp;head,num);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }while(1);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; display(head);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LL *temp;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp=head;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int i=0;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while(temp!=NULL)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; i++;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if(i%2==0)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; insert(&amp;amp;even,temp-&amp;gt;data);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&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; insert(&amp;amp;odd,temp-&amp;gt;data);&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; temp=temp-&amp;gt;next;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;\n Sub list with elements having odd index:&quot;);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; display(odd);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;\n Sub list with elements having even index:&quot;);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; display(even);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/3753993406965552899/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/05/write-c-program-to-generate-list-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/3753993406965552899'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/3753993406965552899'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/05/write-c-program-to-generate-list-and.html' title='Write  a C program to generate a list and divide into two sublist one contating elements at odd index and other elements at even index.'/><author><name>ProgNinja Blue</name><uri>https://plus.google.com/103025513032526183728</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-5309643729659947565</id><published>2012-05-16T15:29:00.004+05:30</published><updated>2012-12-15T00:57:30.066+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><title type='text'>Write a C program to reverse a substring of a string without using any library function.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;i style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;b&gt;Underlying Concept: String manipulation&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;#include&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;#include&amp;lt;stdlib.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;int sub_reverse(char *s,char *r,char *t)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int i=0;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while(s[i]!=0)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if(s[i]==r[0])&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; i++;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char temp;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while(s&amp;lt;t)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; temp=*s;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; *s=*t;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; *t=temp;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; s++;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; t--;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot; /&gt;&lt;br style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot; /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;int main()&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char *string,*sub,*end;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; unsigned u,pos1,pos2;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;\n enter size of string:&quot;);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; scanf(&quot;%u&quot;,&amp;amp;u);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; string=(char *)malloc(u*sizeof(char));&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;\n enter the string:&quot;);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; scanf(&quot;%s&quot;,string);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;\n What is the position of first character of substring:&quot;);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; scanf(&quot;%u&quot;,&amp;amp;pos1);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;\n What is the position of last character of substring:&quot;);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; scanf(&quot;%u&quot;,&amp;amp;pos2);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sub=string+pos1;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end=string+pos2;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sub_reverse(string,sub,end);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;\nNew string is:%s&quot;,string);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/5309643729659947565/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/05/write-c-program-to-reverse-substring-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/5309643729659947565'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/5309643729659947565'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/05/write-c-program-to-reverse-substring-of.html' title='Write a C program to reverse a substring of a string without using any library function.'/><author><name>ProgNinja Blue</name><uri>https://plus.google.com/103025513032526183728</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2036600381616701985.post-792879791837565598</id><published>2012-05-16T15:16:00.005+05:30</published><updated>2012-12-15T00:53:43.088+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><title type='text'>Write a C program to generate all possible permutation of a string.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;span style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif; font-size: large;&quot;&gt;&lt;i&gt;&lt;b&gt;Underlying concept: Recursion&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif; font-size: large;&quot;&gt;&lt;i&gt;&lt;b&gt;Assignment: Generate all possible Combinations of a string (Its to remind you&amp;nbsp; that combination is different from permutation)&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;#include&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;#include&amp;lt;string.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;#include&amp;lt;stdlib.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;int cnt=0;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;void permutate(char *cut,char *c)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char d,keep[20];&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int i,j;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; strcpy(keep,cut);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int len=strlen(cut);&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; d=c[len];&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(d==&#39;\0&#39;)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;%d.%s\n*****\n&quot;,++cnt,cut);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; return ;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(i=len;i&amp;gt;=0;--i)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; for(j=len;j&amp;gt;=i;j--)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; cut[j+1]=cut[j];&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; cut[++j]=d;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; permutate(cut,c);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; strcpy(cut,keep);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;br style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot; /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot; /&gt;&lt;br style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot; /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;int main()&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char *c,*cut;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int n;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;\n Enter n:&quot;);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; scanf(&quot;%d&quot;,&amp;amp;n);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; c=(char*)malloc(n*sizeof(char));&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cut=(char*)malloc(n*sizeof(char));&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;Enter the string:&quot;);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; scanf(&quot;%s&quot;,c);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cut[0]=c[0];&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cut[1]=&#39;\0&#39;;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; permutate(cut,c);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingblue-it-besu.blogspot.com/feeds/792879791837565598/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/05/write-c-program-to-generate-all.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/792879791837565598'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2036600381616701985/posts/default/792879791837565598'/><link rel='alternate' type='text/html' href='http://programmingblue-it-besu.blogspot.com/2012/05/write-c-program-to-generate-all.html' title='Write a C program to generate all possible permutation of a string.'/><author><name>ProgNinja Blue</name><uri>https://plus.google.com/103025513032526183728</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>