<?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-8228086725291688914</id><updated>2026-10-24T04:12:47.569-07:00</updated><category term="multithreading in C"/><category term="number patterns"/><category term="printf explored"/><category term="password"/><category term="scanf"/><category term="Algorithms"/><category term="DOS command"/><category term="escape sequence"/><category term="sequence points"/><category term="star patterns"/><category term="Assembly code"/><category term="MAC Address"/><category term="Quiz"/><category term="address of array"/><category term="amazing"/><category term="break string into charaters"/><category term="common bugs"/><category term="data segment"/><category term="deleting a file"/><category term="function calling"/><category term="history"/><category term="lvalue"/><category term="operator precedence"/><category term="padding in c"/><category term="processor available or not"/><category term="progress bar in c"/><category term="random number"/><category term="read file"/><category term="rename in c"/><category term="sleep function"/><category term="stack flow"/><category term="static variable"/><category term="storage classes in C"/><category term="string sorting"/><title type='text'>C language Stuff</title><subtitle type='html'>This blog is all about c language stuff,questions ,tricky questions with explanation.concepts that are not general....</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>77</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-8202338365012560925</id><published>2015-06-24T10:47:00.000-07:00</published><updated>2015-06-24T10:47:17.324-07:00</updated><title type='text'>Comparing Username Stored in File in C</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
I got a request to read the username from file and compare the same .&lt;br /&gt;
Here is the code for the same :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;php&quot; name=&quot;code&quot;&gt;#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;conio.h&amp;gt;
void main()
{
char ch;
char user_name[128];
char line[128];
char str[128];
char *ptr;
int i=0;
FILE *fp;

//Saving username in file
printf(&quot;Enter the username to write in a file:&quot;);
ch=getch();
while(ch!=13)
{
if(ch==8)
{
printf(&quot;\b&quot;);
putch(NULL);
printf(&quot;\b&quot;);
user_name[i]=&#39;\0&#39;;
--i;
}
else
{
printf(&quot;%c&quot;,ch);
user_name[i++]=ch;
}
ch=getch();
}
user_name[i]=&#39;\0&#39;;
ptr=user_name;
fp=fopen(&quot;d:\\user.txt&quot;,&quot;w+&quot;);
while(*ptr!=&#39;\0&#39;)
{
fputc(*ptr,fp);
ptr++;
}
printf(&quot;\nUsername successfully saved in the file&quot;);

//Reading username from file and saving to string .
fseek( fp, 0, SEEK_SET );
while(fgets(line,sizeof(line),fp)!=NULL)
   {
   char *nwln=strchr(line,&#39;\n&#39;);
   if(nwln!=NULL)
   *nwln=&#39;\0&#39;;
   }
printf(&quot;\nUsername in file is :%s&quot;,line);
fp=NULL;

//take username from user to compare.
printf(&quot;\nEnter username to confirm:&quot;);
fgets(str,sizeof(str),stdin);
str[strlen(str)-1] = &#39;\0&#39;;
if(!strcmp(line,str))
{
    printf(&quot;\nyou are right&quot;);
}
else
{
    printf(&quot;\nyou are wrong&quot;);
}

getch();
}
&lt;/pre&gt;
&lt;pre class=&quot;php&quot; name=&quot;code&quot;&gt;
&lt;/pre&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwtGESW8o1EQaMa6msJGrUFu99HTk1wcd5kkJivdG0MPBBFo0MGJjLCqOnC3YChVxY0ooLhNBd74a3CaHkHvqog7MKKCQZ1MiyPWsPUFr6T-OpTVIcFoLxwDdfnn_a-ToC43ucBDfWqA/s1600/out.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;118&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwtGESW8o1EQaMa6msJGrUFu99HTk1wcd5kkJivdG0MPBBFo0MGJjLCqOnC3YChVxY0ooLhNBd74a3CaHkHvqog7MKKCQZ1MiyPWsPUFr6T-OpTVIcFoLxwDdfnn_a-ToC43ucBDfWqA/s320/out.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;pre class=&quot;php&quot; name=&quot;code&quot;&gt;
&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/8202338365012560925/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2015/06/comparing-username-stored-in-file-in-c.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/8202338365012560925'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/8202338365012560925'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2015/06/comparing-username-stored-in-file-in-c.html' title='Comparing Username Stored in File in C'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwtGESW8o1EQaMa6msJGrUFu99HTk1wcd5kkJivdG0MPBBFo0MGJjLCqOnC3YChVxY0ooLhNBd74a3CaHkHvqog7MKKCQZ1MiyPWsPUFr6T-OpTVIcFoLxwDdfnn_a-ToC43ucBDfWqA/s72-c/out.PNG" height="72" width="72"/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-1774256653730156521</id><published>2015-01-27T05:44:00.000-08:00</published><updated>2015-01-27T05:44:27.227-08:00</updated><title type='text'>Format Specifiers in C</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Let us take a look at some format specifiers used in printf which are necessary to format the output.....&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;border-collapse: separate; color: black; font-family: &#39;Times New Roman&#39;; font-size: x-small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,Verdana,Arial,Helvetica,sans-serif; font-size: 14px; line-height: 18px; text-align: left;&quot;&gt;&lt;code style=&quot;font-family: Consolas,&#39;Lucida Console&#39;,&#39;DejaVu Sans Mono&#39;,&#39;Andale Mono&#39;,monospace; font-size: 0.9em;&quot;&gt;%x&lt;/code&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;--&amp;gt; &lt;/span&gt;prints an&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;font-family: Consolas,&#39;Lucida Console&#39;,&#39;DejaVu Sans Mono&#39;,&#39;Andale Mono&#39;,monospace; font-size: 0.9em;&quot;&gt;int&lt;/code&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;in hexadecimal.&lt;br /&gt;
&lt;code style=&quot;font-family: Consolas,&#39;Lucida Console&#39;,&#39;DejaVu Sans Mono&#39;,&#39;Andale Mono&#39;,monospace; font-size: 0.9em;&quot;&gt;%4x&lt;/code&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;--&amp;gt; &lt;/span&gt;prints a hex int, right-justified to 4 places. If it&#39;s less than 4 digits, it&#39;s preceded by spaces. If it&#39;s more than 4 digits, you get the full number.&lt;br /&gt;
&lt;code style=&quot;font-family: Consolas,&#39;Lucida Console&#39;,&#39;DejaVu Sans Mono&#39;,&#39;Andale Mono&#39;,monospace; font-size: 0.9em;&quot;&gt;%04x&lt;/code&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;--&amp;gt; &lt;/span&gt;prints a hex int, right-justified to 4 places. If it&#39;s less than 4 digits, it&#39;s preceded by zeroes. If it&#39;s more than 4 digits, you get the full number, but no leading zeroes.&lt;br /&gt;
&lt;br /&gt;
example:&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
int i=98;&lt;br /&gt;
printf(&quot;%x\n&quot;,i);&lt;br /&gt;
printf(&quot;%4x\n&quot;,i);&lt;br /&gt;
printf(&quot;%04x&quot;,i);&lt;br /&gt;
getch();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
output:&lt;br /&gt;
62&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 62&lt;br /&gt;
00062&lt;br /&gt;
&lt;br /&gt;
Similary with %d&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
int i=5;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;border-collapse: separate; color: black; font-family: &#39;Times New Roman&#39;; font-size: x-small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,Verdana,Arial,Helvetica,sans-serif; font-size: 14px; line-height: 18px; text-align: left;&quot;&gt;printf(&quot;%d\n&quot;,i);&lt;br /&gt;
printf(&quot;%4d\n&quot;,i);&lt;br /&gt;
printf(&quot;%04d&quot;,i);&lt;br /&gt;
getch();&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
output:&lt;br /&gt;
5&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&lt;br /&gt;
00005&lt;br /&gt;
&lt;br /&gt;
Similary with %c..&lt;br /&gt;
&amp;nbsp;void main()&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,Verdana,Arial,Helvetica,sans-serif; font-size: 14px; line-height: 18px; text-align: left;&quot;&gt;{&lt;br /&gt;
char c=&#39;a&#39;;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;border-collapse: separate; color: black; font-family: &#39;Times New Roman&#39;; font-size: x-small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,Verdana,Arial,Helvetica,sans-serif; font-size: 14px; line-height: 18px; text-align: left;&quot;&gt;printf(&quot;%c\n&quot;,c);&lt;br /&gt;
printf(&quot;%4c\n&quot;,c);&lt;br /&gt;
printf(&quot;%04c&quot;,c);&lt;br /&gt;
getch();&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
output:&lt;br /&gt;
a&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a&lt;br /&gt;
&lt;br /&gt;
0000a&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/1774256653730156521/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2015/01/format-specifiers-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/1774256653730156521'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/1774256653730156521'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2015/01/format-specifiers-in-c.html' title='Format Specifiers in C'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-4949012282712925600</id><published>2015-01-27T05:41:00.002-08:00</published><updated>2015-01-27T05:41:57.700-08:00</updated><title type='text'>Calling conventions in C</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
What is the calling convention?&lt;br /&gt;
When a function is called, the arguments are typically passed to it, and the return value is retrieved.&lt;br /&gt;
&lt;br /&gt;
A calling convention describes:&lt;br /&gt;
--&amp;gt;how the arguments are passed and values returned by functions.&lt;br /&gt;
&lt;br /&gt;
Two calling Conventions:&lt;br /&gt;
1.)cdecl&lt;br /&gt;
2.)pascal&lt;br /&gt;
&lt;br /&gt;
1.)cdecl&lt;br /&gt;
--&amp;gt;This convention is the default for C/C++ programs..&lt;br /&gt;
--&amp;gt;&lt;span style=&quot;background-color: #f1c232;&quot;&gt;Arguments are passed from right to left&lt;/span&gt;, and placed on the stack.&lt;br /&gt;
--&amp;gt;Only the code that calls these functions knows for certain what it has placed on the stack.&lt;br /&gt;
&lt;span style=&quot;background-color: #f1c232;&quot;&gt;So,stack cleanup is performed by the caller...&lt;/span&gt;&lt;br /&gt;
--&amp;gt;Support the variable argument functionality.&lt;br /&gt;
&lt;br /&gt;
2.)pascal&lt;br /&gt;
--&amp;gt;&lt;span style=&quot;background-color: #f1c232;&quot;&gt;Arguments are passed form left to right&lt;/span&gt; ,and placed on stack.&lt;br /&gt;
--&amp;gt;&lt;span style=&quot;background-color: #f1c232;&quot;&gt;Stack cleanup is performed by the called function&lt;/span&gt;.&lt;br /&gt;
--&amp;gt;Does not support variable argument functionality.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
#include&amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include&amp;lt;conio.h&amp;gt;&lt;br /&gt;
void pascal f(int i,int j,int k)&lt;br /&gt;
{ &lt;br /&gt;
printf(“i=%d j=%d k=%d”,i, j, k); &lt;br /&gt;
}&lt;br /&gt;
void cdecl f1(int i,int j,int k)&lt;br /&gt;
{ &lt;br /&gt;
printf(“i=%d j=%d k=%d”,i, j, k); &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
int i=50;&lt;br /&gt;
f1(i++,i++,i++);&lt;br /&gt;
printf(&quot;--&amp;gt;%d\n&quot;,i);&lt;br /&gt;
i=50;&lt;br /&gt;
f(i++,i++,i++);&lt;br /&gt;
printf(&quot;--&amp;gt;%d&quot;,i);&lt;br /&gt;
getch();&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
output:&lt;br /&gt;
i=52 j=51 k=50--&amp;gt;53 &lt;br /&gt;
i=50 j=51 k=52--&amp;gt;53&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
Strictly speaking the result is undefined , Read about the &lt;a href=&quot;http://clanguagestuff.blogspot.in/2011/02/sequence-points.html&quot; target=&quot;_blank&quot;&gt;Sequence Points&lt;/a&gt; and &lt;a href=&quot;http://clanguagestuff.blogspot.in/2011/02/undefined-behaviour.html&quot; target=&quot;_blank&quot;&gt;Undefined Behavior&lt;/a&gt; .&lt;br /&gt;
now if we talk about a particular compiler implementation ,if that compiler produces &quot;i=52 j=51 k=50&quot; for cdecl convention(default for C) then it willl certainly give the output &quot;i=50 j=51 k=52&quot; for the pascal convention because they are opposite to each other..&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/4949012282712925600/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2015/01/calling-conventions-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/4949012282712925600'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/4949012282712925600'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2015/01/calling-conventions-in-c.html' title='Calling conventions in C'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-462709074270969046</id><published>2013-12-18T07:51:00.000-08:00</published><updated>2013-12-18T07:51:37.036-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Assembly code"/><title type='text'>How to translate C source code into assembly instruction for a function </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;background-color: white; color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;color: #0c343d;&quot;&gt;
&lt;b&gt;Converting&amp;nbsp;the function&amp;nbsp;source code&amp;nbsp;into&amp;nbsp;the assembly&amp;nbsp;is not a big deal , it is just a matter of 3 simple steps:&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;color: #0c343d;&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;color: #0c343d;&quot;&gt;
&lt;b&gt;1.) Identifying the non-executable&amp;nbsp;statements&amp;nbsp;within&amp;nbsp;a function.&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;color: #0c343d;&quot;&gt;
&lt;b&gt;2.)Create&amp;nbsp;a function&amp;nbsp;symbol table and resolve all the non-executable instructions.&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;color: #0c343d;&quot;&gt;
&lt;b&gt;3.)Translate C source into assembly source.&lt;/b&gt;&lt;/div&gt;
&lt;br /&gt;These steps sounds to be tough but if you have basic knowledge of&amp;nbsp;&lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD4&quot; style=&quot;background-attachment: scroll !important; background-color: transparent !important; background-image: none !important; background-position: 0% 50%; background-repeat: repeat repeat !important; border-bottom-color: rgb(0, 153, 0) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; color: rgb(0, 153, 0) !important; cursor: pointer !important; display: inline !important; float: none !important; padding: 0px 0px 1px !important; position: static; text-decoration: underline !important;&quot;&gt;c language&lt;/span&gt;&amp;nbsp;these are very easy . let us take the steps one by one considering the follwing example of small code:&lt;br /&gt;&lt;div class=&quot;dp-highlighter&quot; style=&quot;background-color: #e7e5dc; font-family: Consolas, Monaco, &#39;Courier New&#39;, Courier, monospace; font-size: 12px; margin: 18px 0px !important; overflow: auto; padding-top: 1px; width: 770.21875px;&quot;&gt;
&lt;div class=&quot;bar&quot; style=&quot;padding-left: 45px;&quot;&gt;
&lt;div class=&quot;tools&quot; style=&quot;background-color: #f8f8f8; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; color: silver; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 9px; line-height: normal; padding: 3px 8px 10px 10px;&quot;&gt;
&lt;a href=&quot;http://clanguagestuff.blogspot.in/2013/10/stack-flow-in-function-calls-in-c.html#&quot; style=&quot;background-color: inherit; background-image: none; border: none; color: #a0a0a0; margin: 0px 10px 0px 0px; padding: 0px; text-decoration: none;&quot;&gt;view plain&lt;/a&gt;&lt;a href=&quot;http://clanguagestuff.blogspot.in/2013/10/stack-flow-in-function-calls-in-c.html#&quot; style=&quot;background-color: inherit; background-image: none; border: none; color: #a0a0a0; margin: 0px 10px 0px 0px; padding: 0px; text-decoration: none;&quot;&gt;print&lt;/a&gt;&lt;a href=&quot;http://clanguagestuff.blogspot.in/2013/10/stack-flow-in-function-calls-in-c.html#&quot; style=&quot;background-color: inherit; background-image: none; border: none; color: #a0a0a0; margin: 0px 10px 0px 0px; padding: 0px; text-decoration: none;&quot;&gt;?&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;ol class=&quot;dp-c&quot; style=&quot;background-color: white; border: none; color: #5c5c5c; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1px 45px !important; padding: 0px;&quot;&gt;
&lt;li class=&quot;alt&quot; style=&quot;border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; color: inherit; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; margin: 0px; padding: 0px;&quot;&gt;int&amp;nbsp;main()&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;&quot; style=&quot;background-color: #f8f8f8; border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;alt&quot; style=&quot;border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; color: inherit; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;int&amp;nbsp;a&amp;nbsp;=&amp;nbsp;100;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;&quot; style=&quot;background-color: #f8f8f8; border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;int&amp;nbsp;b&amp;nbsp;=&amp;nbsp;100;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;alt&quot; style=&quot;border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; color: inherit; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;int&amp;nbsp;c;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;&quot; style=&quot;background-color: #f8f8f8; border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;c&amp;nbsp;=&amp;nbsp;a+b;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;alt&quot; style=&quot;border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; color: inherit; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;}&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;color: #990000;&quot;&gt;
&lt;b&gt;Step1: Identifying the non-executable&amp;nbsp;statements&amp;nbsp;within&amp;nbsp;a function&lt;/b&gt;&lt;/div&gt;
&lt;br /&gt;To understand this step we have to know what are the non-executable&amp;nbsp;&lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD7&quot; style=&quot;background-attachment: scroll !important; background-color: transparent !important; background-image: none !important; background-position: 0% 50%; background-repeat: repeat repeat !important; border-bottom-color: rgb(0, 153, 0) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; color: rgb(0, 153, 0) !important; cursor: pointer !important; display: inline !important; float: none !important; padding: 0px 0px 1px !important; position: static; text-decoration: underline !important;&quot;&gt;statements&lt;/span&gt;&amp;nbsp;??&lt;br /&gt;Whenever you write a program you always write them at the very beginning of you function body.yes you guessed it right the variable declarations are the ones.&lt;br /&gt;we can define the non-executable&amp;nbsp;statements&amp;nbsp;as:&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Calibri, sans-serif; font-size: 11pt; line-height: 17px;&quot;&gt;Non-executable&amp;nbsp;statements&amp;nbsp;are those&amp;nbsp;which are&amp;nbsp;not converted to the instructions to be executed by the processor. It means that they are just the memory allocation instruction&amp;nbsp;which are&amp;nbsp;processed by the compilers.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;So, in our example we have three non-executable&amp;nbsp;statements&amp;nbsp;shown in the figure below.&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWk8Zg0jSHrQ4mW0OM0oqYzmHyhDYmk_IBtJvqxGmq-Nz3w8cLn1FmE1NvxAo14BgacI2acp4UWMjWvE8_h4fEIH__jLdPcudA2LYEdyyJTswpevA-I4hDZpjlMGi4q_uPRYWcbraO5Q/s1600/step1.png&quot; imageanchor=&quot;1&quot; style=&quot;color: #6699cc; margin-left: 1em; margin-right: 1em; text-decoration: none;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;141&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWk8Zg0jSHrQ4mW0OM0oqYzmHyhDYmk_IBtJvqxGmq-Nz3w8cLn1FmE1NvxAo14BgacI2acp4UWMjWvE8_h4fEIH__jLdPcudA2LYEdyyJTswpevA-I4hDZpjlMGi4q_uPRYWcbraO5Q/s320/step1.png&quot; style=&quot;border: none; position: relative;&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span id=&quot;goog_479344805&quot;&gt;&lt;/span&gt;&lt;span id=&quot;goog_479344806&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style=&quot;color: #990000;&quot;&gt;
&lt;b&gt;Step2: Creating&amp;nbsp;the function&amp;nbsp;symbol and resolving all non-executable&amp;nbsp;statements.&lt;/b&gt;&lt;/div&gt;
&lt;br /&gt;Function Symbol table consists of 4 values:&lt;br /&gt;1.)Symbol Name&lt;br /&gt;2.)Type&lt;br /&gt;3.)Composition (size of data type of symbol)&lt;br /&gt;4.)Offset Address&lt;br /&gt;&lt;br /&gt;You can easily fill the symbol table as shown below for our example.&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEga0OuFhnvtiYjJCTzbdupW1uOdPdDIjo5sWuJg93ctzWc16KLUn_nnVI4_nH7NaI9NTXrZwGJzJgZ5OauBFEWP_UKpy6rG_qytByCriMjMaOnqcHO3zKoADsxEst1JygcdpQDuN8Eajg/s1600/step_2.png&quot; imageanchor=&quot;1&quot; style=&quot;color: #6699cc; margin-left: 1em; margin-right: 1em; text-decoration: none;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;97&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEga0OuFhnvtiYjJCTzbdupW1uOdPdDIjo5sWuJg93ctzWc16KLUn_nnVI4_nH7NaI9NTXrZwGJzJgZ5OauBFEWP_UKpy6rG_qytByCriMjMaOnqcHO3zKoADsxEst1JygcdpQDuN8Eajg/s400/step_2.png&quot; style=&quot;border: none; position: relative;&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;As you can see in the above table , we have taken the variable names as symbols and added their type and size in the respective columns.&lt;br /&gt;&lt;br /&gt;After filling the table we have calculate the total size which comes out to be 12 . Basically this 12 is the size of the&amp;nbsp;stackfor&amp;nbsp;the function&amp;nbsp;main which will be allocated when the main function will be called.&lt;br /&gt;&lt;br /&gt;Now the last column is the offset address . Offest Addresses are allocated by the compiler.&lt;span style=&quot;font-family: Calibri, sans-serif; font-size: 11pt; line-height: 17px;&quot;&gt;&amp;nbsp;&lt;/span&gt;let us see how we will fill that column.&lt;br /&gt;&lt;br /&gt;Let us take the base pointer to the&amp;nbsp;stack&amp;nbsp;as ebp and assume that&amp;nbsp;stack&amp;nbsp;grows downwards (which happens most of the tym ).&lt;br /&gt;&lt;br /&gt;As the size of the&amp;nbsp;stack&amp;nbsp;is 12 and a is the first variable declared in&amp;nbsp;the function&amp;nbsp;so,&lt;br /&gt;&lt;br /&gt;Variable &#39;a&#39; will get the memory at -12(%ebp)&amp;nbsp; that is -12 from ebp (stack&amp;nbsp;base pointer)&lt;br /&gt;Variable &#39;b&#39; will get the memory at -8(%ebp) because &#39;a&#39; is of 4 bytes.&lt;br /&gt;Variable &#39;c&#39; will get the memory ar -4(%ebp) because &#39;b&#39; is also of 4 bytes.&lt;br /&gt;&lt;br /&gt;So, The final function symbol will be:&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjehfkYDH6lNUZ_yphjtDU_XoVG-Vsx0HcIytT1gYZ191S439mYy_mpZGiMY3T3N-KhbvLFEQh6JfOAYaoEffWbRNM1L4klc6z_oIQdIZESfLIYeZniE95c22UwvUpDGmqKsgQ3pOVa4w/s1600/step2_1.png&quot; imageanchor=&quot;1&quot; style=&quot;color: #6699cc; margin-left: 1em; margin-right: 1em; text-decoration: none;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;98&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjehfkYDH6lNUZ_yphjtDU_XoVG-Vsx0HcIytT1gYZ191S439mYy_mpZGiMY3T3N-KhbvLFEQh6JfOAYaoEffWbRNM1L4klc6z_oIQdIZESfLIYeZniE95c22UwvUpDGmqKsgQ3pOVa4w/s400/step2_1.png&quot; style=&quot;border: none; position: relative;&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;color: #990000;&quot;&gt;
&lt;b&gt;Step3: Translating C code to&amp;nbsp;&lt;a class=&quot;kLink&quot; href=&quot;http://clanguagestuff.blogspot.in/2013/10/stack-flow-in-function-calls-in-c.html#&quot; id=&quot;KonaLink5&quot; style=&quot;background-color: transparent !important; background-image: none !important; border: 0px none transparent !important; bottom: 0px; color: blue; cursor: pointer; display: inline !important; font-family: inherit !important; font-size: inherit !important; font-weight: inherit !important; left: 0px; margin: 0px; outline: none; padding: 0px; position: static; right: 0px; top: 0px;&quot;&gt;&lt;span style=&quot;color: blue; font-family: inherit !important; font-size: inherit !important; font-weight: inherit !important; position: static;&quot;&gt;&lt;span class=&quot;kLink&quot; style=&quot;background-color: transparent; background-image: none; border-bottom-style: solid; border-bottom-width: 1px; border-left-style: none !important; border-left-width: 0px !important; border-right-style: none !important; border-right-width: 0px !important; border-top-style: none !important; border-top-width: 0px !important; display: inline !important; float: none !important; font-family: inherit !important; font-size: inherit !important; font-weight: inherit !important; padding: 0px 0px 1px !important; position: static; width: auto !important;&quot;&gt;assembly&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;kLink&quot; style=&quot;background-color: transparent; background-image: none; border-bottom-style: solid; border-bottom-width: 1px; border-left-style: none !important; border-left-width: 0px !important; border-right-style: none !important; border-right-width: 0px !important; border-top-style: none !important; border-top-width: 0px !important; display: inline !important; float: none !important; font-family: inherit !important; font-size: inherit !important; font-weight: inherit !important; padding: 0px 0px 1px !important; position: static; width: auto !important;&quot;&gt;language&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;.&lt;/b&gt;&lt;/div&gt;
&lt;br /&gt;In this process whenever we have to access the variable we will replace that by the offset address given in&amp;nbsp;the functionsymbol table.&lt;br /&gt;&lt;span id=&quot;goog_204380558&quot;&gt;&lt;/span&gt;&lt;span id=&quot;goog_204380559&quot;&gt;&lt;/span&gt;&lt;br /&gt;To convert&amp;nbsp;the function&amp;nbsp;C&amp;nbsp;source code&amp;nbsp;into assembly we need to know one thing that is GNU compilers follows a standard which says that:&lt;br /&gt;&lt;br /&gt;&quot;Every function consist of 4 parts&amp;nbsp;which are:&lt;br /&gt;1.) Function name&lt;br /&gt;2.)Pre-amble (the opening brace of function)&lt;br /&gt;3.)Function-body&lt;br /&gt;4.)Post-amble (the closing brace of function)&quot;&lt;br /&gt;&lt;br /&gt;And the same is written as the following:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;color: #990000;&quot;&gt;
&lt;b&gt;Function name :&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;color: #990000;&quot;&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pre-amble&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;color: #990000;&quot;&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; function-body&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;color: #990000;&quot;&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; post-amble.&lt;/b&gt;&lt;/div&gt;
&lt;br /&gt;Here pre-amble defines the code for the opening curly brace and&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; post-amble defines the code for the closing curly brace.&lt;br /&gt;&lt;br /&gt;Let us take a look at the both the pre-amble ,function body and post-amble small piece of code:&lt;br /&gt;&lt;br /&gt;Pre-amble code:&lt;/div&gt;
&lt;div class=&quot;dp-highlighter&quot; style=&quot;background-color: #e7e5dc; font-family: Consolas, Monaco, &#39;Courier New&#39;, Courier, monospace; font-size: 12px; margin: 18px 0px !important; overflow: auto; padding-top: 1px; width: 770.21875px;&quot;&gt;
&lt;div class=&quot;bar&quot; style=&quot;padding-left: 45px;&quot;&gt;
&lt;div class=&quot;tools&quot; style=&quot;background-color: #f8f8f8; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; color: silver; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 9px; line-height: normal; padding: 3px 8px 10px 10px;&quot;&gt;
&lt;a href=&quot;http://clanguagestuff.blogspot.in/2013/10/stack-flow-in-function-calls-in-c.html#&quot; style=&quot;background-color: inherit; background-image: none; border: none; color: #a0a0a0; margin: 0px 10px 0px 0px; padding: 0px; text-decoration: none;&quot;&gt;view plain&lt;/a&gt;&lt;a href=&quot;http://clanguagestuff.blogspot.in/2013/10/stack-flow-in-function-calls-in-c.html#&quot; style=&quot;background-color: inherit; background-image: none; border: none; color: #a0a0a0; margin: 0px 10px 0px 0px; padding: 0px; text-decoration: none;&quot;&gt;print&lt;/a&gt;&lt;a href=&quot;http://clanguagestuff.blogspot.in/2013/10/stack-flow-in-function-calls-in-c.html#&quot; style=&quot;background-color: inherit; background-image: none; border: none; color: #a0a0a0; margin: 0px 10px 0px 0px; padding: 0px; text-decoration: none;&quot;&gt;?&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;ol class=&quot;dp-c&quot; style=&quot;background-color: white; border: none; color: #5c5c5c; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1px 45px !important; padding: 0px;&quot;&gt;
&lt;li class=&quot;alt&quot; style=&quot;border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; color: inherit; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; margin: 0px; padding: 0px;&quot;&gt;Pushl&amp;nbsp;%ebp&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;&quot; style=&quot;background-color: #f8f8f8; border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;Movl&amp;nbsp;%esp,%ebp&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
Function-body code:&lt;br /&gt;&lt;div class=&quot;dp-highlighter&quot; style=&quot;background-color: #e7e5dc; font-family: Consolas, Monaco, &#39;Courier New&#39;, Courier, monospace; font-size: 12px; margin: 18px 0px !important; overflow: auto; padding-top: 1px; width: 770.21875px;&quot;&gt;
&lt;div class=&quot;bar&quot; style=&quot;padding-left: 45px;&quot;&gt;
&lt;div class=&quot;tools&quot; style=&quot;background-color: #f8f8f8; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; color: silver; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 9px; line-height: normal; padding: 3px 8px 10px 10px;&quot;&gt;
&lt;a href=&quot;http://clanguagestuff.blogspot.in/2013/10/stack-flow-in-function-calls-in-c.html#&quot; style=&quot;background-color: inherit; background-image: none; border: none; color: #a0a0a0; margin: 0px 10px 0px 0px; padding: 0px; text-decoration: none;&quot;&gt;view plain&lt;/a&gt;&lt;a href=&quot;http://clanguagestuff.blogspot.in/2013/10/stack-flow-in-function-calls-in-c.html#&quot; style=&quot;background-color: inherit; background-image: none; border: none; color: #a0a0a0; margin: 0px 10px 0px 0px; padding: 0px; text-decoration: none;&quot;&gt;print&lt;/a&gt;&lt;a href=&quot;http://clanguagestuff.blogspot.in/2013/10/stack-flow-in-function-calls-in-c.html#&quot; style=&quot;background-color: inherit; background-image: none; border: none; color: #a0a0a0; margin: 0px 10px 0px 0px; padding: 0px; text-decoration: none;&quot;&gt;?&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;ol class=&quot;dp-c&quot; style=&quot;background-color: white; border: none; color: #5c5c5c; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1px 45px !important; padding: 0px;&quot;&gt;
&lt;li class=&quot;alt&quot; style=&quot;border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; color: inherit; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; margin: 0px; padding: 0px;&quot;&gt;Subl&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;vars&quot; style=&quot;background-color: inherit; border: none; margin: 0px; padding: 0px;&quot;&gt;$12&lt;/span&gt;&lt;span style=&quot;background-color: inherit; border: none; margin: 0px; padding: 0px;&quot;&gt;,&amp;nbsp;%esp&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;&quot; style=&quot;background-color: #f8f8f8; border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;Movl&amp;nbsp;&lt;span class=&quot;vars&quot; style=&quot;background-color: inherit; border: none; margin: 0px; padding: 0px;&quot;&gt;$100&lt;/span&gt;&lt;span style=&quot;background-color: inherit; border: none; margin: 0px; padding: 0px;&quot;&gt;,&amp;nbsp;-12(%ebp)&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;alt&quot; style=&quot;border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; color: inherit; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;Movl&amp;nbsp;&lt;span class=&quot;vars&quot; style=&quot;background-color: inherit; border: none; margin: 0px; padding: 0px;&quot;&gt;$100&lt;/span&gt;&lt;span style=&quot;background-color: inherit; border: none; margin: 0px; padding: 0px;&quot;&gt;,&amp;nbsp;-8(%ebp)&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;&quot; style=&quot;background-color: #f8f8f8; border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;Movl&amp;nbsp;-8(%ebp),&amp;nbsp;%eax&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;alt&quot; style=&quot;border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; color: inherit; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;Addl&amp;nbsp;-12(%ebp)&amp;nbsp;,&amp;nbsp;%eax&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;&quot; style=&quot;background-color: #f8f8f8; border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;Movl&amp;nbsp;%eax,&amp;nbsp;-4(%ebp)&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
Post-amble code:&lt;br /&gt;&lt;div class=&quot;dp-highlighter&quot; style=&quot;background-color: #e7e5dc; font-family: Consolas, Monaco, &#39;Courier New&#39;, Courier, monospace; font-size: 12px; margin: 18px 0px !important; overflow: auto; padding-top: 1px; width: 770.21875px;&quot;&gt;
&lt;div class=&quot;bar&quot; style=&quot;padding-left: 45px;&quot;&gt;
&lt;div class=&quot;tools&quot; style=&quot;background-color: #f8f8f8; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; color: silver; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 9px; line-height: normal; padding: 3px 8px 10px 10px;&quot;&gt;
&lt;a href=&quot;http://clanguagestuff.blogspot.in/2013/10/stack-flow-in-function-calls-in-c.html#&quot; style=&quot;background-color: inherit; background-image: none; border: none; color: #a0a0a0; margin: 0px 10px 0px 0px; padding: 0px; text-decoration: none;&quot;&gt;view plain&lt;/a&gt;&lt;a href=&quot;http://clanguagestuff.blogspot.in/2013/10/stack-flow-in-function-calls-in-c.html#&quot; style=&quot;background-color: inherit; background-image: none; border: none; color: #a0a0a0; margin: 0px 10px 0px 0px; padding: 0px; text-decoration: none;&quot;&gt;print&lt;/a&gt;&lt;a href=&quot;http://clanguagestuff.blogspot.in/2013/10/stack-flow-in-function-calls-in-c.html#&quot; style=&quot;background-color: inherit; background-image: none; border: none; color: #a0a0a0; margin: 0px 10px 0px 0px; padding: 0px; text-decoration: none;&quot;&gt;?&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;ol class=&quot;dp-c&quot; style=&quot;background-color: white; border: none; color: #5c5c5c; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1px 45px !important; padding: 0px;&quot;&gt;
&lt;li class=&quot;alt&quot; style=&quot;border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; color: inherit; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; margin: 0px; padding: 0px;&quot;&gt;movl&amp;nbsp;%ebp,&amp;nbsp;%esp&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;&quot; style=&quot;background-color: #f8f8f8; border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;popl&amp;nbsp;%ebp&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;alt&quot; style=&quot;border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; color: inherit; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;popl&amp;nbsp;%eip&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;pre-amble and post-amble are the most important part to understand how the&amp;nbsp;stack&amp;nbsp;&lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD3&quot; style=&quot;background-attachment: scroll !important; background-color: transparent !important; background-image: none !important; background-position: 0% 50%; background-repeat: repeat repeat !important; border-bottom-color: rgb(0, 153, 0) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; color: rgb(0, 153, 0) !important; cursor: pointer !important; display: inline !important; float: none !important; padding: 0px 0px 1px !important; position: static; text-decoration: underline !important;&quot;&gt;flow&lt;/span&gt;&amp;nbsp;works&amp;nbsp;&lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD11&quot; style=&quot;background-attachment: scroll !important; background-color: transparent !important; background-image: none !important; background-position: 0% 50%; background-repeat: repeat repeat !important; border-bottom-color: rgb(0, 153, 0) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; color: rgb(0, 153, 0) !important; cursor: pointer !important; display: inline !important; float: none !important; padding: 0px 0px 1px !important; position: static; text-decoration: underline !important;&quot;&gt;in&amp;nbsp; function&lt;/span&gt;&amp;nbsp;in&amp;nbsp;c language,&lt;br /&gt;what is the ebp ,esp and&amp;nbsp;&lt;a class=&quot;kLink&quot; href=&quot;http://clanguagestuff.blogspot.in/2013/10/stack-flow-in-function-calls-in-c.html#&quot; id=&quot;KonaLink6&quot; style=&quot;background-color: transparent !important; background-image: none !important; border: 0px none transparent !important; bottom: 0px; color: blue; cursor: pointer; display: inline !important; font-family: inherit !important; font-size: inherit !important; font-weight: inherit !important; left: 0px; margin: 0px; outline: none; padding: 0px; position: static; right: 0px; top: 0px;&quot;&gt;&lt;span style=&quot;color: blue; font-family: inherit !important; font-size: inherit !important; font-weight: inherit !important; position: static;&quot;&gt;&lt;span class=&quot;kLink&quot; style=&quot;background-color: transparent; background-image: none; border-bottom-style: solid; border-bottom-width: 1px; border-left-style: none !important; border-left-width: 0px !important; border-right-style: none !important; border-right-width: 0px !important; border-top-style: none !important; border-top-width: 0px !important; display: inline !important; float: none !important; font-family: inherit !important; font-size: inherit !important; font-weight: inherit !important; padding: 0px 0px 1px !important; position: static; width: auto !important;&quot;&gt;eip&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&amp;nbsp;?&lt;br /&gt;ebp is the pointer to base address of the&amp;nbsp;stack&amp;nbsp;and&lt;br /&gt;esp is the pointer to top address of the&amp;nbsp;stack.&lt;br /&gt;eip is the pointer to the current instruction to be executed .&lt;br /&gt;&lt;br /&gt;Now let us take the instruction one by one and see what it means:&lt;br /&gt;&lt;br /&gt;&lt;b style=&quot;color: #073763;&quot;&gt;pushl %ebp&lt;/b&gt;&amp;nbsp;:--&amp;gt; This instruction means push the content/value of the ebp to the top of the&amp;nbsp;stack.&lt;br /&gt;&lt;b style=&quot;color: #073763;&quot;&gt;movl %esp,%ebp&lt;/b&gt;&amp;nbsp;:--&amp;gt; This instruction means copy the content/value of the esp to the ebp that is now both the pointers points to the same location.&lt;br /&gt;&lt;b style=&quot;color: #073763;&quot;&gt;subl $12, %esp&lt;/b&gt;&amp;nbsp;:--&amp;gt;This the first instruction of&amp;nbsp;the function&amp;nbsp;body and it does the job of allocating the space for&amp;nbsp;the function&amp;nbsp;on the&amp;nbsp;stack&amp;nbsp;by subtracting the total amount of space required for&amp;nbsp;the function&amp;nbsp;from the esp so that esp points to the top of the&amp;nbsp;stack&amp;nbsp;as it is defined to be.&lt;br /&gt;Note:&lt;br /&gt;you can also note that now there will be a difference of 12 bytes in the ebp and esp as per our example which is nothing but the space required by&amp;nbsp;the function&amp;nbsp;to allocate its local variables.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;b style=&quot;color: #073763;&quot;&gt;movl $100 , -12(%ebp)&lt;/b&gt;&amp;nbsp;:--&amp;gt; This instruction means that move the value 100 at the location 12 less than the location of ebp. that is if ebp is pointing to 1012 address location put the value 100 at 1000(1012-12).&lt;br /&gt;&lt;b style=&quot;color: #073763;&quot;&gt;popl %ebp&lt;/b&gt;&amp;nbsp;--&amp;gt; This instruction means that pop out the contents at the top of the&amp;nbsp;stack&amp;nbsp;that is value at the address pointed by the esp pointer.&lt;br /&gt;&lt;br /&gt;Rest the instruction meanings are self explanatory in corresponding to these instructions.&lt;br /&gt;&lt;br /&gt;Full code:&lt;br /&gt;&lt;div class=&quot;dp-highlighter&quot; style=&quot;background-color: #e7e5dc; font-family: Consolas, Monaco, &#39;Courier New&#39;, Courier, monospace; font-size: 12px; margin: 18px 0px !important; overflow: auto; padding-top: 1px; width: 770.21875px;&quot;&gt;
&lt;div class=&quot;bar&quot; style=&quot;padding-left: 45px;&quot;&gt;
&lt;div class=&quot;tools&quot; style=&quot;background-color: #f8f8f8; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; color: silver; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 9px; line-height: normal; padding: 3px 8px 10px 10px;&quot;&gt;
&lt;a href=&quot;http://clanguagestuff.blogspot.in/2013/10/stack-flow-in-function-calls-in-c.html#&quot; style=&quot;background-color: inherit; background-image: none; border: none; color: #a0a0a0; margin: 0px 10px 0px 0px; padding: 0px; text-decoration: none;&quot;&gt;view plain&lt;/a&gt;&lt;a href=&quot;http://clanguagestuff.blogspot.in/2013/10/stack-flow-in-function-calls-in-c.html#&quot; style=&quot;background-color: inherit; background-image: none; border: none; color: #a0a0a0; margin: 0px 10px 0px 0px; padding: 0px; text-decoration: none;&quot;&gt;print&lt;/a&gt;&lt;a href=&quot;http://clanguagestuff.blogspot.in/2013/10/stack-flow-in-function-calls-in-c.html#&quot; style=&quot;background-color: inherit; background-image: none; border: none; color: #a0a0a0; margin: 0px 10px 0px 0px; padding: 0px; text-decoration: none;&quot;&gt;?&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;ol class=&quot;dp-c&quot; style=&quot;background-color: white; border: none; color: #5c5c5c; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1px 45px !important; padding: 0px;&quot;&gt;
&lt;li class=&quot;alt&quot; style=&quot;border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; color: inherit; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; margin: 0px; padding: 0px;&quot;&gt;Main:&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;&quot; style=&quot;background-color: #f8f8f8; border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;Pushl&amp;nbsp;%ebp&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;alt&quot; style=&quot;border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; color: inherit; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;Movl&amp;nbsp;%esp,%ebp&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;&quot; style=&quot;background-color: #f8f8f8; border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;Subl&amp;nbsp;&lt;span class=&quot;vars&quot; style=&quot;background-color: inherit; border: none; margin: 0px; padding: 0px;&quot;&gt;$12&lt;/span&gt;&lt;span style=&quot;background-color: inherit; border: none; margin: 0px; padding: 0px;&quot;&gt;,&amp;nbsp;%esp&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;alt&quot; style=&quot;border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; color: inherit; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;Movl&amp;nbsp;&lt;span class=&quot;vars&quot; style=&quot;background-color: inherit; border: none; margin: 0px; padding: 0px;&quot;&gt;$100&lt;/span&gt;&lt;span style=&quot;background-color: inherit; border: none; margin: 0px; padding: 0px;&quot;&gt;,&amp;nbsp;-12(%ebp)&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;&quot; style=&quot;background-color: #f8f8f8; border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;Movl&amp;nbsp;&lt;span class=&quot;vars&quot; style=&quot;background-color: inherit; border: none; margin: 0px; padding: 0px;&quot;&gt;$100&lt;/span&gt;&lt;span style=&quot;background-color: inherit; border: none; margin: 0px; padding: 0px;&quot;&gt;,&amp;nbsp;-8(%ebp)&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;alt&quot; style=&quot;border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; color: inherit; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;Movl&amp;nbsp;-8(%ebp),&amp;nbsp;%eax&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;&quot; style=&quot;background-color: #f8f8f8; border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;Addl&amp;nbsp;-12(%ebp)&amp;nbsp;,&amp;nbsp;%eax&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;alt&quot; style=&quot;border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; color: inherit; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;Movl&amp;nbsp;%eax,&amp;nbsp;-4(%ebp)&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;&quot; style=&quot;background-color: #f8f8f8; border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;movl&amp;nbsp;%ebp,&amp;nbsp;%esp&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;alt&quot; style=&quot;border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; color: inherit; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;popl&amp;nbsp;%ebp&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;&quot; style=&quot;background-color: #f8f8f8; border-left-color: rgb(108, 226, 108); border-left-width: 3px; border-style: none none none solid; line-height: 14px; list-style: decimal-leading-zero outside; margin-bottom: 0.25em; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;popl&amp;nbsp;%eip&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br style=&quot;background-color: white; color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;&quot; /&gt;&lt;br style=&quot;background-color: white; color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;&quot; /&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;&quot;&gt;This is how we can convert the C code of&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;&quot;&gt;a function&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;&quot;&gt;&amp;nbsp;to&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD12&quot; style=&quot;background-attachment: scroll !important; background-color: white; background-image: none !important; background-position: 0% 50%; background-repeat: repeat repeat !important; border-bottom-color: rgb(0, 153, 0) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; color: rgb(0, 153, 0) !important; cursor: pointer !important; display: inline !important; float: none !important; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; padding: 0px 0px 1px !important; position: static; text-decoration: underline !important;&quot;&gt;the assembly&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;&quot;&gt;source code&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;&quot;&gt;. The main thing to understand is the pre-amble and the post-amble .&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/462709074270969046/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2013/12/how-to-translate-c-source-code-into.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/462709074270969046'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/462709074270969046'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2013/12/how-to-translate-c-source-code-into.html' title='How to translate C source code into assembly instruction for a function '/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWk8Zg0jSHrQ4mW0OM0oqYzmHyhDYmk_IBtJvqxGmq-Nz3w8cLn1FmE1NvxAo14BgacI2acp4UWMjWvE8_h4fEIH__jLdPcudA2LYEdyyJTswpevA-I4hDZpjlMGi4q_uPRYWcbraO5Q/s72-c/step1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-9079012305448958277</id><published>2013-10-13T00:07:00.001-07:00</published><updated>2013-10-13T00:09:29.315-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="function calling"/><category scheme="http://www.blogger.com/atom/ns#" term="stack flow"/><title type='text'>Stack Flow in function calls 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 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;
&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;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Today I am going to start a topic on how the stack works when we call a functions in c , how the function calls are executed internally. There are some questions which are very general in intervaiew like:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;How the stack is allocated for a function ?&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;How the calling a function works internally ?&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;How stack grows when we call a function within a function ?&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
There are lot more questions on the same stuff. So, we will able to answer all those question after going through the full topic series of this which will be covered in consecutive posts.&lt;br /&gt;
&lt;br /&gt;
So, To understand how the function call works we have to know little bit of assembly programming. Don&#39;t be afraid if you don&#39;t know the same. we don&#39;t require the expertise in that , we just require very basic knowledge.&lt;br /&gt;
&lt;br /&gt;
So to start with we will first learn:&lt;br /&gt;
&lt;br /&gt;
How to translate C source code into assembly instruction for a function :&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;color: #0c343d;&quot;&gt;
&lt;b&gt;Converting the function source code into the assembly is not a big deal , it is just a matter of 3 simple steps:&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;color: #0c343d;&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;color: #0c343d;&quot;&gt;
&lt;b&gt;1.) Identifying the non-executable statements within a function.&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;color: #0c343d;&quot;&gt;
&lt;b&gt;2.)Create a function symbol table and resolve all the non-executable instructions.&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;color: #0c343d;&quot;&gt;
&lt;b&gt;3.)Translate C source into assembly source.&lt;/b&gt;&lt;/div&gt;
&lt;br /&gt;
These steps sounds to be tough but if you have basic knowledge of c language these are very easy . let us take the steps one by one considering the follwing example of small code:&lt;br /&gt;
&lt;pre class=&quot;php&quot; name=&quot;code&quot;&gt;int main()
{
int a = 100;
int b = 100;
int c;
c = a+b;
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;color: #990000;&quot;&gt;
&lt;b&gt;Step1: Identifying the non-executable statements within a function&lt;/b&gt;&lt;/div&gt;
&lt;br /&gt;
To understand this step we have to know what are the non-executable statements ??&lt;br /&gt;
Whenever you write a program you always write them at the very beginning of you function body.yes you guessed it right the variable declarations are the ones.&lt;br /&gt;
we can define the non-executable statements as:&lt;br /&gt;
&lt;br /&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;
  &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-US&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:DontVertAlignCellWithSp/&gt;
   &lt;w:DontBreakConstrainedForcedTables/&gt;
   &lt;w:DontVertAlignInTxbx/&gt;
   &lt;w:Word11KerningPairs/&gt;
   &lt;w:CachedColBalance/&gt;
  &lt;/w:Compatibility&gt;
  &lt;w:BrowserLevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&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;--&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-qformat:yes;
 mso-style-parent:&quot;&quot;;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-para-margin-top:0in;
 mso-para-margin-right:0in;
 mso-para-margin-bottom:10.0pt;
 mso-para-margin-left:0in;
 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-fareast-font-family:&quot;Times New Roman&quot;;
 mso-fareast-theme-font:minor-fareast;
 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;}
&lt;/style&gt;
&lt;![endif]--&gt;&lt;span style=&quot;font-family: &amp;quot;Calibri&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11pt; line-height: 115%;&quot;&gt;Non-executable
statements are those which are not converted to the instructions to be executed by the processor. It means that they are just the memory allocation instruction which are processed by the compilers.&lt;/span&gt; &lt;br /&gt;
&lt;br /&gt;
So, in our example we have three non-executable statements shown in the figure below.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWk8Zg0jSHrQ4mW0OM0oqYzmHyhDYmk_IBtJvqxGmq-Nz3w8cLn1FmE1NvxAo14BgacI2acp4UWMjWvE8_h4fEIH__jLdPcudA2LYEdyyJTswpevA-I4hDZpjlMGi4q_uPRYWcbraO5Q/s1600/step1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;141&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWk8Zg0jSHrQ4mW0OM0oqYzmHyhDYmk_IBtJvqxGmq-Nz3w8cLn1FmE1NvxAo14BgacI2acp4UWMjWvE8_h4fEIH__jLdPcudA2LYEdyyJTswpevA-I4hDZpjlMGi4q_uPRYWcbraO5Q/s320/step1.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span id=&quot;goog_479344805&quot;&gt;&lt;/span&gt;&lt;span id=&quot;goog_479344806&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;color: #990000;&quot;&gt;
&lt;b&gt;Step2: Creating the function symbol and resolving all non-executable statements.&lt;/b&gt;&lt;/div&gt;
&lt;br /&gt;
Function Symbol table consists of 4 values:&lt;br /&gt;
1.)Symbol Name&lt;br /&gt;
2.)Type&lt;br /&gt;
3.)Composition (size of data type of symbol)&lt;br /&gt;
4.)Offset Address&lt;br /&gt;
&lt;br /&gt;
You can easily fill the symbol table as shown below for our example.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEga0OuFhnvtiYjJCTzbdupW1uOdPdDIjo5sWuJg93ctzWc16KLUn_nnVI4_nH7NaI9NTXrZwGJzJgZ5OauBFEWP_UKpy6rG_qytByCriMjMaOnqcHO3zKoADsxEst1JygcdpQDuN8Eajg/s1600/step_2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;97&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEga0OuFhnvtiYjJCTzbdupW1uOdPdDIjo5sWuJg93ctzWc16KLUn_nnVI4_nH7NaI9NTXrZwGJzJgZ5OauBFEWP_UKpy6rG_qytByCriMjMaOnqcHO3zKoADsxEst1JygcdpQDuN8Eajg/s400/step_2.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
As you can see in the above table , we have taken the variable names as symbols and added their type and size in the respective columns.&lt;br /&gt;
&lt;br /&gt;
After filling the table we have calculate the total size which comes out to be 12 . Basically this 12 is the size of the stack for the function main which will be allocated when the main function will be called.&lt;br /&gt;
&lt;br /&gt;
Now the last column is the offset address . Offest Addresses are allocated by the compiler.&lt;span style=&quot;font-family: &amp;quot;Calibri&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11pt; line-height: 115%;&quot;&gt; &lt;/span&gt;let us see how we will fill that column.&lt;br /&gt;
&lt;br /&gt;
Let us take the base pointer to the stack as ebp and assume that stack grows downwards (which happens most of the tym ).&lt;br /&gt;
&lt;br /&gt;
As the size of the stack is 12 and a is the first variable declared in the function so,&lt;br /&gt;
&lt;br /&gt;
Variable &#39;a&#39; will get the memory at -12(%ebp)&amp;nbsp; that is -12 from ebp (stack base pointer) &lt;br /&gt;
Variable &#39;b&#39; will get the memory at -8(%ebp) because &#39;a&#39; is of 4 bytes.&lt;br /&gt;
Variable &#39;c&#39; will get the memory ar -4(%ebp) because &#39;b&#39; is also of 4 bytes.&lt;br /&gt;
&lt;br /&gt;
So, The final function symbol will be:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjehfkYDH6lNUZ_yphjtDU_XoVG-Vsx0HcIytT1gYZ191S439mYy_mpZGiMY3T3N-KhbvLFEQh6JfOAYaoEffWbRNM1L4klc6z_oIQdIZESfLIYeZniE95c22UwvUpDGmqKsgQ3pOVa4w/s1600/step2_1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;98&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjehfkYDH6lNUZ_yphjtDU_XoVG-Vsx0HcIytT1gYZ191S439mYy_mpZGiMY3T3N-KhbvLFEQh6JfOAYaoEffWbRNM1L4klc6z_oIQdIZESfLIYeZniE95c22UwvUpDGmqKsgQ3pOVa4w/s400/step2_1.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;color: #990000;&quot;&gt;
&lt;b&gt;Step3: Translating C code to assembly language.&lt;/b&gt;&lt;/div&gt;
&lt;br /&gt;
In this process whenever we have to access the variable we will replace that by the offset address given in the function symbol table.&lt;br /&gt;
&lt;span id=&quot;goog_204380558&quot;&gt;&lt;/span&gt;&lt;span id=&quot;goog_204380559&quot;&gt;&lt;/span&gt;&lt;br /&gt;
To convert the function C source code into assembly we need to know one thing that is GNU compilers follows a standard which says that:&lt;br /&gt;
&lt;br /&gt;
&quot;Every function consist of 4 parts which are:&lt;br /&gt;
1.) Function name&lt;br /&gt;
2.)Pre-amble (the opening brace of function)&lt;br /&gt;
3.)Function-body&lt;br /&gt;
4.)Post-amble (the closing brace of function)&quot;&lt;br /&gt;
&lt;br /&gt;
And the same is written as the following:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;color: #990000;&quot;&gt;
&lt;b&gt;Function name :&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;color: #990000;&quot;&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pre-amble&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;color: #990000;&quot;&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; function-body&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;color: #990000;&quot;&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; post-amble.&lt;/b&gt;&lt;/div&gt;
&lt;br /&gt;
Here pre-amble defines the code for the opening curly brace and&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; post-amble defines the code for the closing curly brace.&lt;br /&gt;
&lt;br /&gt;
Let us take a look at the both the pre-amble ,function body and post-amble small piece of code:&lt;br /&gt;
&lt;br /&gt;
Pre-amble code:
&lt;/div&gt;
&lt;pre class=&quot;php&quot; name=&quot;code&quot;&gt;Pushl %ebp
Movl %esp,%ebp
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
Function-body code:&lt;br /&gt;
&lt;pre class=&quot;php&quot; name=&quot;code&quot;&gt;Subl $12, %esp
Movl $100, -12(%ebp)
Movl $100, -8(%ebp)
Movl -8(%ebp), %eax
Addl -12(%ebp) , %eax
Movl %eax, -4(%ebp)
&lt;/pre&gt;
Post-amble code:&lt;br /&gt;
&lt;pre class=&quot;php&quot; name=&quot;code&quot;&gt;movl %ebp, %esp
popl %ebp
popl %eip
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
pre-amble and post-amble are the most important part to understand how the stack flow works in&amp;nbsp; function in c language,&lt;br /&gt;
what is the ebp ,esp and eip ?&lt;br /&gt;
ebp is the pointer to base address of the stack and&lt;br /&gt;
esp is the pointer to top address of the stack.&lt;br /&gt;
eip is the pointer to the current instruction to be executed .&lt;br /&gt;
&lt;br /&gt;
Now let us take the instruction one by one and see what it means:&lt;br /&gt;
&lt;br /&gt;
&lt;b style=&quot;color: #073763;&quot;&gt;pushl %ebp&lt;/b&gt; :--&amp;gt; This instruction means push the content/value of the ebp to the top of the stack.&lt;br /&gt;
&lt;b style=&quot;color: #073763;&quot;&gt;movl %esp,%ebp&lt;/b&gt; :--&amp;gt; This instruction means copy the content/value of the esp to the ebp that is now both the pointers points to the same location.&lt;br /&gt;
&lt;b style=&quot;color: #073763;&quot;&gt;subl $12, %esp&lt;/b&gt; :--&amp;gt;This the first instruction of the function body and it does the job of allocating the space for the function on the stack by subtracting the total amount of space required for the function from the esp so that esp points to the top of the stack as it is defined to be.&lt;br /&gt;
Note:&lt;br /&gt;
you can also note that now there will be a difference of 12 bytes in 
the ebp and esp as per our example which is nothing but the space 
required by the function to allocate its local variables.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&lt;b style=&quot;color: #073763;&quot;&gt;movl $100 , -12(%ebp)&lt;/b&gt; :--&amp;gt; This instruction means that move the value 100 at the location 12 less than the location of ebp. that is if ebp is pointing to 1012 address location put the value 100 at 1000(1012-12).&lt;br /&gt;
&lt;b style=&quot;color: #073763;&quot;&gt;popl %ebp&lt;/b&gt; --&amp;gt; This instruction means that pop out the contents at the top of the stack that is value at the address pointed by the esp pointer. &lt;br /&gt;
&lt;br /&gt;
Rest the instruction meanings are self explanatory in corresponding to these instructions.&lt;br /&gt;
&lt;br /&gt;
Full code:
&lt;br /&gt;
&lt;pre class=&quot;php&quot; name=&quot;code&quot;&gt;Main:
Pushl %ebp
Movl %esp,%ebp
Subl $12, %esp
Movl $100, -12(%ebp)
Movl $100, -8(%ebp)
Movl -8(%ebp), %eax
Addl -12(%ebp) , %eax
Movl %eax, -4(%ebp)
movl %ebp, %esp
popl %ebp
popl %eip
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
This is how we can convert the C code of a function to the assembly source code. The main thing to understand is the pre-amble and the post-amble .&lt;br /&gt;
&lt;br /&gt;
I will explain the significance with the example in the next post with step by step change in the stack when we execute these instruction. then it will be cleared why we are using these instruction, so stay tuned for the next post.&lt;br /&gt;
&lt;br /&gt;
If you have any doubt in this , feel free to comment.&lt;br /&gt;
&lt;br /&gt;
Have Fun !!!!&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/9079012305448958277/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2013/10/stack-flow-in-function-calls-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/9079012305448958277'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/9079012305448958277'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2013/10/stack-flow-in-function-calls-in-c.html' title='Stack Flow in function calls in C'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWk8Zg0jSHrQ4mW0OM0oqYzmHyhDYmk_IBtJvqxGmq-Nz3w8cLn1FmE1NvxAo14BgacI2acp4UWMjWvE8_h4fEIH__jLdPcudA2LYEdyyJTswpevA-I4hDZpjlMGi4q_uPRYWcbraO5Q/s72-c/step1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-6637528245897928728</id><published>2013-10-02T08:33:00.001-07:00</published><updated>2013-10-02T08:44:21.699-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Quiz"/><title type='text'>C Language Basic Quiz</title><content type='html'>Please Comment feedback and Queries about the questions after completing.
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;iframe frameborder=&quot;0&quot; height=&quot;750&quot; id=&quot;proprofs&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; name=&quot;proprofs&quot; src=&quot;http://www.proprofs.com/quiz-school/story.php?title=NTYxMTE0&amp;amp;id=560822&amp;amp;ew=700&quot; width=&quot;720&quot;&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;div style=&quot;color: black; font-family: Arial, Helvetica, sans-serif; font-size: 10px; text-align: center;&quot;&gt;
&lt;a href=&quot;http://www.proprofs.com/quiz-school/story.php?title=NTYxMTE0&quot; target=&quot;_blank&quot; title=&quot;C Language Basic Quiz&quot;&gt;C Language Basic Quiz&lt;/a&gt; » &lt;a href=&quot;http://www.proprofs.com/quiz-school/&quot; target=&quot;_blank&quot; title=&quot;Online Exam maker&quot;&gt;Online Exam maker&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/6637528245897928728/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2013/10/c-language-basic-quiz.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/6637528245897928728'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/6637528245897928728'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2013/10/c-language-basic-quiz.html' title='C Language Basic Quiz'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-7152555475539968844</id><published>2013-09-29T01:09:00.001-07:00</published><updated>2013-09-29T03:57:39.206-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Algorithms"/><title type='text'>Tower Of Hanoi Continued...</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
As I have described in the &lt;a href=&quot;http://clanguagestuff.blogspot.in/2013/09/tower-of-hanoi.html&quot; target=&quot;_blank&quot;&gt;previous post&lt;/a&gt; , Here is the Recursion Tree of the Tower. If you are able to draw the recursion tree of a a problem you will be able to code that too very easily.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_MaD9Br2wU9yobRsVOMh8oCIerGRb9fRyJaSjsJ4KRKjuF5dYFEwkVG-PQaG2ZpBycR6Prca6YYJJGxj5REKYwBbv1eWhxFx5MGW3Sw_PaqQKFUX_Zg-ttEzgGqOKEzZ4SAGT_OFZUg/s1600/recustion_tree.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;110&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_MaD9Br2wU9yobRsVOMh8oCIerGRb9fRyJaSjsJ4KRKjuF5dYFEwkVG-PQaG2ZpBycR6Prca6YYJJGxj5REKYwBbv1eWhxFx5MGW3Sw_PaqQKFUX_Zg-ttEzgGqOKEzZ4SAGT_OFZUg/s400/recustion_tree.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
This Tree is self explanatory , In this we have Decomposed the 3 Disc problem into 3 steps and recursively solved the same.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
So, Now we can write the Program for the same , It does not depend which programming language you use to code , the algorithm will be the same.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Tower Of Hanoi Algorithm Implementation.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre name=&quot;code&quot; class=&quot;php&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;
int main()
{
int number_of_discs;
printf(&amp;quot;Enter the Number of discs:&amp;quot;);
scanf(&amp;quot;%d&amp;quot;,&amp;amp;number_of_discs);
printf(&amp;quot;\n&amp;quot;);
Towers(number_of_discs,&#39;A&#39;,&#39;B&#39;,&#39;C&#39;);
}

void Towers(int N,char From, char To, char Via)
{
   if(N==1)
{
printf(&amp;quot;Moving %c to %c\n &amp;quot;, From , To);
}
else
{
  Towers(N-1,From,Via,To);                     //(N-1,A,C,B)
  printf(&amp;quot;Moving %c to %c\n&amp;quot; , From , To);    //(1,A,B,C)
  Towers(N-1,Via, To,From);                   //(N-1,C,B,A)
}

}
&lt;/pre&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/7152555475539968844/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2013/09/tower-of-hanoi-continued.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/7152555475539968844'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/7152555475539968844'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2013/09/tower-of-hanoi-continued.html' title='Tower Of Hanoi Continued...'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_MaD9Br2wU9yobRsVOMh8oCIerGRb9fRyJaSjsJ4KRKjuF5dYFEwkVG-PQaG2ZpBycR6Prca6YYJJGxj5REKYwBbv1eWhxFx5MGW3Sw_PaqQKFUX_Zg-ttEzgGqOKEzZ4SAGT_OFZUg/s72-c/recustion_tree.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-2283520455461965726</id><published>2013-09-29T00:50:00.000-07:00</published><updated>2013-09-29T02:42:16.598-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Algorithms"/><title type='text'>Tower Of Hanoi</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Today I will try to explain the Tower Of Hanoi Algorithm in
Full detail. I don’t want you to just mug up the 3 lines of code and pass an
exam . I want you to learn How we reach to the solution. How we decompose the
problem and recompose it again to get the solution which is very important to
solve a problem like this. You will also learn how to apply the recursion to
get the desired solution.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Tower Of Hanoi:- The problem description is as follows:&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
We have Three pillars/pegs and N discs of different size on
One pillar/peg such that They are in Incresing order of size from top to
bottom.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
What we have to do?&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
We have to move the Discs from&amp;nbsp; Source Peg to &amp;nbsp;Destination Peg &amp;nbsp;keeping the following constraints in Mind.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Constraints:&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
1.)We can take one peg out at a time.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
2.)We can’t place small disc below the larger one during the
task.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
3.)We can only use one more pillar for help to complete the
solution.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Problem:&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwU9VEHKSkH5Q7qc69LMQfdr3qtX99p6Lf45_KIXQRVlEzjlQc5d-vzIrOzuce-3HkXt28hJy_W6S9CB0X157dJeoblZVeq7FaYLEMw757FjDIiwQlB883hPq6jUmDPUUfqmAwJGndeQ/s1600/prblm.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;110&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwU9VEHKSkH5Q7qc69LMQfdr3qtX99p6Lf45_KIXQRVlEzjlQc5d-vzIrOzuce-3HkXt28hJy_W6S9CB0X157dJeoblZVeq7FaYLEMw757FjDIiwQlB883hPq6jUmDPUUfqmAwJGndeQ/s320/prblm.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Solution:&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWXSf_WKQ0YJZTByH-o5qhnTlO7Wpz-PMwm-VIZRqj6K0X7jCWhc-iLmS79pelgqJuVTAUIyTxaYrb6rTTJ4zaPZcpoL4BIhMWvjbhtqY4QlAwh837oCV5_fxFPcI0c1rBsy8uNJILlQ/s1600/solution.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;113&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWXSf_WKQ0YJZTByH-o5qhnTlO7Wpz-PMwm-VIZRqj6K0X7jCWhc-iLmS79pelgqJuVTAUIyTxaYrb6rTTJ4zaPZcpoL4BIhMWvjbhtqY4QlAwh837oCV5_fxFPcI0c1rBsy8uNJILlQ/s320/solution.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
We have described the problem the solution above. Now we have to think how to solve the same.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Let Us decompose the problem and try to solve it&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Let us Assume that we have only one Disc On peg A and We have to move the same to the Peg B.The solution is obvious , We will just pick the disc and put it on B and the problem is solved , let us see the same in Picture.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;Solution of 1 disc Problem&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghAImveUkmNgLwRM2khhnoLG1VBs-k19LBlmJvoRO53vBGOcS_f-ptmRpa3DQxV-ofjvq6LNAv2Qf9IiOxOlrRSP2KEP07XlQNjAKdhEwopQL76ONxISfxqZVAX9ury3vm9nZqFCq2BA/s1600/one_disc_problm.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;240&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghAImveUkmNgLwRM2khhnoLG1VBs-k19LBlmJvoRO53vBGOcS_f-ptmRpa3DQxV-ofjvq6LNAv2Qf9IiOxOlrRSP2KEP07XlQNjAKdhEwopQL76ONxISfxqZVAX9ury3vm9nZqFCq2BA/s320/one_disc_problm.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;(1,A,B,C) &lt;/span&gt;denotes that we have moved 1 disc from A to B using C.&lt;/b&gt;&lt;/h3&gt;
&lt;div&gt;
SO, (1,A,B,C) solves the One Disc Problem.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Now , Let Us Assume that We have Two Disc and We have to move both disc from A to B. Let us see the solution of Two Disc Problem in Picture.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Solution Of 2 Discs problem&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLKE8TT4AkzWBd8QBUjTTUxd6hAyr3pqB3cXEoTbYg31GIT7pD2qrMYCihq3IK0fEokhES1D0bAVyDmXN3S6R6mbhNItS3MWcqh7xQtiS53CiBIgKvEPiuskM-0eW-sMDJ8ww5TFO9lA/s1600/2_Disc_solution.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLKE8TT4AkzWBd8QBUjTTUxd6hAyr3pqB3cXEoTbYg31GIT7pD2qrMYCihq3IK0fEokhES1D0bAVyDmXN3S6R6mbhNItS3MWcqh7xQtiS53CiBIgKvEPiuskM-0eW-sMDJ8ww5TFO9lA/s640/2_Disc_solution.png&quot; width=&quot;388&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
So, To solve 2 Disc problem we have followed the following 3 steps:&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;1.) (1,A,C,B)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;2.) (1,A,B,C)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;3.) (1,C,B,A)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Now Let us Take the 3 Disc Problem, Now we have to move the 3 discs from A to B.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Solution of 3 Disc Problem:&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8BboZWIT9DWZN69ryu7fvEey2xmF4arRlugqtX9qhgA7MM_QGjRUXyZWCIFVRFU6EUWep43mCEsmMWuigZLps50dTzSMH3Jwf2k2_Qqg5Yay93MhUgnnYnNdhwWy8Y1wXP4ad_PpGSg/s1600/3_disc_solution.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8BboZWIT9DWZN69ryu7fvEey2xmF4arRlugqtX9qhgA7MM_QGjRUXyZWCIFVRFU6EUWep43mCEsmMWuigZLps50dTzSMH3Jwf2k2_Qqg5Yay93MhUgnnYnNdhwWy8Y1wXP4ad_PpGSg/s640/3_disc_solution.png&quot; width=&quot;358&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Now if We see The solution of 2 Disc &lt;span style=&quot;color: red;&quot;&gt;Problem&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;(2,A,B,C)&lt;/span&gt; is :&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;1) (1,A,C,B) &amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;2.) (1,A,B,C)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;3.) 1(C,B,A)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;So,The First 3 steps:&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;1.) (1,A,B,C)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;2.) (1,A,C,B)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;3.) (1,B,C,A)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&amp;nbsp;of the 3 disc problem is the solution of&lt;span style=&quot;color: red;&quot;&gt; Problem&amp;nbsp;(2,A,C,B)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;And,The 4th Step:&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;4.) (1,A,B,C)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;is the solution of&lt;span style=&quot;color: red;&quot;&gt; Problem(1,A,B,C)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;And the last 3 steps:&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;5.) (1,C,A,B)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;6.) (1,C,B,A)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;7.) (1,A,B,C)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;is the solution of&lt;span style=&quot;color: red;&quot;&gt; Problem(2,C,B,A)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;So the solution of&lt;span style=&quot;color: red;&quot;&gt; 3 disc problem(3,A,B,C) can be written as:&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;1.) (2,A,C,B)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;2.) (1,A,B,C)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;3.) (2,C,B,A).&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;and Similarly the solution of&lt;span style=&quot;color: red;&quot;&gt; N disc problem(n,A,B,C) can be written as:&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;1.) (n-1,A,C,B)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;2.) (1,A,B,C)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;3.) (n-1,C,B,A).&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;So, In this way we have decomposed the problem into three parts to solve it.&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Now let us say&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;A--&amp;gt;From&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;B--&amp;gt;To&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;C--&amp;gt;Via&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;So the Tower of hanoid problem is (N,From,To,Via) which can be solved in three steps:&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;1.) (n-1,From,Via,To) -- first solve the problem of moving &lt;span style=&quot;color: blue;&quot;&gt;n-1 discs From to Via&lt;/span&gt; .&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;2.) (1,From,To,Via) -- Then solve the problem of moving &lt;span style=&quot;color: blue;&quot;&gt;1 disc From to To&lt;/span&gt;.&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;3.) (n-1,Via,To,From) -- Then Solve the problem of moving &lt;span style=&quot;color: blue;&quot;&gt;n-1 disc from Via to To back&lt;/span&gt;.&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;We can also draw the &lt;a href=&quot;http://clanguagestuff.blogspot.in/2013/09/tower-of-hanoi-continued.html&quot; target=&quot;_blank&quot;&gt;Recursion Tree of the problem Here.&lt;/a&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/2283520455461965726/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2013/09/tower-of-hanoi.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/2283520455461965726'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/2283520455461965726'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2013/09/tower-of-hanoi.html' title='Tower Of Hanoi'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwU9VEHKSkH5Q7qc69LMQfdr3qtX99p6Lf45_KIXQRVlEzjlQc5d-vzIrOzuce-3HkXt28hJy_W6S9CB0X157dJeoblZVeq7FaYLEMw757FjDIiwQlB883hPq6jUmDPUUfqmAwJGndeQ/s72-c/prblm.png" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-1652320570262974991</id><published>2013-09-23T11:06:00.000-07:00</published><updated>2013-09-24T07:44:20.830-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="storage classes in C"/><title type='text'>Storage Classes in C</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Today I am going to explain the most important concept of C language.&lt;br /&gt;
If you have gone through any interview , It is quite possible that you came across the questions like:&lt;br /&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;b&gt;&lt;span style=&quot;color: orange;&quot;&gt;What do you mean by storage class in C?&lt;/span&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;span style=&quot;color: orange;&quot;&gt;How many storage classes are there in C?&lt;/span&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;span style=&quot;color: orange;&quot;&gt;Explain the different storage classes in C ?&lt;/span&gt;&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;br /&gt;
So, I will be explaining the storage class concept in full detail with all its types.&lt;br /&gt;
&lt;br /&gt;
Let us start by understanding &lt;span style=&quot;color: orange;&quot;&gt;&lt;b&gt;What it means by a Storage class?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
We know that Every variable posses the following property:&lt;br /&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;b&gt;Lifetime:&lt;/b&gt; Lifetime of a variable defines &quot;till what time we can access a particular variable&quot;.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Scope:&lt;/b&gt; Scope of a variable defined &quot;Where we can access a variable in our hundred and thousands lines of code&quot;.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Default value:&lt;/b&gt; what is the default value of the variable when it is only declared that is programmer has not assigned any value to it explicitly.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Storage place:&lt;/b&gt; Storage of a variable defined Where the variable is getting the memory to be accessed.&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;br /&gt;
All the above properties are tied to the variables , and the specifiers consisting of these properties specify the storage class of a variable...&lt;br /&gt;
&lt;br /&gt;
So, We can say that &lt;b&gt;&lt;span style=&quot;color: orange;&quot;&gt;Storage class is an attribute/specifier which defines Lifetime,scope,storage and default value of a variable.&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
For defining different lifetime,scope,storage and default value the storage classes are categorized into 4 categories:&lt;br /&gt;
1.)Auto&lt;br /&gt;
2.)Static&lt;br /&gt;
3.)Extern&lt;br /&gt;
4.)Register&lt;br /&gt;
&lt;br /&gt;
So, just by saying that this is an auto variable, a static variable , a extern variable or a register variable we are&lt;br /&gt;
telling about all the four properties of a variable.&lt;br /&gt;
&lt;br /&gt;
Explanation of all the classes coming soon one by one.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/1652320570262974991/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2013/09/storage-classes-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/1652320570262974991'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/1652320570262974991'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2013/09/storage-classes-in-c.html' title='Storage Classes in C'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-8674765797010991227</id><published>2013-08-13T06:57:00.002-07:00</published><updated>2013-09-29T04:08:53.819-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="multithreading in C"/><title type='text'>gettid() vs pthread_self()</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;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;So we have looked at both&amp;nbsp;&lt;a href=&quot;http://techdip.webs.com/apps/blog/show/13955116-getting-the-thread-id&quot; rel=&quot;nofollow&quot; style=&quot;border-bottom-color: rgb(205, 221, 231); color: #005081; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;gettid(getting the id of the thread)&lt;/a&gt;&amp;nbsp;and the&amp;nbsp;&lt;a href=&quot;http://techdip.webs.com/apps/blog/show/13954982-pthread-self-&quot; rel=&quot;nofollow&quot; style=&quot;border-bottom-color: rgb(205, 221, 231); color: #005081; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;pthread_self()&lt;/a&gt;,Now let us join then as see the output...so the difference between then is clear...&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;

&lt;pre name=&quot;code&quot; class=&quot;php&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;stdlib.h&amp;gt;
#include&amp;lt;pthread.h&amp;gt;
#include&amp;lt;linux/unistd.h&amp;gt;
#include&amp;lt;sys/syscall.h&amp;gt;
void* printid(void *ptr)
{
printf(&amp;quot;The id of %s is %u\n&amp;quot;,(char*)ptr,syscall( __NR_gettid ));
printf(&amp;quot;The id of %s is %u\n&amp;quot;,(char*)ptr,(unsigned int)pthread_self());
}
int main()
{
    pthread_t thread[5];
    char *msg[]={&amp;quot;thread1&amp;quot;,&amp;quot;thread2&amp;quot;,&amp;quot;thread3&amp;quot;,&amp;quot;thread4&amp;quot;,&amp;quot;thread5&amp;quot;};
    int i;
    for(i=0;i&amp;lt;5;i++)
    {
        pthread_create(&amp;amp;thread[i],NULL,printid,(void*)msg[i]);
        pthread_join(thread[i],NULL);
    }
    return 0;
}
&lt;/pre&gt;

&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;output:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;The id of thread1 is 18799&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;The id of thread1 is 3086543760&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;The id of thread2 is 18800&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;The id of thread2 is 3086543760&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;The id of thread3 is 18801&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;The id of thread3 is 3086543760&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;The id of thread4 is 18802&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;The id of thread4 is 3086543760&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;The id of thread5 is 18803&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;The id of thread5 is 3086543760&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: #333399; font-size: small;&quot;&gt;Explanation:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: #333399; font-size: small;&quot;&gt;As you can see the ID generated by pthread_self() is reused by the threading implementation after the thread completion which have achieved using the join in the for loop..and the ID assigned by the kernel is unique one...&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: #993300; font-size: small;&quot;&gt;So the difference between gettid() and the pthread_self() is:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: #993300; font-size: small;&quot;&gt;1.)POSIX thread IDs are assigned and maintained by the threading implementation. The thread ID returned by gettid() is a number (similar to a process ID) that is assigned by the kernel.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: #993300; font-size: small;&quot;&gt;2.)ID generated by the pthread_self() can be used after the completion of the thread but&amp;nbsp; the ID genereated by the kernel can&#39;t be used even after the completion of the thread..&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/8674765797010991227/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2013/08/gettid-vs-pthreadself.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/8674765797010991227'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/8674765797010991227'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2013/08/gettid-vs-pthreadself.html' title='gettid() vs pthread_self()'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-4851847363248176081</id><published>2013-08-13T06:57:00.000-07:00</published><updated>2013-09-29T04:11:21.360-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="multithreading in C"/><title type='text'>Getting the Thread ID 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;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: #993300; font-size: small;&quot;&gt;As we have see in the&amp;nbsp;&lt;a href=&quot;http://techdip.webs.com/apps/blog/show/13954982-pthread-self-&quot; rel=&quot;nofollow&quot; style=&quot;border-bottom-color: rgb(205, 221, 231); color: #005081; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;pthread_self()&lt;/a&gt;,the ID is implemented or maintained by threading implementation not by the kernel,so for getting the unique ID assiged by the kernel we have to use the system call...&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Take a look at the example...&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;

&lt;pre name=&quot;code&quot; class=&quot;php&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;stdlib.h&amp;gt;
#include&amp;lt;pthread.h&amp;gt;
#include&amp;lt;linux/unistd.h&amp;gt;
#include&amp;lt;sys/syscall.h&amp;gt;
void* printid(void *ptr)
{
printf(&amp;quot;The id of %s is %u\n&amp;quot;,(char*)ptr,syscall( __NR_gettid ));
}
int main()
{
    pthread_t thread[5];
    char *msg[]={&amp;quot;thread1&amp;quot;,&amp;quot;thread2&amp;quot;,&amp;quot;thread3&amp;quot;,&amp;quot;thread4&amp;quot;,&amp;quot;thread5&amp;quot;};
    int i;
    for(i=0;i&amp;lt;5;i++)
    {
        pthread_create(&amp;amp;thread[i],NULL,printid,(void*)msg[i]);
        pthread_join(thread[i],NULL);
    }
    return 0;
}
&lt;/pre&gt;
&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;output:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;On my system the output is:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;The id of thread1 is 18622&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;The id of thread2 is 18623&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;The id of thread3 is 18624&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;The id of thread4 is 18625&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;The id of thread5 is 18626&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: navy; font-size: small;&quot;&gt;As you can see now the IDs are different because they are assigned by the kernel not by the threading implementation...&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;Also look at :&lt;a href=&quot;http://techdip.webs.com/apps/blog/show/13955488-gettid-vs-pthread-self-&quot; rel=&quot;nofollow&quot; style=&quot;border-bottom-color: rgb(205, 221, 231); color: #005081; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;gettid() vs pthread_self()&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/4851847363248176081/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2013/08/getting-thread-id-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/4851847363248176081'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/4851847363248176081'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2013/08/getting-thread-id-in-c.html' title='Getting the Thread ID In C'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-3747300620693696808</id><published>2013-08-13T06:56:00.001-07:00</published><updated>2013-09-29T04:13:34.477-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="multithreading in C"/><title type='text'>pthread_self()</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;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Getting the Thread ID..&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;We can get the ID of the thread by using the funciton pthread_self() on the running thread.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;The main point about this function is :It uniquely identifies&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #ff6600; font-size: small;&quot;&gt;EXISTING&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;threads,Here&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #ff6600; font-size: small;&quot;&gt;EXISTING&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;has a special meaning..The meaning is&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #ff6600; font-size: small;&quot;&gt;pthread_self()&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;return the value which can be reused across the program that means if you have created a thread and it completed its execution then the id of that thread can be used as the id of another thread..&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Let us prove the statement that is a thread completes then the id of that thread(returned by pthread_self) can be used as the id of another thread...&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;

&lt;pre name=&quot;code&quot; class=&quot;php&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;stdlib.h&amp;gt;
#include&amp;lt;pthread.h&amp;gt;
#include&amp;lt;linux/unistd.h&amp;gt;
#include&amp;lt;sys/syscall.h&amp;gt;
void* printid(void *ptr)
{
printf(&amp;quot;The id of %s is %u\n&amp;quot;,(char*)ptr,(unsigned int)pthread_self());
}
int main()
{
    pthread_t thread[5];
    char *msg[]={&amp;quot;thread1&amp;quot;,&amp;quot;thread2&amp;quot;,&amp;quot;thread3&amp;quot;,&amp;quot;thread4&amp;quot;,&amp;quot;thread5&amp;quot;};
    int i;
    for(i=0;i&amp;lt;5;i++)
    {
        pthread_create(&amp;amp;thread[i],NULL,printid,(void*)msg[i]);
        pthread_join(thread[i],NULL);
    }
    return 0;
}
&lt;/pre&gt;

&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;output:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;On my system the output is:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;The id of thread1 is 3086285712&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;The id of thread2 is 3086285712&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;The id of thread3 is 3086285712&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;The id of thread4 is 3086285712&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;The id of thread5 is 3086285712&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: #333399; font-size: small;&quot;&gt;As you can see the ID&#39;s of all the thread is equal...&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: #333399; font-size: small;&quot;&gt;Explanation:I need to explain only one thing that is how to make sure that a thread completes before the execution of the next thread the answer is simple joining the thread solves our purpose..so in the for loop we create a thread then call a join so the main program waits for the thread to complete for the next iteration of the for loop..In this way we can make sure that the thread starts after the completion of the previous thread...&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: #333399; font-size: small;&quot;&gt;As the thread completes so the program can use the same ID of thread1 for the thread2 and so on....&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: maroon; font-size: small;&quot;&gt;Why so???&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: small;&quot;&gt;POSIX thread IDs are assigned and maintained by the threading implementation not by the kernel,to get the ID assigned by the kernel see&amp;nbsp;&lt;a href=&quot;http://techdip.webs.com/apps/blog/show/13955116-getting-the-thread-id&quot; rel=&quot;nofollow&quot; style=&quot;border-bottom-color: rgb(205, 221, 231); color: #005081; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;here...&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/3747300620693696808/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2013/08/pthreadself.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/3747300620693696808'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/3747300620693696808'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2013/08/pthreadself.html' title='pthread_self()'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-8096634753807558164</id><published>2013-08-13T06:55:00.001-07:00</published><updated>2013-09-29T04:15:57.398-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="multithreading in C"/><title type='text'>Thread Specific Data Example</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;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: green; font-size: small;&quot;&gt;Here is the Example to using Thread Specific Data..&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: green; font-size: small;&quot;&gt;In this example I am using File pointer as the TSD,setting the value of the key and then getting the correspoding file pointer for the particular thread...&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: green; font-size: small;&quot;&gt;Each Thread creates its log file and writes its name in the file....&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;&lt;/div&gt;

&lt;pre name=&quot;code&quot; class=&quot;php&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;stdlib.h&amp;gt;
#include&amp;lt;pthread.h&amp;gt;
static pthread_key_t key;
void write_to_file(void *ptr)
{
    FILE *fp= (FILE*)pthread_getspecific(key);
    fprintf(fp,&amp;quot;%s&amp;quot;,(char*)ptr);
        fclose(fp);
}
void* perform(void *ptr)
{
    FILE *fp;
    char *filename=malloc(strlen((char*)ptr)+8 );
    sprintf(filename,&amp;quot;%slog.log&amp;quot;,(char*)ptr);
    fp=fopen(filename,&amp;quot;w&amp;quot;);
    pthread_setspecific(key,fp);
    write_to_file(ptr);
}
int main()
{
    pthread_t thread[5];
    char *msg[]={&amp;quot;thread1&amp;quot;,&amp;quot;thread2&amp;quot;,&amp;quot;thread3&amp;quot;,&amp;quot;thread4&amp;quot;,&amp;quot;thread5&amp;quot;};
    int i;
    pthread_key_create(&amp;amp;key,NULL);
    for(i=0;i&amp;lt;5;i++)
    {
        pthread_create(&amp;amp;thread[i],NULL,perform,(void*)msg[i]);
        pthread_join(thread[i],NULL);
    }
    printf(&amp;quot;Now main ends&amp;quot;);
    return 0;
}

&lt;/pre&gt;

&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/8096634753807558164/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2013/08/thread-specific-data-example.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/8096634753807558164'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/8096634753807558164'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2013/08/thread-specific-data-example.html' title='Thread Specific Data Example'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-6057695076529454585</id><published>2013-08-13T06:54:00.001-07:00</published><updated>2013-08-13T06:54:11.677-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="multithreading in C"/><title type='text'>Thread Specific Data</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;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;Thread Specific Data&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;Thread Specific Data means data related to a particular thread,Think of a pool of different data for different threads that each thread can access with a public key...&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;All things revolves around a key to get the particular data..&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: maroon; font-size: medium;&quot;&gt;what to do--&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: maroon; font-size: medium;&quot;&gt;1.)Create a key&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: maroon; font-size: medium;&quot;&gt;2.)set the specific data for the thread using the key&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: maroon; font-size: medium;&quot;&gt;3.)get the specific data using the key only for a specific thread&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;Example:suppose there are 4 Threads running and every threads has to create a log file of the task that is performing,so each thread wants a file pointer specific to that thread so we can keep those file pointers as the TSD and can use a key to access the TSD for each thread..&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;For creating a key use the following function:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: medium;&quot;&gt;int pthread_key_create(pthread_key_t *key, void (*destructor) (void *));&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: medium;&quot;&gt;first argument-The key which you have defined...&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: medium;&quot;&gt;second argument-The function which you want to run after the completion of the thread,generally for cleanup,descrutor kind of thing.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: navy; font-size: medium;&quot;&gt;Note-If you pass a function pointer here, GNU/Linux automatically calls that function when each thread exits, passing the thread-specific value corresponding to that key. This is particularly handy because the cleanup function is called even if the thread is canceled at some arbitrary point in its execution. If the thread-specific value is null, the thread cleanup function is not called. If you don&#39;t need a cleanup function, you may pass NULL instead of a function pointer.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: maroon; font-size: medium;&quot;&gt;For setting the value use the following function:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: maroon; font-size: medium;&quot;&gt;pthread_setspecific(key, value);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: #993300; font-size: medium;&quot;&gt;For getting the value use the following function:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: #993300; font-size: medium;&quot;&gt;pthread_getspecific(key);&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/6057695076529454585/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2013/08/thread-specific-data.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/6057695076529454585'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/6057695076529454585'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2013/08/thread-specific-data.html' title='Thread Specific Data'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-1058416327011809839</id><published>2013-08-13T06:53:00.001-07:00</published><updated>2013-09-29T04:17:40.120-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="multithreading in C"/><title type='text'>Return Value From Thread</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;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;As we have seen in the examples the return type of the functions that runs as the threads is the void*,it means we can return a value from the thread,but the point is how to capture that returned value in the main function...&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;The answer is the join again,as we have seen in the&amp;nbsp;&lt;a href=&quot;http://techdip.webs.com/apps/blog/entries/show/13758533-thread-join-in-c&quot; rel=&quot;nofollow&quot; style=&quot;border-bottom-color: rgb(205, 221, 231); color: #005081; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;join&lt;/a&gt;&amp;nbsp;the function prototype is&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;int pthread_join(pthread_t,void **)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;Here the 2nd argument is the pointer to the value returned by the thread...&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;In the main funtion we can capture and use the value returned by the thread using the pthread_join.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;Let us capture the return value...&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;/div&gt;
&lt;pre name=&quot;code&quot; class=&quot;php&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;stdlib.h&amp;gt;
#include&amp;lt;pthread.h&amp;gt;
void* myfunc1(void *ptr)
{
    char *msg;
    int i=0;
    msg=(char*)ptr;
    while(1)
    {
        sleep(1);
        if(i&amp;gt;5)
            break;
        else
        {
            printf(&amp;quot;i in thread1=%d\n&amp;quot;,i);i++;
        }
    }
    printf(&amp;quot;Thread1 completed\n&amp;quot;);
    return &amp;quot;hello&amp;quot;;
}
void *myfunc2(void *ptr)
{
    char *msg;
    int i=0;
    msg=(char*)ptr;
    while(1)
    {
        sleep(1);
        if(i&amp;gt;10)
            break;
        else
        {
            printf(&amp;quot;i in thread2=%d\n&amp;quot;,i);i++;
        }
    }
    printf(&amp;quot;Thread2 completed\n&amp;quot;);
    return &amp;quot;Hi&amp;quot;;
}
int main()
{
    pthread_t thread1,thread2;
    int val1,val2;
    int status;
    char *msg1=&amp;quot;Thread1&amp;quot;;
    char *msg2=&amp;quot;Thread2&amp;quot;;
    void **ret_val1=malloc(sizeof(void*));
    void **ret_val2=malloc(sizeof(void*));
    printf(&amp;quot;In the main funciton\n&amp;quot;);
    pthread_create(&amp;amp;thread1,NULL,myfunc1,(void*)msg1);
    pthread_create(&amp;amp;thread2,NULL,myfunc2,(void*)msg2);
    pthread_join(thread1,ret_val1);
    pthread_join(thread2,ret_val2);
    printf(&amp;quot;return value from thread1  is:%s\n&amp;quot;,*ret_val1);
    printf(&amp;quot;return value from thread2 is:%s\n&amp;quot;,*ret_val2);
    printf(&amp;quot;Now main ends&amp;quot;);
    return 0;
}
&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/1058416327011809839/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2013/08/return-value-from-thread.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/1058416327011809839'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/1058416327011809839'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2013/08/return-value-from-thread.html' title='Return Value From Thread'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-542633617146851944</id><published>2013-08-13T06:52:00.001-07:00</published><updated>2013-09-29T04:19:04.686-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="multithreading in C"/><title type='text'>Thread Join 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;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;Why thread Join??&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;As we have seen in the&amp;nbsp;&lt;a href=&quot;http://techdip.webs.com/apps/blog/entries/show/13757440-first-multithreaded-program-in-c&quot; rel=&quot;nofollow&quot; style=&quot;border-bottom-color: rgb(205, 221, 231); color: #005081; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;first multithreaded program&lt;/a&gt;&amp;nbsp;that we have the while(1) loop in the main function ,that is to ensure that the application/program keeps runnning because if main ends the program ends...&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;Now if we dun want to waste the time in the main program and only want to run the threads we can use the thread join to achieve this task.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;what is a join??&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;Join means we are telling the thread to join with the other thread that is we are telling that wait for the other thread to finish..&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;So two threads are included in the join&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;first thread -to whom we are saying to join&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;second thread-the thread to join with&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;suppose there is Thread1 and Thread2,and we require the Thread2 must complete before Thread1 so we have to tell the Thread1 to join with the Thread2..&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;So in our Example,We have to say main to join with the Thread1 and Thread2 ,that is telling main to wait for both the Threads to complete,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;So, By using join we need not to worry about the main,the main will end only after the completion of the both threads..&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;Funtion prototype:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: teal; font-size: medium;&quot;&gt;int pthread_join(pthread_t tid, void **status);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: maroon; font-size: medium;&quot;&gt;The first argument is the thread ID.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: maroon; font-size: medium;&quot;&gt;The second argument is a pointer to the data your thread function returned,keep it as NULL for now.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;Example:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;/div&gt;
&lt;pre name=&quot;code&quot; class=&quot;php&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;stdlib.h&amp;gt;
#include&amp;lt;pthread.h&amp;gt;
void* myfunc1(void *ptr)
{
    char *msg;
    int i=0;
    msg= (char*)ptr;
    while(1)
    {
        printf(&amp;quot;In the %s\n&amp;quot;,msg);
        sleep(1);
    if(i++&amp;gt; 7)
    break;
    }
printf(&amp;quot;Thread1 completed\n&amp;quot;);
}
void *myfunc2(void *ptr)
{
    char *msg;
    int i=0;
    msg= (char*)ptr;
    while(1)
    {
        printf(&amp;quot;In the %s\n&amp;quot;,msg);
        sleep(1);
    if(i++&amp;gt;10 )
    break;
    }
printf(&amp;quot;Thread2 completed\n&amp;quot;);
}
int main()
{
    pthread_t thread1,thread2;
    int val1,val2;
    int status;
    char *msg1=&amp;quot;Thread1&amp;quot;;
    char *msg2=&amp;quot;Thread2&amp;quot;;
    void **ret_val;
    printf(&amp;quot;In the main funciton\n&amp;quot;);
    val1=pthread_create(&amp;amp;thread1,NULL,myfunc1,(void*)msg1);
    val2=pthread_create(&amp;amp;thread2,NULL,myfunc2,(void*)msg2);
    printf(&amp;quot;the value returned by thread1=%d\n&amp;quot;,val1);
    printf(&amp;quot;the value returned by thread2=%d\n&amp;quot;,val2);
    pthread_join(thread1,NULL);//telling main to join with thread1
    pthread_join(thread2,NULL);//telling main to join with thread2
        printf(&amp;quot;Now main ends:\n&amp;quot;);
    return 0;
}
&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/542633617146851944/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2013/08/thread-join-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/542633617146851944'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/542633617146851944'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2013/08/thread-join-in-c.html' title='Thread Join In C'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-6884750433514797760</id><published>2013-08-13T06:50:00.001-07:00</published><updated>2013-09-29T04:20:29.245-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="multithreading in C"/><title type='text'>First Multi Threaded Program 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;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
Today i have written my first multithreaded program in C on linux,&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
It is very easy to write multithreded program using the pthread library..&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
Let us take a look which function we need to create a multithreded program in c...&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
The function to create the thread:&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: maroon;&quot;&gt;int pthread_create(pthread_t *tid,const pthread_attr_t *attr,void *(*func)(void *), void *arg)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: green;&quot;&gt;Note-Each thread will have its own unique thread ID.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: #333399;&quot;&gt;The first argument is the variable where its thread ID will be stored.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: #333399;&quot;&gt;The second argument contains attributes describing the thread. Keep this as NULL now,will explain later.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: #333399;&quot;&gt;The third argument is a pointer to the function you want to run as a thread.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;span style=&quot;color: #333399;&quot;&gt;The final argument is a pointer to data you want to pass to the function.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
Having this information in mind you can write a simple multithreaded program in C...&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
Let us take a look at a example:&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #222222; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21.59375px;&quot;&gt;
&lt;/div&gt;
&lt;pre name=&quot;code&quot; class=&quot;php&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;stdlib.h&amp;gt;
#include&amp;lt;pthread.h&amp;gt;
void* myfunc1(void *ptr)
{
char *msg;
msg= (char*)ptr;
printf(&amp;quot;%s started\n&amp;quot;,msg);
while(1)
{
printf(&amp;quot;In the %s\n&amp;quot;,msg);
sleep(1);
}
}
void *myfunc2(void *ptr)
{
char *msg;
msg= (char*)ptr;
printf(&amp;quot;%s started\n&amp;quot;,msg);
while(1)
{
printf(&amp;quot;In the %s\n&amp;quot;,msg);
sleep(1);
}
}
int main()
{
pthread_t thread1,thread2;
int val1,val2;
char *msg1=&amp;quot;Thread1&amp;quot;;
char *msg2=&amp;quot;Thread2&amp;quot;;
printf(&amp;quot;In the main funciton\n&amp;quot;);
printf(&amp;quot;My first thread program\n&amp;quot;);
val1= pthread_create(&amp;amp;thread1,NULL,myfunc1,(void*)msg1);
val2= pthread_create(&amp;amp;thread2,NULL,myfunc2,(void*)msg2);
printf(&amp;quot;The value returned by thread1=%d\n&amp;quot;,val1);
printf(&amp;quot;The value returned by thread2=%d\n&amp;quot;,val2);
while(1)
{
printf(&amp;quot;in the main function\n&amp;quot;);
sleep(1);
}
return 0;
}
&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/6884750433514797760/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2013/08/first-multi-threaded-program-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/6884750433514797760'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/6884750433514797760'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2013/08/first-multi-threaded-program-in-c.html' title='First Multi Threaded Program in C'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-6483874814966320907</id><published>2011-09-16T05:54:00.000-07:00</published><updated>2013-09-30T06:54:38.751-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="deleting a file"/><title type='text'>Deleting a File in C</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Here is the program to delete a file in C......&lt;br /&gt;
&lt;pre name=&quot;code&quot; class=&quot;php&quot;&gt;
#include &amp;lt;stdio.h&amp;gt;
#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;errno.h&amp;gt;
int main(void)
{
   char file[80];
   int i;
   clrscr();
   printf(&amp;quot;File to delete: &amp;quot;);
   gets(file);
   i=remove(file);
   if(i==0)
   {
   printf(&amp;quot;file removed&amp;quot;);
   }
   else
   {
   if(errno==ENOENT)
   printf(&amp;quot;\nNo such file exists&amp;quot;);
   if(errno==EACCES)
   printf(&amp;quot;\nPermission denied&amp;quot;);
   }
   getch();
   return 0;
}
&lt;/pre&gt;
&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Feel Free to Comment if any point is not clear........&lt;/span&gt;&lt;/b&gt;.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/6483874814966320907/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2011/09/deleting-file-in-c.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/6483874814966320907'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/6483874814966320907'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2011/09/deleting-file-in-c.html' title='Deleting a File in C'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-7044863911849033490</id><published>2011-09-13T20:44:00.000-07:00</published><updated>2013-09-30T06:58:07.283-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="rename in c"/><title type='text'>Renaming a file in c</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;In this post we will find how to rename and move a file in the same drive using c language....&lt;br /&gt;
This can be done in c using the rename() function..The prototype of rename is:&lt;br /&gt;
&lt;div style=&quot;color: #660000;&quot;&gt;int rename(const *char oldname,const *char newname);&lt;/div&gt;&lt;div style=&quot;color: #660000;&quot;&gt;On sucess--it returns 0,&lt;/div&gt;&lt;div style=&quot;color: #660000;&quot;&gt;On error---it returns -1;&lt;/div&gt;Let us take an example:&lt;br /&gt;
&lt;br /&gt;
&lt;pre name=&quot;code&quot; class=&quot;php&quot;&gt;
#include &amp;lt;stdio.h&amp;gt;
#include&amp;lt;conio.h&amp;gt;
#include&amp;lt;errno.h&amp;gt;
int main(void)
{
   char oldname[80], newname[80];
   int i;
   clrscr();
   printf(&amp;quot;Enter File to rename: &amp;quot;);
   gets(oldname);
   printf(&amp;quot;\nEnter New name: &amp;quot;);
   gets(newname);
   i=rename(oldname, newname);
     if(i==0)
     {
     printf(&amp;quot;rename done&amp;quot;);
     }
     else
     {
     if(errno==ENOENT){printf(&amp;quot;no such file/directory exists&amp;quot;);}
     if(errno==EACCES){printf(&amp;quot;access denied&amp;quot;);}
     if(errno==ENOTSAM){printf(&amp;quot;Drive is not same&amp;quot;);}
     }
getch();
   return 0;
}
&lt;/pre&gt;
Let us find the output for different inputs &lt;br /&gt;
&lt;div style=&quot;color: #783f04;&quot;&gt;output:&lt;/div&gt;&lt;div style=&quot;color: #783f04;&quot;&gt;Enter&amp;nbsp; File to rename:c:\test.txt&lt;/div&gt;&lt;div style=&quot;color: #783f04;&quot;&gt;Enter New name:c:\go.txt&lt;/div&gt;&lt;div style=&quot;color: #783f04;&quot;&gt;rename done&lt;/div&gt;&lt;span style=&quot;color: #783f04;&quot;&gt;Explanation:it will sucessfully rename the file test to go in the c drive &lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;color: #660000;&quot;&gt;&lt;br /&gt;
output:&lt;/div&gt;&lt;div style=&quot;color: #660000;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;color: #660000;&quot;&gt;Enter&amp;nbsp; File to rename:d:\test.txt&lt;/div&gt;&lt;div style=&quot;color: #660000;&quot;&gt;Enter New name:c:\go.txt&lt;/div&gt;&lt;div style=&quot;color: #660000;&quot;&gt;Drive is not same&lt;/div&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Explanation:Using rename function u can only work within a drive &lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;color: purple;&quot;&gt;&lt;br /&gt;
output:&lt;/div&gt;&lt;div style=&quot;color: purple;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;color: purple;&quot;&gt;Enter&amp;nbsp; File to rename:d:\test.txt&lt;/div&gt;&lt;div style=&quot;color: purple;&quot;&gt;Enter New name:d:\moveinthis\go.txt&lt;/div&gt;&lt;div style=&quot;color: purple;&quot;&gt;rename done&lt;/div&gt;&lt;div style=&quot;color: purple;&quot;&gt;Explanation:You can move the file from one directory to another directory using rename but the condition is that the directories must be in the same drive......&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;color: #4c1130;&quot;&gt;output:&lt;/div&gt;&lt;div style=&quot;color: #4c1130;&quot;&gt;Enter&amp;nbsp; File to rename:d:\ex.txt&lt;/div&gt;&lt;div style=&quot;color: #4c1130;&quot;&gt;Enter New name:d:\moveinthis\go.txt&lt;/div&gt;&lt;div style=&quot;color: #4c1130;&quot;&gt;no such file/directory exists&lt;/div&gt;&lt;div style=&quot;color: #4c1130;&quot;&gt;Explanation:This message will come if there is no file named as ex.txt present in the d drive......&lt;/div&gt;&lt;div style=&quot;color: #274e13;&quot;&gt;&lt;br /&gt;
output:&lt;/div&gt;&lt;div style=&quot;color: #274e13;&quot;&gt;Enter&amp;nbsp; File to rename:c:\temp&lt;/div&gt;&lt;div style=&quot;color: #274e13;&quot;&gt;Enter New name:c:\check&lt;/div&gt;&lt;div style=&quot;color: #274e13;&quot;&gt;rename done&lt;/div&gt;&lt;span style=&quot;color: #274e13;&quot;&gt;Explanation:We can rename also a directory&amp;nbsp; using the rename function,but still the condition is we must work in the same drive.....&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/7044863911849033490/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2011/09/renaming-file-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/7044863911849033490'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/7044863911849033490'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2011/09/renaming-file-in-c.html' title='Renaming a file in c'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-3954552928319938708</id><published>2011-09-08T06:29:00.000-07:00</published><updated>2013-09-30T07:00:13.982-07:00</updated><title type='text'>The difference between pointer to array and pointer to its first element</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;In the previous &lt;a href=&quot;http://clanguagestuff.blogspot.com/2011/09/address-of-array-and-address-of-first.html&quot;&gt;Post&lt;/a&gt;,We have seen that the address of array and the address of its first element is same,so,the question was what is the difference between Pointer to array and the Pointer to the first element of array while both contains the same address as proved in this &lt;a href=&quot;http://clanguagestuff.blogspot.com/2011/09/address-of-array-and-address-of-first.html&quot;&gt;Post&lt;/a&gt;....&lt;br /&gt;
That is if write something like this--&lt;br /&gt;
int (*ptr)[5];&lt;br /&gt;
&lt;span style=&quot;color: #274e13;&quot;&gt;ptr=&amp;amp;a; &lt;/span&gt;&lt;br /&gt;
and a pointer to first element of the array that is....&lt;br /&gt;
int *ptr1;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;color: #274e13;&quot;&gt;ptr1=a;&lt;/div&gt;Then,&lt;span style=&quot;color: #351c75;&quot;&gt;What&#39;s the Difference between ptr and ptr1??????&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #351c75;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;To Get the difference between we have just to recall the concept of pointer arithmetic that is &lt;span style=&quot;color: #660000;&quot;&gt;what happens if we add some number to a pointer&lt;/span&gt;??...&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #351c75;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;As we know whenever we add any number to the pointer the pointer appends to the memory location which is equal to the &lt;span style=&quot;color: #660000;&quot;&gt;sizeof datatype*number&lt;/span&gt;....&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #351c75;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;For example:if a pointer is pointing to an int and its value is 65588 then if we add 1 to the pointer then it goes to 65590 that is (sizeof int *num) that is 2*1=2,so 2 gets added to the pointer and now it points to 65590 memory location...&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #351c75;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;So,Having the concept of pointer arithmetic in mind when we declare a pointer to an array and increments it the value of the pointer get incremented by sizeof array*datatype size*number...&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #351c75;&quot;&gt;For example:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #351c75;&quot;&gt;if we write int a[5]={1,2,3,4,5};&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #351c75;&quot;&gt;the sizrof array is 5,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #351c75;&quot;&gt;datatype size is 2 for int(16-bit assumed),&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #351c75;&quot;&gt;and number is 1,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #351c75;&quot;&gt;int(*ptr)[5];&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #351c75;&quot;&gt;ptr=&amp;amp;a;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #351c75;&quot;&gt;ptr=ptr+1;or ptr++;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #351c75;&quot;&gt;if in address of array is 65516 that is ptr is 65516 in the beginning then after ptr=ptr+1 or ptr++;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #351c75;&quot;&gt;The value of ptr is 65516+(5*2*1)=65516+10=65526&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #351c75;&quot;&gt;This is what happens if ptr is the pointer to array and if the ptr is the pointer to the first elements of the array then as the first element is an int so when we increments the ptr the value get incremented by sizeof int that is it points to the next element...&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #351c75;&quot;&gt;let us write a program&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;pre name=&quot;code&quot; class=&quot;php&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;conio.h&amp;gt;
void main()
{
int arr[5]={1,2,3,4,5};
int(*ptr1)[5];
int *ptr2;
ptr1=&amp;amp;a;//pointer to an array
ptr2=&amp;amp;a[0];//pointer to first element of array
printf(&amp;quot;The address of array is:%u&amp;quot;,ptr1);
printf(&amp;quot;\nThe address of first element of array is:%u&amp;quot;,ptr2);
ptr1++;
printf(&amp;quot;\nNow the value of ptr1 is:%u&amp;quot;,ptr1);
ptr2++;
printf(&amp;quot;\nNow the value of ptr2 is:%u&amp;quot;&amp;quot;,ptr2);
}
&lt;/pre&gt;
output:&lt;div style=&quot;color: #274e13;&quot;&gt;The address of array is:65516&lt;/div&gt;&lt;div style=&quot;color: #274e13;&quot;&gt;The address of first element of array is:65516&lt;/div&gt;&lt;div style=&quot;color: #274e13;&quot;&gt;Now the value of ptr1 is:65526&lt;/div&gt;&lt;span style=&quot;color: #351c75;&quot;&gt;&lt;span style=&quot;color: #274e13;&quot;&gt;Now the value of ptr2 is:65518&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #351c75;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;i&gt;&lt;b&gt;&lt;span style=&quot;color: #351c75;&quot;&gt;I explained to the best of my knowledge,Correct me if there is anything wrong by commenting ,your comments,query and suggestions are invited to raise the level of this blog......&lt;/span&gt;&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #351c75;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;i&gt;&lt;b&gt;Have a nice time.....&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/3954552928319938708/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2011/09/difference-between-pointer-to-array-and.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/3954552928319938708'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/3954552928319938708'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2011/09/difference-between-pointer-to-array-and.html' title='The difference between pointer to array and pointer to its first element'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-984276606280744978</id><published>2011-09-07T20:58:00.000-07:00</published><updated>2013-09-30T07:05:55.027-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="address of array"/><title type='text'>Address of array and Address of first element of array</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Today we will explore the address of array and the Address of First Element of the same array....&lt;br /&gt;
let us first create an array of int containing the 5 elements.&lt;br /&gt;
int a[5]={1,2,3,4,5};&lt;br /&gt;
Here a is the array of the 5 int data type elements...&lt;br /&gt;
As we know we can find the address of the array by applying the &amp;amp; operator with the array name that is &quot;a&quot;,so the address of the aray is &quot;&amp;amp;a&quot;...we can print this address using the %u format specifier in the printf..&lt;br /&gt;
&lt;span style=&quot;color: #990000;&quot;&gt;printf(&quot;address of array is:%u&quot;,&amp;amp;a);//address of the array&lt;/span&gt;&lt;br /&gt;
let us write a program..&lt;br /&gt;
&lt;div style=&quot;color: #660000;&quot;&gt;
&lt;/div&gt;
&lt;pre name=&quot;code&quot; class=&quot;php&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;conio.h&amp;gt;
void main()
{
int a[5]={1,2,3,4,5};
clrscr();
printf(&amp;quot;The address of array is:%u&amp;quot;,&amp;amp;a);
getch();
}
&lt;/pre&gt;

The output is the address of the array...let us say it prints&lt;br /&gt;
&lt;div style=&quot;color: #660000;&quot;&gt;The address of array is:65516&lt;/div&gt;Now let us find the address the first element of the array,as ww know we can get the first element by a[0],and its address by &amp;amp;a[0]..&lt;br /&gt;
so the statement &lt;span style=&quot;color: #274e13;&quot;&gt;printf(&quot;The address of first element is:%u&quot;,&amp;amp;a[0]);&lt;/span&gt; gives the address of the first element of the array...it prints.&lt;br /&gt;
&lt;div style=&quot;color: #274e13;&quot;&gt;The address of first element is:65516&lt;/div&gt;Further,we also know that the a(the name of the array) is nothing but the pointer to the first element of the array so printing the a will also give the same value....&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;
&lt;/span&gt;
&lt;pre name=&quot;code&quot; class=&quot;php&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;conio.h&amp;gt;
void main()
{
int a[5]={1,2,3,4,5};
printf(&amp;quot;The address of array is:%u&amp;quot;,&amp;amp;a);
printf(&amp;quot;The address of first element is:%u&amp;quot;,&amp;amp;a[0]);
printf(&amp;quot;The value of a is:%u&amp;quot;,a);
}
&lt;/pre&gt;

output:&lt;div style=&quot;color: #20124d;&quot;&gt;The address of array is:65516&lt;/div&gt;&lt;div style=&quot;color: #20124d;&quot;&gt;The address of first element is:65516&lt;/div&gt;&lt;div style=&quot;color: #20124d;&quot;&gt;The value of a is:65516&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;color: #4c1130;&quot;&gt;As we can see the result the,The conclusion is...&lt;/div&gt;&lt;div style=&quot;color: #4c1130;&quot;&gt;&quot;The Address of Array and the Address of its first element is Same........&quot;.&lt;/div&gt;&lt;div style=&quot;color: #4c1130;&quot;&gt;As for the explanation we can say that array starts from the first element so the address of its first elements is same as the address of itself........&lt;/div&gt;&lt;div style=&quot;color: #4c1130;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;color: #660000;&quot;&gt;So,the Question arises--&lt;/div&gt;&lt;div style=&quot;color: #783f04;&quot;&gt;&quot;What&#39;s the Difference Between Pointer to array and the pointer to the first element of array if both contains the same address????&quot;&lt;/div&gt;that is:&lt;br /&gt;
if we declare int a[5];&lt;br /&gt;
and a pointer to array that is...&lt;br /&gt;
int (*ptr)[5];&lt;br /&gt;
&lt;span style=&quot;color: #274e13;&quot;&gt;ptr=&amp;amp;a; &lt;/span&gt;&lt;br /&gt;
and a pointer to first element of the array that is....&lt;br /&gt;
int *ptr1;&lt;br /&gt;
&lt;div style=&quot;color: #274e13;&quot;&gt;ptr1=a;&lt;/div&gt;so,&lt;span style=&quot;color: #351c75;&quot;&gt;What&#39;s the Difference between ptr and ptr1??????&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;http://clanguagestuff.blogspot.com/2011/09/difference-between-pointer-to-array-and.html&quot;&gt;Get Answer here.&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/984276606280744978/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2011/09/address-of-array-and-address-of-first.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/984276606280744978'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/984276606280744978'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2011/09/address-of-array-and-address-of-first.html' title='Address of array and Address of first element of array'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-4709286573056158419</id><published>2011-09-04T01:31:00.000-07:00</published><updated>2013-09-30T07:07:58.002-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="MAC Address"/><title type='text'>MAC address using 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;color: #990000;&quot;&gt;Mac Address&lt;/span&gt;--&amp;gt;from Wikipedia&lt;br /&gt;
A &lt;b&gt;Media Access Control address&lt;/b&gt; (&lt;b&gt;MAC address&lt;/b&gt;) is a &lt;a href=&quot;http://en.wikipedia.org/wiki/Unique_identifier&quot; title=&quot;Unique identifier&quot;&gt;unique identifier&lt;/a&gt; assigned to &lt;a class=&quot;mw-redirect&quot; href=&quot;http://en.wikipedia.org/wiki/Network_adapter&quot; title=&quot;Network adapter&quot;&gt;network interfaces&lt;/a&gt; for communications on the physical network segment. MAC addresses are used for numerous network technologies and most &lt;a href=&quot;http://en.wikipedia.org/wiki/IEEE_802&quot; title=&quot;IEEE 802&quot;&gt;IEEE 802&lt;/a&gt; network technologies including &lt;a href=&quot;http://en.wikipedia.org/wiki/Ethernet&quot; title=&quot;Ethernet&quot;&gt;Ethernet&lt;/a&gt;. Logically, MAC addresses are used in the &lt;a href=&quot;http://en.wikipedia.org/wiki/Media_Access_Control&quot; title=&quot;Media Access Control&quot;&gt;Media Access Control&lt;/a&gt; protocol sub-layer of the &lt;a class=&quot;mw-redirect&quot; href=&quot;http://en.wikipedia.org/wiki/OSI_reference_model&quot; title=&quot;OSI reference model&quot;&gt;OSI reference model&lt;/a&gt;.&lt;br /&gt;
MAC addresses are most often assigned by the manufacturer of a network interface card (NIC) and are stored in its hardware, the card&#39;s read-only memory, or some other firmware mechanism. If assigned by the manufacturer, a MAC address usually encodes the manufacturer&#39;s registered identification number and may be referred to as the &lt;b&gt;burned-in address&lt;/b&gt;. It may also be known as an &lt;b&gt;Ethernet hardware address&lt;/b&gt; (&lt;b&gt;EHA&lt;/b&gt;), &lt;b&gt;hardware address&lt;/b&gt; or &lt;b&gt;physical address&lt;/b&gt;. A &lt;a class=&quot;mw-redirect&quot; href=&quot;http://en.wikipedia.org/wiki/Network_node&quot; title=&quot;Network node&quot;&gt;network node&lt;/a&gt; may have multiple NICs and will then have one unique MAC address per NIC.&lt;br /&gt;
&lt;br /&gt;
Now the question is &lt;span style=&quot;color: #990000;&quot;&gt;How can we find the Mac Address using C language&lt;/span&gt;....&lt;br /&gt;
There may be many methods to do that but&amp;nbsp; i am using the &lt;a href=&quot;http://clanguagestuff.blogspot.com/2011/09/dos-command-in-c.html&quot;&gt;sytem() function which is used to run the DOS command using C&lt;/a&gt; and the FILE handling to get the MAC address or pghysical address of the pc... &lt;br /&gt;
&lt;br /&gt;
As we know we can get the physical or MAC address using the DOS command &quot;ipconfig/all&quot; ..u can get the mac address using this command from the dos prompt as shown in the figure below..&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpFVJTMQlM_q9zZxMGBHGLuvIZxsexkvX_F7f8s8QPpp05s3iiyIdLdjofrvFwek4H_4BO_PlZINS_4l_Q42DEbooKGHw3ongzhn49RTZVhb86c32eWIso3nLpyn2oWT4575wpqTEVcw/s1600/macid.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpFVJTMQlM_q9zZxMGBHGLuvIZxsexkvX_F7f8s8QPpp05s3iiyIdLdjofrvFwek4H_4BO_PlZINS_4l_Q42DEbooKGHw3ongzhn49RTZVhb86c32eWIso3nLpyn2oWT4575wpqTEVcw/s320/macid.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;As you can se in the figure the Physical Address is 00-1C-C0-1A-6E-C0&lt;br /&gt;
Now mout ask is only to show this address as theoutput of our C program....&lt;br /&gt;
What firstly Strike in the mind,the idea is :&lt;br /&gt;
&lt;div style=&quot;color: #274e13;&quot;&gt;&quot;To get the ipconfig/all command executed using sytem funtion and redirecting the output to the string or taking the output to the string and then getting the substring form that main string starting from the Physical Address that will be easy and simple.....&quot;&lt;/div&gt;I also look for that and tried but was not able to do the same....&lt;span style=&quot;color: blue;&quot;&gt;any help in this regard will be appriciated&lt;/span&gt;&lt;br /&gt;
now what i have done to get the only MAC address or the physical addres,i just rediredced the output of the system funtion() with the inconfig/all command to a file ,read that file back line by line which is very necessary then search for the substring starting with Physical Address or containg the Physical Address,get that printed and get out of the loop using break....&lt;br /&gt;
You can see the code below...&lt;br /&gt;
&lt;div style=&quot;color: #cc0000;&quot;&gt;&lt;/div&gt;

&lt;pre name=&quot;code&quot; class=&quot;php&quot;&gt;
#include &amp;lt;stdio.h&amp;gt;
#include&amp;lt;conio.h&amp;gt;
int main ()
{
  FILE *fp;
  clrscr();
  system (&amp;quot;ipconfig/all&amp;gt;f:\macid.txt&amp;quot;);
   fp=fopen(&amp;quot;f:\macid.txt&amp;quot;,&amp;quot;r&amp;quot;);
   if(fp!=NULL)
   {
   char line[128];
   while(fgets(line,sizeof line,fp)!=NULL)
   {
   char *nwln=strchr(line,&amp;#39;\n&amp;#39;);
   char *ptr;
   if(nwln!=NULL)
   *nwln=&amp;#39;\0&amp;#39;;
   ptr=strstr(line,&amp;quot;Physical Address&amp;quot;);
   if(ptr!=NULL)
   {
   printf(&amp;quot;%s\n&amp;quot;,ptr);
   break;
   }
  }
   }
  getch();
  return 0;
} 
&lt;/pre&gt;

NOTE:Run the program using DOS Prompt instead of turboc ide....&lt;br /&gt;
Your comments and query are invited .....&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/4709286573056158419/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2011/09/mac-address-using-c.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/4709286573056158419'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/4709286573056158419'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2011/09/mac-address-using-c.html' title='MAC address using c'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpFVJTMQlM_q9zZxMGBHGLuvIZxsexkvX_F7f8s8QPpp05s3iiyIdLdjofrvFwek4H_4BO_PlZINS_4l_Q42DEbooKGHw3ongzhn49RTZVhb86c32eWIso3nLpyn2oWT4575wpqTEVcw/s72-c/macid.PNG" height="72" width="72"/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-2068109998075527037</id><published>2011-09-04T00:47:00.000-07:00</published><updated>2013-09-30T07:09:12.977-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="DOS command"/><title type='text'>Dos Command in C</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;This example will show how to use the DOS command in C and rediret its output to a file..&lt;br /&gt;
&lt;pre name=&quot;code&quot; class=&quot;php&quot;&gt;
#include &amp;lt;stdio.h&amp;gt;
#include&amp;lt;conio.h&amp;gt;
void main ()
{
  FILE *fp;
  clrscr();
  printf (&amp;quot;Checking if processor is available...&amp;quot;);
  if (system(NULL))
  {
  puts (&amp;quot;Ok&amp;quot;);
  }
  else
  {
  printf(&amp;quot;Processor is not available&amp;quot;);
  getch();
  exit (1);
  }
  system (&amp;quot;dir&amp;gt;c:\dirlist.txt&amp;quot;);
  printf(&amp;quot;Done!!File created&amp;quot;);
getch();
}
&lt;/pre&gt;
output:will create the file with name dirlist in the &quot;c:\&quot; drive..........&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/2068109998075527037/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2011/09/dos-command-in-c.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/2068109998075527037'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/2068109998075527037'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2011/09/dos-command-in-c.html' title='Dos Command in C'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-2269594811127575433</id><published>2011-08-30T23:36:00.000-07:00</published><updated>2013-09-30T07:10:32.528-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="processor available or not"/><title type='text'>Check whether the processor is available or not</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;This program will check whether the processor is available or not.. &lt;br /&gt;
&lt;/div&gt;
&lt;pre name=&quot;code&quot; class=&quot;php&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;conio.h&amp;gt;
void main()
{
printf (&amp;quot;Checking if processor is available...&amp;quot;);
if (system(NULL))
printf(&amp;quot;Processor is available&amp;quot;);
else
printf(&amp;quot;Processor is not available&amp;quot;);
getch();
}
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/2269594811127575433/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2011/08/check-whether-processor-is-available-or.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/2269594811127575433'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/2269594811127575433'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2011/08/check-whether-processor-is-available-or.html' title='Check whether the processor is available or not'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8228086725291688914.post-7479676235413849937</id><published>2011-08-30T23:00:00.000-07:00</published><updated>2013-09-30T07:11:59.422-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="DOS command"/><title type='text'>Running a DOS command using C</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;To Run a DOS command using C we use the system() function present in process.h and stdlib.h&lt;br /&gt;
The prototype of the function is:&lt;br /&gt;
&lt;div style=&quot;color: red;&quot;&gt;int system(const char *command);&lt;/div&gt;&lt;div style=&quot;color: red;&quot;&gt;On Success returns 0&lt;/div&gt;&lt;span style=&quot;color: red;&quot;&gt;On Error returns -1&lt;/span&gt;&lt;br /&gt;
Example:&lt;br /&gt;

&lt;pre name=&quot;code&quot; class=&quot;php&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;conio.h&amp;gt;
void main()
{
clrscr();
int i;
printf(&amp;quot;This program will execute the DOS command&amp;quot;);
i=system(&amp;quot;dir&amp;quot;);
if(i==0)
printf(&amp;quot;completed successfully&amp;quot;);
else
printf(&amp;quot;error in executing the command&amp;quot;);
getch();
}
&lt;/pre&gt;
If you are using turboc3 and run this using Ctrl+F9 you will not see the error , to run this go to cmd prompt and then execute the exe file created after compiling the program form the DOS prompt.you will easily get the output..if you are having any problem...just mail me at milankmr2011@gmail.com&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://clanguagestuff.blogspot.com/feeds/7479676235413849937/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clanguagestuff.blogspot.com/2011/08/running-dos-command-using-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/7479676235413849937'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8228086725291688914/posts/default/7479676235413849937'/><link rel='alternate' type='text/html' href='http://clanguagestuff.blogspot.com/2011/08/running-dos-command-using-c.html' title='Running a DOS command using C'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02779273119448670438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>