<?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-24710794</id><updated>2024-09-21T19:50:53.241-07:00</updated><category term="Interview questions"/><category term="Technical Interview questions"/><category term="C Questions"/><category term="C Programming Language"/><category term="C++ Questions"/><category term="C"/><category term="C++ Programming Language"/><category term="C++"/><category term="Linux"/><category term="RPM"/><category term="bash"/><category term="unix shell scripting"/><category term="C books"/><category term="C++ Books"/><category term="C++ STL"/><category term="C++ Standard Template Library"/><category term="C++ library"/><category term="C++ template"/><category term="Data Structures in C"/><category term="Debugging multi-threaded applications"/><category term="Dennis Ritchie"/><category term="Java Script Linux"/><category term="Linux Device Driver books"/><category term="Linux Kernel books"/><category term="Linux on browser"/><category term="Online C compiler"/><category term="RIP Dennis Ritchie"/><category term="SIGBUS"/><category term="SIGBUS Vs SIGSEGV"/><category term="SIGSEGV"/><category term="Signal handling in Linux"/><category term="Signals in Linux"/><category term="Test your C Programming skills"/><category term="UNIX"/><category term="Windows Debugging"/><category term="free C compiler"/><category term="free C++ compiler"/><category term="grep"/><category term="online c++ compiler"/><category term="static variable"/><category term="yum"/><title type='text'>C Questions</title><subtitle type='html'>This is my own compilation of some of the interesting C programs. Welcome to C Questions blog.&#xa;&#xa;&#xa;Welcome you to publish your own such interesting C puzzles. &#xa;And, well recently I have added some C++ stuff as well, hope you will enjoy them. Thanks</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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>45</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-24710794.post-7131876167722954855</id><published>2017-12-18T20:55:00.000-08:00</published><updated>2017-12-18T20:55:35.199-08:00</updated><title type='text'>All about volatile variable 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 volatile keyword in C?&lt;br /&gt;
volatile is a data type qualifier in C.&lt;br /&gt;
&lt;br /&gt;
Role of volatile variable in signal handler?&lt;br /&gt;
When a variable is declared as volatile, the C compiler does not optimize the code where this variable involves.&lt;br /&gt;
&lt;br /&gt;
It also means that someone might externally change the value of this variable over time, hence do not cache the value of this variable.&lt;br /&gt;
&lt;br /&gt;
In case of interrupt handlers or signal handlers where the counter is dependent is on the incoming data, this counter variables value changes due to external factors like arrival of new data on the port. Hence even though the program did not modified the data, the value of this counter variable changed. Such variable should be declared as volatile variable, so that the C compiler does not optimize the usage of this variable and hence does not pick up the value from the cache.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/7131876167722954855/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/7131876167722954855' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/7131876167722954855'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/7131876167722954855'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2017/12/all-about-volatile-variable-in-c.html' title='All about volatile variable in C'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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-24710794.post-2066830196424316606</id><published>2017-12-18T18:15:00.001-08:00</published><updated>2017-12-18T18:15:34.305-08:00</updated><title type='text'>Logical &amp; and addition</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;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;What is going to be the output of this code?&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp; &lt;/span&gt;1 &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;#include &lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;&lt;stdio .h=&quot;&quot;&gt;&lt;/stdio&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp; &lt;/span&gt;2 &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; main(&lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp; &lt;/span&gt;3 &lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp; &lt;/span&gt;4 &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; a=&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;, b=&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp; &lt;/span&gt;5 &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; c;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp; &lt;/span&gt;6 &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;c = a&amp;amp;b + &lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;65&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;7&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;printf(&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;&quot;c=&lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;%d\n&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;, c);&lt;/span&gt;&lt;/div&gt;
&lt;style type=&quot;text/css&quot;&gt;
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d53bd3; background-color: #ffffff}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #cd7923; background-color: #ffffff}
span.s1 {font-variant-ligatures: no-common-ligatures; color: #cd7923}
span.s2 {font-variant-ligatures: no-common-ligatures}
span.s3 {font-variant-ligatures: no-common-ligatures; color: #c33720}
span.s4 {font-variant-ligatures: no-common-ligatures; color: #34bc26}
span.s5 {font-variant-ligatures: no-common-ligatures; color: #000000}
span.s6 {font-variant-ligatures: no-common-ligatures; color: #d53bd3}
&lt;/style&gt;










&lt;br /&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp; 8&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s5&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s5&quot;&gt;This code looks simple enough. Guess??&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s5&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/2066830196424316606/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/2066830196424316606' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/2066830196424316606'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/2066830196424316606'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2017/12/logical-and-addition.html' title='Logical &amp; and addition'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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-24710794.post-171974925068981782</id><published>2017-12-15T08:46:00.001-08:00</published><updated>2017-12-15T09:35:32.273-08:00</updated><title type='text'>const behavior of a variable in C Programming Language</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
When you intend to not change the value of a variable you declare it as a const in C language.&lt;br /&gt;
&lt;br /&gt;
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #557799;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;c1&lt;/span&gt;()
{
  &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;a;
  &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;int&lt;/span&gt; b;

  a&lt;span style=&quot;color: #333333;&quot;&gt;=&amp;amp;&lt;/span&gt;amp;b;

  printf(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;*a=%d, b=%d&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;&lt;/span&gt;,&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;a, b);
  
  &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;a &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;a &lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;;
  &lt;span style=&quot;color: #888888;&quot;&gt;//b = b + 1; &lt;/span&gt;

  printf(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;*a=%d, b=%d&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;&lt;/span&gt;, &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;a, b);

&lt;span style=&quot;color: #888888;&quot;&gt;//return ;&lt;/span&gt;
}

main()
{       
        printf(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;C=%d&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;&lt;/span&gt;, c1());
}
&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;If you execute&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; b = b&amp;nbsp;+ 1:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;then the compiler complains:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;c1.c:12:5: &lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&lt;b&gt;error: &lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;cannot assign to variable &#39;b&#39; with const-qualified type &#39;const int&#39;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp; &lt;/span&gt;b = b + 1;&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp; &lt;/span&gt;~ ^&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;c1.c:5:13: &lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;&lt;b&gt;note: &lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;variable &#39;b&#39; declared const here&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp; &lt;/span&gt;const int b;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;




&lt;style type=&quot;text/css&quot;&gt;
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #34bc26; background-color: #ffffff}
span.s1 {font-variant-ligatures: no-common-ligatures}
span.s2 {font-variant-ligatures: no-common-ligatures; color: #c33720}
span.s3 {font-variant-ligatures: no-common-ligatures; color: #000000}
&lt;/style&gt;







&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;~~~~~~~~~~^&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;color: black; font-variant-ligatures: no-common-ligatures;&quot;&gt;That&#39;s what is expected.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;color: black; font-variant-ligatures: no-common-ligatures;&quot;&gt;But if we declare a pointer variable and that points to the const variable, and you increment the &quot;value&quot; of what the pointer variable is pointing to, then the compiler does not complain. &lt;/span&gt;&lt;span style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;Why?&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;color: black; font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;color: black; font-variant-ligatures: no-common-ligatures;&quot;&gt;Using only&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;color: black; font-variant-ligatures: no-common-ligatures;&quot;&gt;&amp;nbsp; *a = *a&amp;nbsp;+ 1;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;color: black; font-variant-ligatures: no-common-ligatures;&quot;&gt;actually increments the value of b because it&#39;s same as *a.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;color: black; font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;color: black; font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;color: black; font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;color: black; font-variant-ligatures: no-common-ligatures;&quot;&gt;Let&#39;s change the program slightly:&lt;/span&gt;&lt;/div&gt;
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #557799;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;c1&lt;/span&gt;()
{
  &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;a;
  &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;int&lt;/span&gt; b;

  a&lt;span style=&quot;color: #333333;&quot;&gt;=&amp;amp;&lt;/span&gt;b;

  printf(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;*a=%d, b=%d&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;&lt;/span&gt;,&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;a, b);
  
  &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;a &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;a &lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;;
  &lt;span style=&quot;color: #888888;&quot;&gt;//b = b + 1; &lt;/span&gt;

  printf(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;*a=%d, b=%d&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;&lt;/span&gt;, &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;a, b);

&lt;span style=&quot;color: #888888;&quot;&gt;//return ;&lt;/span&gt;
}

main()
{       
        printf(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;C=%d&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;&lt;/span&gt;, c1());

}
&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;color: black; font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;color: black; font-variant-ligatures: no-common-ligatures;&quot;&gt;This time the compiler gives an error.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;color: black; font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;s1.c:11:6: &lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&lt;b&gt;error: &lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;read-only variable is not assignable&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp; &lt;/span&gt;*a = *a + 1;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;style type=&quot;text/css&quot;&gt;
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #34bc26; background-color: #ffffff}
span.s1 {font-variant-ligatures: no-common-ligatures}
span.s2 {font-variant-ligatures: no-common-ligatures; color: #c33720}
&lt;/style&gt;




&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;~~ ^&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;So, the rational is if you use the&lt;/span&gt;&lt;b&gt; const&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt; identifier, then you can&#39;t update it&#39;s value.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/171974925068981782/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/171974925068981782' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/171974925068981782'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/171974925068981782'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2017/12/const-behavior-of-variable-in-c.html' title='const behavior of a variable in C Programming Language'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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-24710794.post-4214302029040399941</id><published>2017-12-15T07:12:00.002-08:00</published><updated>2017-12-15T07:59:50.542-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><category scheme="http://www.blogger.com/atom/ns#" term="C Programming Language"/><category scheme="http://www.blogger.com/atom/ns#" term="static variable"/><title type='text'>Static variable behavior</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
How the static variable behaves?&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;#include &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&lt;stdio .h=&quot;&quot;&gt;&lt;/stdio&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;//int s1();&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s3&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt; s1()&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; static&lt;/span&gt;&lt;span class=&quot;s4&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;s4&quot;&gt; s;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p5&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; return&lt;/span&gt;&lt;span class=&quot;s4&quot;&gt; s++;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;main()&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; int&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt; i=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; while&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt; (i&amp;lt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; {&lt;/span&gt;&lt;span class=&quot;Apple-converted-space&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&amp;nbsp; &amp;nbsp; i++;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;printf(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;S=&lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;%d\n&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;, s1());&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;style type=&quot;text/css&quot;&gt;
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d53bd3; background-color: #ffffff}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #5230e1; background-color: #ffffff}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #34bc26; background-color: #ffffff}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #cd7923; background-color: #ffffff}
span.s1 {font-variant-ligatures: no-common-ligatures}
span.s2 {font-variant-ligatures: no-common-ligatures; color: #c33720}
span.s3 {font-variant-ligatures: no-common-ligatures; color: #34bc26}
span.s4 {font-variant-ligatures: no-common-ligatures; color: #000000}
span.s5 {font-variant-ligatures: no-common-ligatures; color: #cd7923}
span.s6 {font-variant-ligatures: no-common-ligatures; color: #d53bd3}
&lt;/style&gt;

















&lt;br /&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;Simple program. But here&#39;s the trick.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;s is a static variable.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; return s++;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;the post increment is done as if:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; return s;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; s = s&amp;nbsp;+ 1;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;So, when the first time s1() prints, it prints the value of s = 0, s being a static variable it&#39;s initialized to 0. But the first time s1() returns before it&#39;s being incremented. The next statement of course executes, and s is incremented. Since it&#39;s a static variable, it&#39;s not in the call stack, hence it&#39;s got incremented after the s1() function returns, but before the function actually exits.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;As per Wikipedia:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #222222; font-family: &amp;quot;roboto&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; font-size: 16px;&quot;&gt;When the program (executable or library) is loaded into&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;color: #222222; font-family: Roboto, arial, sans-serif; font-size: 16px; font-variant-ligatures: normal;&quot;&gt;memory&lt;/b&gt;&lt;span style=&quot;color: #222222; font-family: &amp;quot;roboto&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; font-size: 16px;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;color: #222222; font-family: Roboto, arial, sans-serif; font-size: 16px; font-variant-ligatures: normal;&quot;&gt;static variables&lt;/b&gt;&lt;span style=&quot;color: #222222; font-family: &amp;quot;roboto&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; font-size: 16px;&quot;&gt;&amp;nbsp;are&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;color: #222222; font-family: Roboto, arial, sans-serif; font-size: 16px; font-variant-ligatures: normal;&quot;&gt;stored&lt;/b&gt;&lt;span style=&quot;color: #222222; font-family: &amp;quot;roboto&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; font-size: 16px;&quot;&gt;&amp;nbsp;in the data segment of the program&#39;s address space (if initialized), or the BSS segment (if uninitialized), and are&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;color: #222222; font-family: Roboto, arial, sans-serif; font-size: 16px; font-variant-ligatures: normal;&quot;&gt;stored&lt;/b&gt;&lt;span style=&quot;color: #222222; font-family: &amp;quot;roboto&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; font-size: 16px;&quot;&gt;&amp;nbsp;in corresponding sections of object files prior to loading.&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;br /&gt;
As per this 1995 Linux Journal article:&amp;nbsp;http://www.linuxjournal.com/article/1059&lt;br /&gt;
&lt;i&gt;&lt;span style=&quot;background-color: white; font-family: Georgia, serif;&quot;&gt;Executable code is always placed in a section known as&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: white; font-family: Georgia, serif;&quot;&gt;.text&lt;/b&gt;&lt;span style=&quot;background-color: white; font-family: Georgia, serif;&quot;&gt;; all data variables initialized by the user are placed in a section known as&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: white; font-family: Georgia, serif;&quot;&gt;.data&lt;/b&gt;&lt;span style=&quot;background-color: white; font-family: Georgia, serif;&quot;&gt;; and uninitialized data is placed in a section known as&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: white; font-family: Georgia, serif;&quot;&gt;.bss&lt;/b&gt;.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;Hence the static variable actually increments.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span style=&quot;color: #222222; font-family: &amp;quot;roboto&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; font-size: 16px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/4214302029040399941/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/4214302029040399941' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/4214302029040399941'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/4214302029040399941'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2017/12/static-variable-behavior.html' title='Static variable behavior'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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-24710794.post-9139821394645733715</id><published>2016-07-15T12:39:00.002-07:00</published><updated>2016-07-15T12:42:13.742-07:00</updated><title type='text'>New Technology Blog</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;a href=&quot;http://0x80386.blogspot.com/&quot;&gt;http://0x80386.blogspot.com/&lt;/a&gt;&lt;br /&gt;
-- Introducing my new technology blog on Cloud Computing.
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/9139821394645733715/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/9139821394645733715' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/9139821394645733715'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/9139821394645733715'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2016/07/new-technology-blog.html' title='New Technology Blog'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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-24710794.post-4220936501722044802</id><published>2015-08-12T23:32:00.000-07:00</published><updated>2015-08-12T23:32:41.924-07:00</updated><title type='text'>Let&#39;s run a c program by hand</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Let’s compile a C program by hand. The aim is to compile the
a.c program.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$cat a.h&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;#define AA 100&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;$cat a.c&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;#include “a.h”&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;main()&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;printf(“%d
apples”, AA);&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;exit(19);&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;$&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;
&lt;/span&gt;
So, this is the program we really wanted to compile. &lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;$gcc a.c –o a.exe&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;$./a.exe&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;100 apples$&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;$&lt;/span&gt;&lt;br /&gt;

&lt;br /&gt;

To know what’s happening behind the scene, do this:&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;[kongkon@cadbury ~]$ gcc -v a.c&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;Reading&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; specs from /usr/lib/gcc/i386-redhat-linux/3.4.3/specs&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;Configured with: ../configure
--prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-java-awt=gtk --host=i386-redhat-linux&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;Thread model: posix&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;gcc version 3.4.3 20050227 (Red Hat
3.4.3-22.1)&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;/usr/libexec/gcc/i386-redhat-linux/3.4.3/&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;cc1&lt;/span&gt;&lt;/b&gt;
-quiet -v a.c -quiet -dumpbase a.c&lt;span&gt;&amp;nbsp; &lt;/span&gt;-auxbase a -version -o /tmp/ccfWiYm9.s&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;ignoring nonexistent directory
&quot;/usr/lib/gcc/i386-redhat-linux/3.4.3/../../../../i386-redhat-linux/include&quot;&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;#include &quot;...&quot; search
starts here:&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;#include &amp;lt;...&amp;gt; search starts
here:&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;/usr/local/include&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;/usr/lib/gcc/i386-redhat-linux/3.4.3/include&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;/usr/include&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;End of search list.&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;GNU C version 3.4.3 20050227 (Red
Hat 3.4.3-22.1) (i386-redhat-linux)&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;compiled by GNU C version 3.4.3
20050227 (Red Hat 3.4.3-22.1).&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;GGC heuristics: --param
ggc-min-expand=98 --param ggc-min-heapsize=128313&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;color: red;&quot;&gt;as&lt;/b&gt; -V -Qy -o /tmp/ccyJwUTb.o /tmp/ccfWiYm9.s&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;GNU assembler version 2.15.92.0.2
(i386-redhat-linux) using BFD version 2.15.92.0.2 20040927&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;/usr/libexec/gcc/i386-redhat-linux/3.4.3/&lt;b style=&quot;color: red;&quot;&gt;collect2&lt;/b&gt;
--eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2
/usr/lib/gcc/i386-redhat-linux/3.4.3/../../../crt1.o
/usr/lib/gcc/i386-redhat-linux/3.4.3/../../../crti.o 
/usr/lib/gcc/i386-redhat-linux/3.4.3/crtbegin.o 
-L/usr/lib/gcc/i386-redhat-linux/3.4.3
-L/usr/lib/gcc&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;/i386-redhat-linux/3.4.3
-L/usr/lib/gcc/i386-redhat-linux/3.4.3/../../.. /tmp/cc&lt;span&gt;
&lt;/span&gt;yJwUTb.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed
-lgcc_s&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;--no-as-needed /usr/lib/gcc/i386-redhat-linux/3.4.3/crtend.o
/usr/lib/gcc/i386-redhat-linux/3.4.3/../../../crtn.o&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;[kongkon@cadbury ~]$&lt;/span&gt;&lt;br /&gt;

Understood? It’s really hard to understand. Let me explain a
little, and then things will look simpler. The –v switch to gcc explains what
gcc has done with the compilation process. Now, first of all what is gcc? gcc
is the compiler like everyone would say. Yes, it is the compiler. Actually it is a
wrapper, which calls different programs to compile the C program: if you look
at the –v output more closely you will see that, gcc calls &quot;cpp&quot;, the C preprocessor
first, then &quot;cc1&quot;, the C compiler, and then &quot;as&quot;, the assembler. As an output we
get the object file, the same what we get by running “gcc –c a.c”. Here we take
help of the linker, &quot;ld&quot;, to link a.o with our library for printf, since we have
not written code of printf() of our own. We need to link our a.o with libc.so for printf
code, as specified by -lc. This outputs a.exe, out executable. Run this, and
enjoy 100 apples. &lt;br /&gt;

&lt;br /&gt;

Let’s do every thing by hand. Let’s call all of them one by
one. First the C preprocessor, cpp.&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;[kongkon@cadbury ~]$ cpp a.c&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;# 1 &quot;a.c&quot;&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;# 1 &quot;&lt;built-in&gt;&quot;&lt;/built-in&gt;&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;# 1 &quot;&lt;command line=&quot;&quot;&gt;&lt;/command&gt;&quot;&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;# 1 &quot;a.c&quot;&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;# 1 &quot;a.h&quot; 1&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;# 2 &quot;a.c&quot; 2&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;main()&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;printf(&quot;%d apples&quot;,100);&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;exit(19);&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;[kongkon@cadbury ~]$&lt;/span&gt;&lt;br /&gt;

cpp by default dumps the output in the console, redirect it
to a file, call it a.i.&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;[kongkon@cadbury ~]$ cpp a.c -o a.i&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;[kongkon@cadbury ~]$&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;[kongkon@cadbury ~]$ ls a.*&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;a.c&lt;span&gt;&amp;nbsp;
&lt;/span&gt;a.h&lt;span&gt;&amp;nbsp; &lt;/span&gt;a.i&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;[kongkon@cadbury ~]$&lt;/span&gt;&lt;br /&gt;

&lt;br /&gt;

Next is the C compiler, cc1. &lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;[kongkon@cadbury ~]$ cc1 a.i&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;-bash: cc1: command not found&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;[kongkon@cadbury ~]$&lt;/span&gt;&lt;br /&gt;

Oops! Bash did not find&amp;nbsp; cc1, he does not know where is cc1. Take the help of gcc
itself to find where cc1 is. Do this:&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;[kongkon@cadbury ~]$ gcc
-print-prog-name=cc1&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;/usr/libexec/gcc/i386-redhat-linux/3.4.3/cc1&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;[kongkon@cadbury ~]$&lt;/span&gt;&lt;br /&gt;

Next, compile a.i, not a.c.&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;[kongkon@cadbury ~]$
/usr/libexec/gcc/i386-redhat-linux/3.4.3/cc1 a.i&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;main&lt;/span&gt;&lt;br /&gt;

&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;Execution times (seconds)&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;parser&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;:&lt;span&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;0.01 (100%) usr&lt;span&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;0.00 ( 0%) sys&lt;span&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;0.00 ( 0%) wall&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;TOTAL&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;:&lt;span&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;0.01&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;0.00&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;0.01&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;[kongkon@cadbury ~]$&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;[kongkon@cadbury ~]$ ls a.*&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;a.c&lt;span&gt;&amp;nbsp;
&lt;/span&gt;a.h&lt;span&gt;&amp;nbsp; &lt;/span&gt;a.i&lt;span&gt;&amp;nbsp; &lt;/span&gt;a.s&lt;/span&gt;&lt;br /&gt;

This produces a.s.&lt;br /&gt;

Now, call the assembler, to create the object file, a.o.&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;[kongkon@cadbury ~]$ as a.s -o a.o&lt;/span&gt;&lt;br /&gt;

So, we have the object file here, a.o.&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;[kongkon@cadbury ~]$ ls a.*&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;a.c&lt;span&gt;&amp;nbsp;
&lt;/span&gt;a.h&lt;span&gt;&amp;nbsp; &lt;/span&gt;a.i&lt;span&gt;&amp;nbsp; &lt;/span&gt;a.o&lt;span&gt;&amp;nbsp;
&lt;/span&gt;a.s&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;[kongkon@cadbury ~]$&lt;/span&gt;&lt;br /&gt;

Now, call the linker program, ld.&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;[kongkon@cadbury ~]$ ld -o a.exe
a.o -e main -lc -dynamic-linker /lib/ld-linux.so.2&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;[kongkon@cadbury ~]$ ls a.*&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;a.c&lt;span&gt;&amp;nbsp;
&lt;/span&gt;a.exe&lt;span&gt;&amp;nbsp; &lt;/span&gt;a.h&lt;span&gt;&amp;nbsp; &lt;/span&gt;a.i&lt;span&gt;&amp;nbsp;
&lt;/span&gt;a.o&lt;span&gt;&amp;nbsp; &lt;/span&gt;a.s&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;[kongkon@cadbury ~]$&lt;/span&gt;&lt;br /&gt;

So, here we have the executable binary a.exe.&lt;br /&gt;

Run this and you will see the same output as we did in our
first step.&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;[kongkon@cadbury ~]$ ./a.exe&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;color: blue;&quot;&gt;100 apples[kongkon@cadbury ~]$&lt;/span&gt;&lt;br /&gt;

&amp;nbsp;Check whether the program exited successfully.&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;kongkon@cadbury ~]$ echo $?&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;19&amp;nbsp;&lt;/span&gt;&lt;br /&gt;


&lt;span style=&quot;color: blue;&quot;&gt;[kongkon@cadbury ~]$&lt;/span&gt;&lt;br /&gt;

&lt;br /&gt;

&lt;br /&gt;

So, we have successfully compiler a C program. Happy
programming.&lt;br /&gt;

&lt;br /&gt;

&lt;div align=&quot;center&quot; style=&quot;text-align: center;&quot;&gt;
The thread ends here.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/4220936501722044802/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/4220936501722044802' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/4220936501722044802'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/4220936501722044802'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2015/08/lets-run-c-program-by-hand.html' title='Let&#39;s run a c program by hand'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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-24710794.post-5412343130161556863</id><published>2014-12-03T13:01:00.000-08:00</published><updated>2014-12-03T13:01:11.541-08:00</updated><title type='text'>rpm spec file magic</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
In Unix flavored Operating Systems various software packages are packaged along with the source file in the form of an rpm package. The rpm package contains the source rpm and the binary rpm, along with optional other dependent tools rpm packages that is needed for the main binary rpm to work. In earlier days it was achieved in the form of an tarball, which contains the configure script. The configure scripts calls the Makefile to build the final binary package that&#39;s finally ready to installed on that platform.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here I plan to discuss some of the tricks I have learned in the rpm spec file.&lt;br /&gt;
The spec file contains various sections:&lt;br /&gt;
a) %description&lt;br /&gt;
b) %prep&lt;br /&gt;
c) %build&lt;br /&gt;
d) %install&lt;br /&gt;
e) %files&lt;br /&gt;
f) %package&amp;nbsp; ## This is optional section &lt;br /&gt;
g) %clean&lt;br /&gt;
h) %changelog&lt;br /&gt;
&lt;br /&gt;
Some of these sections are self explanatory, like the %description, %clean and %changelog section. The most interesting things happen in the %build, %install and %files section.&lt;br /&gt;
In the %build and %install section you can write anything that you can write in a bash script, they understand the bash syntax and executes them.&lt;br /&gt;
The %files section however does not understand the bash scripting language, and only understand the rpm macros.&lt;br /&gt;
If you want to include addition packages in the same package.spec.in file, then the %package section comes handy, and you include a %package section for each additional rpm package you intend to produce.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The basic structure goes like this:&lt;br /&gt;
# This is a comment &lt;br /&gt;
Name:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; my-package&lt;br /&gt;
Version:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1.0&lt;br /&gt;Release:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %RPM_RELTAG%&lt;br /&gt;Summary:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; my package update release&lt;br /&gt;Source:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %RPM_SOURCE%&lt;br /&gt;License:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; License info&lt;br /&gt;Vendor:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The source code belong to&lt;br /&gt;Packager:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The repackaging is done by&lt;br /&gt;Group:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System Environment/Libraries&lt;br /&gt;Requires:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; my-package-tools&lt;br /&gt;BuildRequires:&amp;nbsp; coreutils&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ##dependent packages needed to build this package&lt;br /&gt;
&lt;br /&gt;
%description&lt;br /&gt;This provides the my package which is very important for everyone.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;%define debug_package %{nil}&lt;br /&gt;
## This is how you define a local variable (called prefix)&lt;br /&gt;%define prefix&amp;nbsp; /lib/firmware/important/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
%define MY_FILE_LIST %{expand:%( \&lt;br /&gt;FW=&quot;&quot; \&lt;br /&gt;FW+=&quot; a.bin&quot; \&amp;nbsp;&amp;nbsp;&amp;nbsp; ## a file&lt;br /&gt;
FW+=&quot; b.bin&quot; \&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ## b file&lt;br /&gt;
FW+=&quot; c.bin&quot;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ##c file&lt;br /&gt;##FW+=&quot; c1.bin&quot; \&amp;nbsp;&amp;nbsp; ##c1 file&lt;br /&gt;FW+=&quot; d.bin&quot;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ##d file&lt;br /&gt;FW+=&quot; e.bin&quot;&amp;nbsp;&amp;nbsp;&amp;nbsp; ##e file&lt;br /&gt;FW+=&quot; f.bin&quot;&amp;nbsp;&amp;nbsp;&amp;nbsp; ## f file&lt;br /&gt;echo $FW \&lt;br /&gt;)}&lt;br /&gt;&lt;br /&gt;%global flist() %{expand:%( \&lt;br /&gt;files=&quot;%*&quot; \&lt;br /&gt;if [ -n &quot;%{?1}&quot; ] ; then \&lt;br /&gt;for pkg in $files&amp;nbsp; \&lt;br /&gt;do \&lt;br /&gt;&amp;nbsp; echo &quot;%%{prefix}/$pkg&quot; \&lt;br /&gt;done \&lt;br /&gt;fi \&lt;br /&gt;)}&lt;br /&gt;
&lt;br /&gt;
%prep&lt;br /&gt;%setup -n src&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
## The % build section is also common between the base rpm package and additional (tools) rpm package&lt;br /&gt;&lt;br /&gt;
%build&lt;br /&gt;RM=rm&lt;br /&gt;
MD5SUM=/usr/bin/md5sum&amp;nbsp;&lt;br /&gt;
## md5sum is part of coreutils, hence it&#39;s mentioned in the BuildRequires &lt;br /&gt;
&lt;br /&gt;
cd fw/&lt;br /&gt;${RM} -fr checksum.txt&lt;br /&gt;
&lt;br /&gt;
for FW in %{MY_FILE_LIST}; do \&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo ${FW}; \&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ${MD5SUM} ${FW} &amp;gt;&amp;gt; checksum.txt; \&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;
%install&lt;br /&gt;install -d ${RPM_BUILD_ROOT}%{prefix}/&lt;br /&gt;cd fw/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
## This will install all the a.bin, b.bin etc files into the right place, no need list one by one&lt;br /&gt;
for FW in %{MY_FILE_LIST}; do \&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; install ${FW} ${RPM_BUILD_ROOT}%{prefix};&lt;br /&gt;done&lt;br /&gt;install checksum.txt ${RPM_BUILD_ROOT}%{prefix}&lt;br /&gt;
&lt;br /&gt;
## The tools rpm that this spec file produces installs the my_special_tool as part of it, and&lt;br /&gt;
## the % install section is common for both the base package and the addition (tools) package&lt;br /&gt;
# Install Tools files&lt;br /&gt;install -d ${RPM_BUILD_ROOT}%{prefix}&lt;br /&gt;cd ../tools&lt;br /&gt;install -m 0755 -D my_special_tool ${RPM_BUILD_ROOT}%{prefix}&lt;br /&gt;
&lt;br /&gt;
%files&lt;br /&gt;%defattr(0664,root,root)&lt;br /&gt;
## This is the magic &lt;br /&gt;
% flist %MY_FILE_LIST&lt;br /&gt;## Otherwise you have to install each individual file separately like&lt;br /&gt;
#% {prefix}/a.bin&lt;br /&gt;#% {prefix}/b.bin&lt;br /&gt;
#etc&lt;br /&gt;
&lt;br /&gt;
## Now comes information about the additional package&lt;br /&gt;
##&lt;br /&gt;## Tools package&lt;br /&gt;##&lt;br /&gt;&lt;br /&gt;%package tools&lt;br /&gt;Summary:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %{name} deployment tools&lt;br /&gt;Group:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System Environment/Base&lt;br /&gt;Requires:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; special-tools &amp;gt;= 1.4-5&lt;br /&gt;&lt;br /&gt;%description tools&lt;br /&gt;This package provides the special deployment tool for the my software.&lt;br /&gt;&lt;br /&gt;%files tools&lt;br /&gt;%defattr(-,root,root,-)&lt;br /&gt;%attr(700,root,root) %{prefix}/my_special_tool&lt;br /&gt;%doc %{_mandir}/man8/my_special_tool.8.gz&lt;br /&gt;&lt;br /&gt;%clean&lt;br /&gt;rm -rf ${RPM_BUILD_ROOT}&lt;br /&gt;&lt;br /&gt;%changelog&lt;br /&gt;* Wed Dec 03 2014 Kongkon Jyoti Dutta &lt;kongkon gmail.com=&quot;&quot;&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - ABC-123 Releasing my special tool to the world&lt;/kongkon&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/5412343130161556863/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/5412343130161556863' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/5412343130161556863'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/5412343130161556863'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2014/12/rpm-spec-file-magic.html' title='rpm spec file magic'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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-24710794.post-7553761485496290191</id><published>2014-06-10T12:40:00.000-07:00</published><updated>2014-06-10T12:40:05.780-07:00</updated><title type='text'>How to update the drive firmware in Linux</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;br /&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: center;&quot;&gt;
&lt;/h2&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
echo &quot;Using firmware file $fwfile for upgrading $product on device $x…&quot;&lt;br /&gt;
&lt;br /&gt;
The process to download in Solid State Drive and Hard Disk Drive is a little different. In case of SDD we can burn the firmware in one command, but in case of HDD we need to write in a loop since there is a limitation of 0x80000 bytes on VFS module system call.&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;b id=&quot;docs-internal-guid-4912df62-e348-5121-4f69-4d3eb38ca2a6&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if [ &quot;$rev&quot; != &quot;$target_fw_ver&quot; ]; then&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&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;echo &quot;Upgrading $disk_type firmware to version $target_fw_ver on $x i.e.$sg_dev...&quot;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&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;if &amp;nbsp;[ &quot;$disk_type&quot; = &quot;ssd&quot; ]; then&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;i&gt;&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: #4a86e8; color: blue; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;sg_write_buffer --in=${fwfile} --mode=5 --id=0 $sg_dev&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if [ $? -ne 0 ]; then&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;echo &quot;Failed to upgrade SSD firmware on $x i.e.$sg_dev to version $target_fw_ver!&quot; &amp;gt;&amp;amp;2&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;exit 1&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fi&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&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;else&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;# hdd firmware upgrade&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bytes=`ls -l $fwfile | awk &#39;{ print $5; }&#39;`&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;start=0&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#length = 0x80000 Bytes&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;length=524288&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;while [ $start -lt $bytes ]; do&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if let &#39;start+length&amp;gt;bytes&#39;; then&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;let &#39;length=bytes-start&#39;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fi&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;i&gt;&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: #4a86e8; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;sg_write_buffer --in=$fwfile --skip=$start --offset=$start --length=$length --mode=0x7 --id=0 $sg_dev&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if [ $? -ne 0 ]; then&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;echo &quot;Failed to upgrade HDD firmware $x i.e.$sg_dev to version $target_fw_ver!&quot; &amp;gt;&amp;amp;2&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;exit 1&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fi&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;let start+=length&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;done&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&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;fi&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/7553761485496290191/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/7553761485496290191' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/7553761485496290191'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/7553761485496290191'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2014/06/how-to-update-drive-firmware-in-linux.html' title='How to update the drive firmware in Linux'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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-24710794.post-7913071516505262187</id><published>2012-10-31T11:42:00.001-07:00</published><updated>2013-07-01T11:58:12.916-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="RPM"/><category scheme="http://www.blogger.com/atom/ns#" term="yum"/><title type='text'>Let&#39;s see what you installed</title><content type='html'>&lt;a href=&quot;https://plus.google.com/108640350501330256934&quot; rel=&quot;publisher&quot;&gt;Google+&lt;/a&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;u&gt;To install packages in Linux: &lt;/u&gt;&lt;br /&gt;
Packages can be installed using yum, or rpm. Each one has it&#39;s own internal database that list what is already installed into the system.&lt;br /&gt;
&lt;br /&gt;
To install a package using yum:&lt;br /&gt;
#yum install &lt;package-name&gt;&lt;/package-name&gt;&lt;br /&gt;
&lt;br /&gt;
To install a package using rpm:&lt;br /&gt;
#rpm -ivh &lt;package-name&gt;&lt;/package-name&gt;&lt;br /&gt;
#rpm -Uvh &lt;package-name an=&quot;an&quot; from=&quot;from&quot; nbsp=&quot;nbsp&quot; older=&quot;older&quot; p=&quot;p&quot; to=&quot;to&quot; upgrade=&quot;upgrade&quot; version=&quot;version&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;To check what is already installed: &lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
To check what is yum installed:&lt;br /&gt;
#yum list | grep &lt;package-name&gt; &lt;/package-name&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To check what is rpm installed:&lt;br /&gt;
#rpm -qa | grep &lt;package-name&gt;&lt;br /&gt;&lt;/package-name&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
HTH&lt;br /&gt;
--kongkon&lt;br /&gt;
&lt;/package-name&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/7913071516505262187/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/7913071516505262187' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/7913071516505262187'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/7913071516505262187'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2012/10/lets-see-what-you-installed.html' title='Let&#39;s see what you installed'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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-24710794.post-2947365179989326703</id><published>2012-10-23T18:00:00.000-07:00</published><updated>2012-10-23T18:01:31.313-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="bash"/><category scheme="http://www.blogger.com/atom/ns#" term="grep"/><category scheme="http://www.blogger.com/atom/ns#" term="unix shell scripting"/><title type='text'>How to grep in shell script...</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
The task is there is a file containing one column of entries. Write a script to compare the o/p of one command and check whether the output matches with any row of that file (supported.txt file).&lt;br /&gt;
&lt;br /&gt;
$cat supported.txt &lt;br /&gt;
SAS2308_2(C1)&lt;br /&gt;
SAS2308_2(D1)&lt;br /&gt;
&lt;br /&gt;
Assume $devInfo gives us a string that contains like the rows of support.txt file. If there is a match between the o/p of $devInfo in that file, then do nothing, else warn.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f2ede1; color: #333333; display: inline !important; float: none; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;checkSupportedFwDev() {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f2ede1; color: #333333; display: inline !important; float: none; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; local supportedControllerList=`cat supported.txt`&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f2ede1; color: #333333; display: inline !important; float: none; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; #Get the controller name from $devInfo and compare that with $supportedControllerList&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f2ede1; color: #333333; display: inline !important; float: none; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; local currentController=`echo &quot;${devInfo}&quot; | grep &quot;Controller&quot; |grep -v Number | awk &#39;{ print $NF }&#39;`&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f2ede1; color: #333333; display: inline !important; float: none; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; #echo &quot;currentController=[$currentController]&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f2ede1; color: #333333; display: inline !important; float: none; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; local supported=`echo &quot;${supportedControllerList}&quot; | grep $currentController`&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f2ede1; color: #333333; display: inline !important; float: none; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if [ -z ${supported} ]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f2ede1; color: #333333; display: inline !important; float: none; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; then&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f2ede1; color: #333333; display: inline !important; float: none; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; echo &quot;Warning: This adapter [${currentController}] is not officially supported.&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f2ede1; color: #333333; display: inline !important; float: none; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fi&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f2ede1; color: #333333; display: inline !important; float: none; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f2ede1; color: #333333; display: inline !important; float: none; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Another approach to do the same:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f2ede1; color: #333333; display: inline !important; float: none; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;checkSupportedFwDev() {&lt;/span&gt;&lt;span style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f2ede1; color: #333333; display: inline !important; float: none; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f2ede1; color: #333333; display: inline !important; float: none; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; #Get the controller name from $devInfo and compare that with $supportedControllerList&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f2ede1; color: #333333; display: inline !important; float: none; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; local currentController=`echo &quot;${devInfo}&quot; | grep &quot;Controller&quot; |grep -v Number | awk &#39;{ print $NF }&#39;`&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f2ede1; color: #333333; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot; /&gt;
&lt;span style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f2ede1; color: #333333; display: inline !important; float: none; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if ! grep &quot;^${currentController}\$&quot; supported.txt &amp;gt;/dev/null 2&amp;gt;&amp;amp;1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f2ede1; color: #333333; display: inline !important; float: none; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; then&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f2ede1; color: #333333; display: inline !important; float: none; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; echo &quot;Warning: This adapter [${currentController}] is not officially supported.&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f2ede1; color: #333333; display: inline !important; float: none; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fi&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f2ede1; color: #333333; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot; /&gt;
&lt;span style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f2ede1; color: #333333; display: inline !important; float: none; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Which approach you like and why?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/2947365179989326703/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/2947365179989326703' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/2947365179989326703'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/2947365179989326703'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2012/10/how-to-grep-in-shell-script.html' title='How to grep in shell script...'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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-24710794.post-7693077176360675223</id><published>2012-10-12T11:17:00.000-07:00</published><updated>2012-10-12T11:53:24.001-07:00</updated><title type='text'>Vi tricks</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
How to set the line numbers into vi editor?&lt;br /&gt;
Everyone knows this:&lt;br /&gt;
a) cd&lt;br /&gt;
-- go to home directory&lt;br /&gt;
b) edit(create if not there) a file called .exrc, and all this line&lt;br /&gt;
set nu&lt;br /&gt;
or set number&lt;br /&gt;
Simple.&lt;br /&gt;
&lt;br /&gt;
But, what I al now looking at is how to set the vi line numbering in only a special work directory, say /home/kdutta/mywork. I do not want to set vi line numbering to all directories, at times this is annoying.&lt;br /&gt;
Putting a .exrc file into /home/kdutta/mywork/.exrc does not seem to work, here, even if I source it. &lt;br /&gt;
&lt;br /&gt;
Do you know, how to do that?&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/7693077176360675223/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/7693077176360675223' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/7693077176360675223'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/7693077176360675223'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2012/10/vi-tricks.html' title='Vi tricks'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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-24710794.post-3848829895820098326</id><published>2012-09-27T17:28:00.000-07:00</published><updated>2012-10-23T18:02:34.166-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="bash"/><category scheme="http://www.blogger.com/atom/ns#" term="unix shell scripting"/><title type='text'>Difference between $variable and ${variable} in (bash) shell scripting</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Many often we do shell scripting, but small small ignorance at times cost a lot. Here is an example of what we mean and what it become.&lt;br /&gt;
&lt;span style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #e1e4f2; color: black; display: inline !important; float: none; font-family: monospace; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre; widows: 2; word-spacing: 0px;&quot;&gt;[/tmp]$ cat try.sh
#! /bin/sh

a=12
b=34
echo $a_$b
echo ${a}_$b
[vivarkey@/tmp]$ sh try.sh
34
12_34
[/tmp]$&lt;/span&gt;&lt;br /&gt;
&lt;br class=&quot;Apple-interchange-newline&quot; /&gt;
&lt;br class=&quot;Apple-interchange-newline&quot; /&gt;
In the above shell script we intended to print &quot;variableA_variableB&quot;, in the shell script on last but one line. But since we missed the braces around the variable it actually truncated the previous variable along with the &#39;-&#39; symbol.&lt;br /&gt;
&lt;br class=&quot;Apple-interchange-newline&quot; /&gt;
NB: This code snippet is tried in bash shell on Linux, on mac it gives different result.&lt;br /&gt;
&lt;br class=&quot;Apple-interchange-newline&quot; /&gt;
HTH&lt;br /&gt;
Kongkon&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/3848829895820098326/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/3848829895820098326' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/3848829895820098326'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/3848829895820098326'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2012/09/difference-between-variable-and.html' title='Difference between $variable and ${variable} in (bash) shell scripting'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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-24710794.post-1933057636443227270</id><published>2012-09-27T12:52:00.000-07:00</published><updated>2012-10-27T01:04:37.217-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="RPM"/><title type='text'>Playing with RPM</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Ever wondered after running the rpm --install (or rpm -ivh) command what happened, what sort of files created in the file system.&lt;br /&gt;
&lt;br /&gt;
To find out the list of files that an &lt;b&gt;already&lt;/b&gt; installed rpm spawned:&lt;br /&gt;
&lt;i&gt;rpm -ql &lt;rpm -package-name=&quot;-package-name&quot;&gt;&lt;/rpm&gt;&lt;/i&gt;&lt;br /&gt;
NB: there is no .rpm after the package name here in this command.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;[root@localhost release]# rpm -qa|grep lsifw-tools-xrtx&lt;br /&gt;lsifw-tools-xrtx-1-1.xrtx.1872.noarch&lt;br /&gt;[root@localhost release]# rpm -ql lsifw-tools-xrtx-1-1.xrtx.1872.noarch&lt;br /&gt;/lib/firmware/lsi/.NOT_RELEASE_DIR&lt;br /&gt;/lib/firmware/lsi/FirmwareID.sh&lt;br /&gt;/lib/firmware/lsi/xrtx_lsifw.sh&lt;br /&gt;/usr/share/man/man8/xrtx_lsifw.8.gz&lt;br /&gt;[root@localhost release]#&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To find out the list of files that an rpm will generate once you install the rpm:&lt;br /&gt;
&lt;i&gt;rpm -qlp &lt;rpm -package-name=&quot;-package-name&quot; .rpm=&quot;.rpm&quot;&gt;&lt;/rpm&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;[root@localhost tmp]# rpm -qlp /tmp/lsifw-tools-xrtx-1-1.xrtx.1872.src.rpm &lt;br /&gt;lsifw-tools-xrtx-source.spec&lt;br /&gt;lsifw-tools-xrtx.tgz&lt;br /&gt;[root@localhost tmp]#&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
HTH&lt;br /&gt;
Kongkon&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/1933057636443227270/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/1933057636443227270' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/1933057636443227270'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/1933057636443227270'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2012/09/playing-with-rpm.html' title='Playing with RPM'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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-24710794.post-4112960643812539831</id><published>2012-06-18T17:40:00.000-07:00</published><updated>2013-12-28T22:11:14.885-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="C++ library"/><title type='text'>C++ Library Problem</title><content type='html'>&lt;a href=&quot;https://plus.google.com/108640350501330256934&quot; rel=&quot;publisher&quot;&gt;Google+&lt;/a&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span class=&quot;entry&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;C++ Library Problem&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
You have a library provided by the vendor. All you have is header files and library files. Library contains the class &quot;Shape&quot; and there is whole hierarchy tree (I mean classes which derive from this base class).&lt;br /&gt;&lt;br /&gt;
Now
 you want to add some function &quot;getArea&quot; (not originally present in the 
class or any of its derived class) in the class &quot;Shape&quot; , you don&#39;t have 
the source code.&lt;br /&gt;


Using this library, you have written a lot of code. Now, you have to 
make some changes so that, any object of &quot;Shape&quot; class (or its derived 
class) will be able to call this function.&lt;br /&gt;&lt;br /&gt;
With your strategy, you should be able to override the definition of this function in the derived class.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.careercup.com/question?id=13872673&quot;&gt;http://www.careercup.com/question?id=13872673&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/4112960643812539831/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/4112960643812539831' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/4112960643812539831'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/4112960643812539831'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2012/06/c-library-problem.html' title='C++ Library Problem'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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><georss:featurename>Fremont, CA, USA</georss:featurename><georss:point>37.5482697 -121.9885719</georss:point><georss:box>37.447555699999995 -122.1465004 37.6489837 -121.8306434</georss:box></entry><entry><id>tag:blogger.com,1999:blog-24710794.post-2781646198650459851</id><published>2011-12-14T18:11:00.001-08:00</published><updated>2012-01-21T01:48:57.189-08:00</updated><title type='text'>A simple C program</title><content type='html'>Let&#39;s talk about simplicity. And let&#39;s look at a simple C program today. Why not, every day we deal with complex problem, so let&#39;s talk about a simple C program now.

Here is the program;
&lt;p&gt;

main() &lt;/p&gt;
{ &lt;/p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; char *p1=&quot;name&quot;; &lt;/p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; char *p2; &lt;/p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; p2=(char*)malloc(20); &lt;/p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; memset (p2, 0, 20); &lt;/p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; while(*p2++ = *p1++); &lt;/p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;%s\n&quot;, p2); &lt;/p&gt;
} &lt;/p&gt;

&lt;/p&gt;


Well, what does this program do. This is the topic of today&#39;s blog. &lt;/p&gt;

Ans:  &lt;/p&gt;

Looks like this program output&#39;s the string &lt;i&gt; name &lt;/i&gt;, but that&#39;s not true. &lt;/p&gt;

What do you think about this program? &lt;/p&gt;

Write your comments about it.</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/2781646198650459851/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/2781646198650459851' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/2781646198650459851'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/2781646198650459851'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2011/12/simple-c-program.html' title='A simple C program'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-24710794.post-8789259253706669272</id><published>2011-11-24T07:12:00.028-08:00</published><updated>2011-12-10T19:57:35.008-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++ Programming Language"/><category scheme="http://www.blogger.com/atom/ns#" term="C++ Standard Template Library"/><category scheme="http://www.blogger.com/atom/ns#" term="C++ STL"/><category scheme="http://www.blogger.com/atom/ns#" term="C++ template"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Technical Interview questions"/><title type='text'>All about C++ templates</title><content type='html'>&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-7390990723809521&quot;;
/* Second Ad */
google_ad_slot = &quot;0521889711&quot;;
google_ad_width = 336;
google_ad_height = 280;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Templates in C++ can be of class template or function template.&lt;br /&gt;
A template is used as a mechanism to generalize the parameter type we pass to either the class or function. This extends the function overloading concept of C++. Template takes the C++ concept of polymorphism to the next level.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is a example of function templates:&lt;br /&gt;
Let&#39;s say we have a swap function that swaps two variables of type T.&lt;br /&gt;
&lt;br /&gt;
void f(int a, int b, float m, float n)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; swap(a, b); &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //swap two integer values&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; swap(m, n); &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //swaps two float values&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
We can write a template function to do this as below:&lt;br /&gt;
&lt;br /&gt;
template &amp;lt;class T&gt;&lt;br /&gt;
void swap (T &amp;amp;x, T &amp;amp;y)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; T temp = x;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; x = y;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; y = T;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Similarly we have class template where we can pass any type of parameter using the template T.&lt;br /&gt;
&lt;br /&gt;
template &amp;lt; class T&gt;&lt;br /&gt;
class vector&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; T *v;    //type T vector, T can be int, float, anything&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int size;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; public:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vector (int m)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; v = new T[size = m];   // v is an array of type T&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //initialize the array&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = 0; i &amp;lt; size; i++)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;             v[i] = 0;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is an example of a class vector which initialize an object of type T of array.  Invoke it this way:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vector &amp;lt; int&gt; v1(10);   &amp;nbsp;&amp;nbsp;  //a vector class of int&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vector &amp;lt; float&gt; v2(20); &amp;nbsp;&amp;nbsp;  //a vector class of float&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Q1. Find the o/p of the code snippet:&lt;br /&gt;
template &amp;lt class T, int l=7&gt; class Foo { &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; static const T k = l;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int q;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; public:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Foo(int x = l) : q(x)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; T GetQ() const { return q; }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void f() {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Foo &amp;lt long, 9&gt; foo(10);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; std :: cout &amp;lt;&amp;lt foo.GetQ();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Ans:&lt;br /&gt;
Explaination:&lt;br /&gt;
Default values for template parameters&lt;br /&gt;
&lt;br /&gt;
Template parameters may have default values, and when instantiating the template these values can be omitted. Here’s an example:&lt;br /&gt;
&lt;br /&gt;
template &amp;lt;typename T=int, int N=10&amp;gt;&lt;br /&gt;
class Foo {&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
Foo&amp;lt;float, 42&amp;gt; foo1;&lt;br /&gt;
Foo&amp;lt;double&amp;gt; foo2;&lt;br /&gt;
Foo&amp;lt;&amp;gt; foo3;&lt;br /&gt;
&lt;br /&gt;
Note specifically the strange syntax for the definition of foo3, which means that it instantiates the Foo template with all parameters assigned their default values. Default values may only be specified for class templates. &lt;br /&gt;
&lt;br /&gt;
Q2. What is STL? &lt;br /&gt;
Ans: STL is the C++ Standard Template Library. Instead of writing your own, you can use templates from STL just like other library functions that we use from any other C/C++ library. It is a collections of class templates and function templates. We sahould use template library as it is bug free rather than writing our own like inventing the wheel again.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;In tehnical terms:&lt;/u&gt; &lt;br /&gt;
The Standard Template Libraries (STL&#39;s) are a set of C++ template classes to provide common programming data structures and functions such as doubly linked lists (list), paired arrays (map), expandable arrays (vector), large string storage and manipulation (rope), etc. The STL library is available from the STL home page. This is also your best detailed reference for all of the STL class functions available.   STL can be categorized into the following groupings:         &lt;br /&gt;
&lt;br /&gt;
Here is the greatest post about C++ Templates:&lt;br /&gt;
&lt;a href=&quot;http://eli.thegreenplace.net/2011/04/22/c-template-syntax-patterns/&quot;&gt;http://eli.thegreenplace.net/2011/04/22/c-template-syntax-patterns/&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Q3. What is partial specialization or template specialization?&lt;br /&gt;
&lt;br /&gt;
Q4. How can you force instantiation of a template?&lt;br /&gt;
&lt;br /&gt;
Q5. What is an iterator?&lt;br /&gt;
&lt;br /&gt;
Q6. What is an algorithm (in terms of the STL/C++ standard library)?</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/8789259253706669272/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/8789259253706669272' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/8789259253706669272'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/8789259253706669272'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2011/11/all-about-c-templates.html' title='All about C++ templates'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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-24710794.post-5068559889070531986</id><published>2011-10-22T03:23:00.001-07:00</published><updated>2011-12-10T19:58:22.366-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C Programming Language"/><category scheme="http://www.blogger.com/atom/ns#" term="C++ Programming Language"/><category scheme="http://www.blogger.com/atom/ns#" term="free C compiler"/><category scheme="http://www.blogger.com/atom/ns#" term="free C++ compiler"/><category scheme="http://www.blogger.com/atom/ns#" term="Online C compiler"/><category scheme="http://www.blogger.com/atom/ns#" term="online c++ compiler"/><title type='text'></title><content type='html'>&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-7390990723809521&quot;;
/* Second Ad */
google_ad_slot = &quot;0521889711&quot;;
google_ad_width = 336;
google_ad_height = 280;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;

  var _gaq = _gaq || [];
  _gaq.push([&#39;_setAccount&#39;, &#39;UA-26484561-1&#39;]);
  _gaq.push([&#39;_trackPageview&#39;]);

  (function() {
    var ga = document.createElement(&#39;script&#39;); ga.type = &#39;text/javascript&#39;; ga.async = true;
    ga.src = (&#39;https:&#39; == document.location.protocol ? &#39;https://ssl&#39; : &#39;http://www&#39;) + &#39;.google-analytics.com/ga.js&#39;;
    var s = document.getElementsByTagName(&#39;script&#39;)[0]; s.parentNode.insertBefore(ga, s);
  })();

&lt;/script&gt;  &lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Hello World!&lt;br /&gt;
&lt;br /&gt;
How about compiling a C programming right from the browser itself.&lt;br /&gt;
Here it is:&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class=&#39;widget-content&#39;&gt;&lt;iframe frameborder=&quot;0&quot; scrolling=&quot;yes&quot; height=&quot;480&quot;  src=&quot;http://codepad.org/iPNZCmyr/fork&quot;  width=&quot;750&quot; &gt;&lt;/iframe&gt; &lt;/div&gt;&lt;script type=&quot;text/javascript&quot;&gt;

  var _gaq = _gaq || [];
  _gaq.push([&#39;_setAccount&#39;, &#39;UA-26484561-1&#39;]);
  _gaq.push([&#39;_trackPageview&#39;]);

  (function() {
    var ga = document.createElement(&#39;script&#39;); ga.type = &#39;text/javascript&#39;; ga.async = true;
    ga.src = (&#39;https:&#39; == document.location.protocol ? &#39;https://ssl&#39; : &#39;http://www&#39;) + &#39;.google-analytics.com/ga.js&#39;;
    var s = document.getElementsByTagName(&#39;script&#39;)[0]; s.parentNode.insertBefore(ga, s);
  })();

&lt;/script&gt;   &lt;script type=&quot;text/javascript&quot;&gt;

  var _gaq = _gaq || [];
  _gaq.push([&#39;_setAccount&#39;, &#39;UA-26484561-1&#39;]);
  _gaq.push([&#39;_trackPageview&#39;]);

  (function() {
    var ga = document.createElement(&#39;script&#39;); ga.type = &#39;text/javascript&#39;; ga.async = true;
    ga.src = (&#39;https:&#39; == document.location.protocol ? &#39;https://ssl&#39; : &#39;http://www&#39;) + &#39;.google-analytics.com/ga.js&#39;;
    var s = document.getElementsByTagName(&#39;script&#39;)[0]; s.parentNode.insertBefore(ga, s);
  })();

&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/5068559889070531986/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/5068559889070531986' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/5068559889070531986'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/5068559889070531986'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2011/10/hello-world-how-about-compiling-c.html' title=''/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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-24710794.post-5730333278883781114</id><published>2011-10-22T00:35:00.005-07:00</published><updated>2011-12-10T19:58:41.920-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C books"/><category scheme="http://www.blogger.com/atom/ns#" term="C Programming Language"/><category scheme="http://www.blogger.com/atom/ns#" term="C++ Books"/><category scheme="http://www.blogger.com/atom/ns#" term="C++ Programming Language"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux Device Driver books"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux Kernel books"/><title type='text'>Best C/C++/Data Structure Programming books</title><content type='html'>&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-7390990723809521&quot;;
/* Second Ad */
google_ad_slot = &quot;0521889711&quot;;
google_ad_width = 336;
google_ad_height = 280;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;

  var _gaq = _gaq || [];
  _gaq.push([&#39;_setAccount&#39;, &#39;UA-26484561-1&#39;]);
  _gaq.push([&#39;_trackPageview&#39;]);

  (function() {
    var ga = document.createElement(&#39;script&#39;); ga.type = &#39;text/javascript&#39;; ga.async = true;
    ga.src = (&#39;https:&#39; == document.location.protocol ? &#39;https://ssl&#39; : &#39;http://www&#39;) + &#39;.google-analytics.com/ga.js&#39;;
    var s = document.getElementsByTagName(&#39;script&#39;)[0]; s.parentNode.insertBefore(ga, s);
  })();

&lt;/script&gt;  &lt;!-- Place this tag where you want the +1 button to render --&gt; &lt;g:plusone annotation=&quot;inline&quot;&gt;&lt;/g:plusone&gt;  &lt;!-- Place this render call where appropriate --&gt; &lt;script type=&quot;text/javascript&quot;&gt;
  (function() {
    var po = document.createElement(&#39;script&#39;); po.type = &#39;text/javascript&#39;; po.async = true;
    po.src = &#39;https://apis.google.com/js/plusone.js&#39;;
    var s = document.getElementsByTagName(&#39;script&#39;)[0]; s.parentNode.insertBefore(po, s);
  })();
&lt;/script&gt;  &lt;!-- Update your html tag to include the itemscope and itemtype attributes --&gt; &lt;html itemscope itemtype=&quot;http://schema.org/Blog&quot;&gt;  &lt;!-- Add the following three tags to your body --&gt; &lt;span itemprop=&quot;name&quot;&gt;C/C++ Programming Questions&lt;/span&gt; &lt;span itemprop=&quot;description&quot;&gt;This blog is for C/C++ Programming&lt;/span&gt; &lt;img itemprop=&quot;image&quot; src=&quot;http://cquestion.blogspot.com&quot;&gt;    &lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Here is my collection of some of the best Programming books.&lt;br /&gt;
&lt;br /&gt;
No 1 has to be this:&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/AVvXsEhE_UUMNtF9L09pRp-214MPKuUWBIW-n5NNePX3-JLm1TOTaGDI7EhOYuNawNGmo6kGfdiG8Mkv_s9gZMFJU42fKCjbXqLvkWICwURIuVaBO0-qaoBlK8HtjjywRAEckWryX0_hYw/s1600/C.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE_UUMNtF9L09pRp-214MPKuUWBIW-n5NNePX3-JLm1TOTaGDI7EhOYuNawNGmo6kGfdiG8Mkv_s9gZMFJU42fKCjbXqLvkWICwURIuVaBO0-qaoBlK8HtjjywRAEckWryX0_hYw/s320/C.jpg&quot; width=&quot;242&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the rest of them.&lt;br /&gt;
When it comes to data structure there is a book written in simple English, very easy to comprehend the basic fundamentals of computer science. &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/AVvXsEjAvHEUZHjrfI_l_4Gf28izZ2QgEECQqjeApJ3ChDCt1nMVtmGbMA_iUak_bICO6jOYyk_hc1hchFMkLKC4RdtI4KqPSshakInImR0fk0xZjqYedrcdUEfQ44fG8Dri3xLRVwglGQ/s1600/DataStructureByLipschutz.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAvHEUZHjrfI_l_4Gf28izZ2QgEECQqjeApJ3ChDCt1nMVtmGbMA_iUak_bICO6jOYyk_hc1hchFMkLKC4RdtI4KqPSshakInImR0fk0xZjqYedrcdUEfQ44fG8Dri3xLRVwglGQ/s1600/DataStructureByLipschutz.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
There are couple of C++ books. But I find this to be the best:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C++&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; How to Program by Deitel and Deitel&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And here a list of best Linux programming books:&lt;br /&gt;
a) Linux Kernel&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/AVvXsEiw8UPU8AFN87rRNRbscRJ92J17kdXaDmhyphenhyphenn3uDGWp2eglDM5uKu_bxmooNSUz000mGWkZ8ioeAgmmPMVakHBgHFxusSHmaEE1thx9-R2ErlE-W_DDS80RP1GlYUitBGn3x0dwyQQ/s1600/UnderstandingtheLinuxKernel.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiw8UPU8AFN87rRNRbscRJ92J17kdXaDmhyphenhyphenn3uDGWp2eglDM5uKu_bxmooNSUz000mGWkZ8ioeAgmmPMVakHBgHFxusSHmaEE1thx9-R2ErlE-W_DDS80RP1GlYUitBGn3x0dwyQQ/s320/UnderstandingtheLinuxKernel.jpg&quot; width=&quot;243&quot; /&gt;&lt;/a&gt;&lt;/div&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/AVvXsEh0Lb0h0pSY7XD55yT45eB9zk10GQ9_nrY9KmrnmQ2L0NQbg3vqsOypBT0xweDOQpt2AQAnpTIsT0903i0-RAhjm9p7LsWtvxZ5NZtcrR7ylNqhPOKWvO7jI_srhdWU69B5IsMjnA/s1600/LinuxKernelDevelopment.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0Lb0h0pSY7XD55yT45eB9zk10GQ9_nrY9KmrnmQ2L0NQbg3vqsOypBT0xweDOQpt2AQAnpTIsT0903i0-RAhjm9p7LsWtvxZ5NZtcrR7ylNqhPOKWvO7jI_srhdWU69B5IsMjnA/s320/LinuxKernelDevelopment.jpg&quot; width=&quot;240&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span id=&quot;goog_228291512&quot;&gt;&lt;/span&gt;&lt;span id=&quot;goog_228291513&quot;&gt;&lt;/span&gt;&lt;br /&gt;
b) Linux Device Driver Programming&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/AVvXsEh2Qf2aqMQ0cwUyV_L5CFYKOnyhu8tjMk8iYmyUbr3uI7SzBNwh4altaNmeMJpB8YJ65fw_w5LDWBsdgkvW2zYk0MepbXPOZ79xzE6eLa74ig5-o8UXteEk1ZKTyo49MTj84NrnHA/s1600/ldd3.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2Qf2aqMQ0cwUyV_L5CFYKOnyhu8tjMk8iYmyUbr3uI7SzBNwh4altaNmeMJpB8YJ65fw_w5LDWBsdgkvW2zYk0MepbXPOZ79xzE6eLa74ig5-o8UXteEk1ZKTyo49MTj84NrnHA/s320/ldd3.jpg&quot; width=&quot;243&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Enjoy, happy reading.&lt;br /&gt;
&lt;br /&gt;
Regards,&lt;br /&gt;
Kongkon&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/5730333278883781114/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/5730333278883781114' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/5730333278883781114'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/5730333278883781114'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2011/10/best-ccdata-structure-programming-books.html' title='Best C/C++/Data Structure Programming books'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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/AVvXsEhE_UUMNtF9L09pRp-214MPKuUWBIW-n5NNePX3-JLm1TOTaGDI7EhOYuNawNGmo6kGfdiG8Mkv_s9gZMFJU42fKCjbXqLvkWICwURIuVaBO0-qaoBlK8HtjjywRAEckWryX0_hYw/s72-c/C.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-24710794.post-5842719833439940878</id><published>2011-10-21T23:45:00.003-07:00</published><updated>2011-12-10T19:59:00.054-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C Programming Language"/><category scheme="http://www.blogger.com/atom/ns#" term="Java Script Linux"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux on browser"/><title type='text'>Free Linux Machine with C compiler</title><content type='html'>&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-7390990723809521&quot;;
/* Second Ad */
google_ad_slot = &quot;0521889711&quot;;
google_ad_width = 336;
google_ad_height = 280;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;

  var _gaq = _gaq || [];
  _gaq.push([&#39;_setAccount&#39;, &#39;UA-26484561-1&#39;]);
  _gaq.push([&#39;_trackPageview&#39;]);

  (function() {
    var ga = document.createElement(&#39;script&#39;); ga.type = &#39;text/javascript&#39;; ga.async = true;
    ga.src = (&#39;https:&#39; == document.location.protocol ? &#39;https://ssl&#39; : &#39;http://www&#39;) + &#39;.google-analytics.com/ga.js&#39;;
    var s = document.getElementsByTagName(&#39;script&#39;)[0]; s.parentNode.insertBefore(ga, s);
  })();

&lt;/script&gt;  &lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Hello World!&lt;br /&gt;
Many of us wanted their own Linux machine to do some C programming or at least to get a feel of the Linux Operating System.&lt;br /&gt;
&lt;br /&gt;
Here is a Linux machine which can be accessible over the internet free of cost only for you :-).&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
Just type the following URL in the browser and here you are in your own Linux machine:&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;http://bellard.org/jslinux/&lt;/b&gt;&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/AVvXsEjNi5-o4X75pvtpueXIZNH1fVFDu7dpgD-NtbtW4L1AV4WGvkHXMzSg0SQwvKJmt_X7D8Ql70jLNJmsK-IbpCEoSWafdoWlA2DKCnn7-5NEuqJh8EX_ACnQtukWcltmbkuqh24_VA/s1600/jsLinux001.jpg&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/AVvXsEjNi5-o4X75pvtpueXIZNH1fVFDu7dpgD-NtbtW4L1AV4WGvkHXMzSg0SQwvKJmt_X7D8Ql70jLNJmsK-IbpCEoSWafdoWlA2DKCnn7-5NEuqJh8EX_ACnQtukWcltmbkuqh24_VA/s320/jsLinux001.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
This is an amaizing work by Bellard. There is also a clipboard facility to copy/paste your work back and forth between your local system and the Linux machine.&lt;br /&gt;
&lt;br /&gt;
Copy your file to the clipboard: &lt;pre&gt;cat myfile &amp;gt; /dev/clipboard
&lt;/pre&gt;&lt;br /&gt;
Explore this machine, and I am sure you will have lots of fun. The best part is that there is a C Compiler to test your own C programs.&lt;br /&gt;
It&#39;s a tiny version of a C compiler called &quot;tcc&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To have a deep dive into the booting process of this OS, look at the booting sequence:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Linux version 2.6.20 (bellard@voyager) (gcc version 3.4.6 20060404 (Red Hat 3.4.6-9)) #2 Mon Aug 8 23:51:02 CEST 2011&lt;br /&gt;
BIOS-provided physical RAM map:&lt;br /&gt;
sanitize start&lt;br /&gt;
sanitize bail 0&lt;br /&gt;
&amp;nbsp;BIOS-e801: 0000000000000000 - 000000000009f000 (usable)&lt;br /&gt;
&amp;nbsp;BIOS-e801: 0000000000100000 - 0000000001000000 (usable)&lt;br /&gt;
16MB LOWMEM available.&lt;br /&gt;
Entering add_active_range(0, 0, 4096) 0 entries of 256 used&lt;br /&gt;
Zone PFN ranges:&lt;br /&gt;
&amp;nbsp; DMA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0 -&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4096&lt;br /&gt;
&amp;nbsp; Normal&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4096 -&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4096&lt;br /&gt;
early_node_map[1] active PFN ranges&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; 0:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0 -&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4096&lt;br /&gt;
On node 0 totalpages: 4096&lt;br /&gt;
&amp;nbsp; DMA zone: 32 pages used for memmap&lt;br /&gt;
&amp;nbsp; DMA zone: 0 pages reserved&lt;br /&gt;
&amp;nbsp; DMA zone: 4064 pages, LIFO batch:0&lt;br /&gt;
&amp;nbsp; Normal zone: 0 pages used for memmap&lt;br /&gt;
DMI not present or invalid.&lt;br /&gt;
Allocating PCI resources starting at 10000000 (gap: 01000000:ff000000)&lt;br /&gt;
Detected 3.333 MHz processor.&lt;br /&gt;
Built 1 zonelists.&amp;nbsp; Total pages: 4064&lt;br /&gt;
Kernel command line: console=ttyS0 root=/dev/ram0 rw init=/sbin/init notsc=1&lt;br /&gt;
Initializing CPU#0&lt;br /&gt;
Disabling TSC...&lt;br /&gt;
PID hash table entries: 64 (order: 6, 256 bytes)&lt;br /&gt;
Console: colour dummy device 80x25&lt;br /&gt;
Dentry cache hash table entries: 2048 (order: 1, 8192 bytes)&lt;br /&gt;
Inode-cache hash table entries: 1024 (order: 0, 4096 bytes)&lt;br /&gt;
Memory: 11956k/16384k available (1265k kernel code, 4040k reserved, 324k data, 124k init, 0k highmem)&lt;br /&gt;
virtual kernel memory layout:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; fixmap&amp;nbsp; : 0xffffc000 - 0xfffff000&amp;nbsp;&amp;nbsp; (&amp;nbsp; 12 kB)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; vmalloc : 0xc1800000 - 0xffffa000&amp;nbsp;&amp;nbsp; ( 999 MB)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; lowmem&amp;nbsp; : 0xc0000000 - 0xc1000000&amp;nbsp;&amp;nbsp; (&amp;nbsp; 16 MB)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .init : 0xc0290000 - 0xc02af000&amp;nbsp;&amp;nbsp; ( 124 kB)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .data : 0xc023c503 - 0xc028d854&amp;nbsp;&amp;nbsp; ( 324 kB)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .text : 0xc0100000 - 0xc023c503&amp;nbsp;&amp;nbsp; (1265 kB)&lt;br /&gt;
Checking if this processor honours the WP bit even in supervisor mode... Ok.&lt;br /&gt;
Calibrating delay using timer specific routine.. 20.22 BogoMIPS (lpj=101116)&lt;br /&gt;
Mount-cache hash table entries: 512&lt;br /&gt;
CPU: After generic identify, caps: 00000010 00000000 00000000 00000000 00000000 00000000 00000000&lt;br /&gt;
Intel Pentium with F0 0F bug - workaround enabled.&lt;br /&gt;
&lt;br /&gt;
CPU: After all inits, caps: 00000000 00000000 00000000 00000000 00000000 00000000 00000000&lt;br /&gt;
Compat vDSO mapped to ffffe000.&lt;br /&gt;
CPU: Intel Pentium MMX stepping 03&lt;br /&gt;
Checking &#39;hlt&#39; instruction... OK.&lt;br /&gt;
NET: Registered protocol family 16&lt;br /&gt;
Setting up standard PCI resources&lt;br /&gt;
NET: Registered protocol family 2&lt;br /&gt;
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)&lt;br /&gt;
TCP established hash table entries: 1024 (order: 0, 4096 bytes)&lt;br /&gt;
TCP bind hash table entries: 512 (order: -1, 2048 bytes)&lt;br /&gt;
TCP: Hash tables configured (established 1024 bind 512)&lt;br /&gt;
TCP reno registered&lt;br /&gt;
checking if image is initramfs...it isn&#39;t (bad gzip magic numbers); looks like an initrd&lt;br /&gt;
Freeing initrd memory: 2048k freed&lt;br /&gt;
Total HugeTLB memory allocated, 0&lt;br /&gt;
io scheduler noop registered&lt;br /&gt;
io scheduler anticipatory registered&lt;br /&gt;
io scheduler deadline registered&lt;br /&gt;
io scheduler cfq registered (default)&lt;br /&gt;
Real Time Clock Driver v1.12ac&lt;br /&gt;
JS clipboard: I/O at 0x03c0&lt;br /&gt;
Serial: 8250/16550 driver $Revision: 1.90 $ 4 ports, IRQ sharing disabled&lt;br /&gt;
serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16450&lt;br /&gt;
RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize&lt;br /&gt;
loop: loaded (max 8 devices)&lt;br /&gt;
TCP cubic registered&lt;br /&gt;
NET: Registered protocol family 1&lt;br /&gt;
NET: Registered protocol family 17&lt;br /&gt;
Using IPI Shortcut mode&lt;br /&gt;
Time: pit clocksource has been installed.&lt;br /&gt;
RAMDISK: ext2 filesystem found at block 0&lt;br /&gt;
RAMDISK: Loading 2048KiB [1 disk] into ram disk... | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ done.&lt;br /&gt;
EXT2-fs warning: maximal mount count reached, running e2fsck is recommended&lt;br /&gt;
VFS: Mounted root (ext2 filesystem).&lt;br /&gt;
Freeing unused kernel memory: 124k freed&lt;br /&gt;
&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Enjoy this. We shall explore more later.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/5842719833439940878/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/5842719833439940878' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/5842719833439940878'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/5842719833439940878'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2011/10/free-linux-machine-with-c-compiler.html' title='Free Linux Machine with C compiler'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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/AVvXsEjNi5-o4X75pvtpueXIZNH1fVFDu7dpgD-NtbtW4L1AV4WGvkHXMzSg0SQwvKJmt_X7D8Ql70jLNJmsK-IbpCEoSWafdoWlA2DKCnn7-5NEuqJh8EX_ACnQtukWcltmbkuqh24_VA/s72-c/jsLinux001.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-24710794.post-3303737793848633930</id><published>2011-10-21T21:42:00.001-07:00</published><updated>2011-12-10T19:59:22.352-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C Programming Language"/><category scheme="http://www.blogger.com/atom/ns#" term="Dennis Ritchie"/><category scheme="http://www.blogger.com/atom/ns#" term="RIP Dennis Ritchie"/><category scheme="http://www.blogger.com/atom/ns#" term="UNIX"/><title type='text'>RIP Dennis Ritchie</title><content type='html'>&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-7390990723809521&quot;;
/* Second Ad */
google_ad_slot = &quot;0521889711&quot;;
google_ad_width = 336;
google_ad_height = 280;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;

  var _gaq = _gaq || [];
  _gaq.push([&#39;_setAccount&#39;, &#39;UA-26484561-1&#39;]);
  _gaq.push([&#39;_trackPageview&#39;]);

  (function() {
    var ga = document.createElement(&#39;script&#39;); ga.type = &#39;text/javascript&#39;; ga.async = true;
    ga.src = (&#39;https:&#39; == document.location.protocol ? &#39;https://ssl&#39; : &#39;http://www&#39;) + &#39;.google-analytics.com/ga.js&#39;;
    var s = document.getElementsByTagName(&#39;script&#39;)[0]; s.parentNode.insertBefore(ga, s);
  })();

&lt;/script&gt;     &lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;h1 class=&quot;firstHeading&quot; id=&quot;firstHeading&quot;&gt;  Dennis Ritchie&lt;/h1&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/AVvXsEhE_UUMNtF9L09pRp-214MPKuUWBIW-n5NNePX3-JLm1TOTaGDI7EhOYuNawNGmo6kGfdiG8Mkv_s9gZMFJU42fKCjbXqLvkWICwURIuVaBO0-qaoBlK8HtjjywRAEckWryX0_hYw/s1600/C.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE_UUMNtF9L09pRp-214MPKuUWBIW-n5NNePX3-JLm1TOTaGDI7EhOYuNawNGmo6kGfdiG8Mkv_s9gZMFJU42fKCjbXqLvkWICwURIuVaBO0-qaoBlK8HtjjywRAEckWryX0_hYw/s320/C.jpg&quot; width=&quot;242&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiW4UPTG9UBeUP1LE5iXOlVVQiTRa1aayz4r-IKJT6WkkdCckycSIgcIB4rR1zooYJLx_2L0Zee647IzlpwXiJ3YITpcidlH2Jd0jCbSqK-IZjWv5qrW3myvmRnlmMDioKpEtRzUg/s1600/Dennis_MacAlistair_Ritchie.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiW4UPTG9UBeUP1LE5iXOlVVQiTRa1aayz4r-IKJT6WkkdCckycSIgcIB4rR1zooYJLx_2L0Zee647IzlpwXiJ3YITpcidlH2Jd0jCbSqK-IZjWv5qrW3myvmRnlmMDioKpEtRzUg/s1600/Dennis_MacAlistair_Ritchie.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h1 class=&quot;firstHeading&quot; id=&quot;firstHeading&quot;&gt;  &amp;nbsp;&lt;/h1&gt;&lt;h1 class=&quot;firstHeading&quot; id=&quot;firstHeading&quot;&gt;  &lt;span style=&quot;font-size: small; font-weight: normal;&quot;&gt;The great Dennis Ritchie, the creator of C Programming Language, the reason behind which this programming blog exist today, died on 12th October 2011, at the age of 70.&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;&lt;h1 class=&quot;firstHeading&quot; id=&quot;firstHeading&quot;&gt;  &lt;span style=&quot;font-size: small; font-weight: normal;&quot;&gt;Here is a small C program as a tribute to Dennis Ritchie.&lt;/span&gt;&lt;/h1&gt;&lt;h1 class=&quot;firstHeading&quot; id=&quot;firstHeading&quot;&gt;  &lt;span style=&quot;font-size: small; font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;&lt;h1 class=&quot;firstHeading&quot; id=&quot;firstHeading&quot;&gt;  &lt;span style=&quot;font-size: small; font-weight: normal;&quot;&gt;main() {&lt;/span&gt;&lt;/h1&gt;&lt;h1 class=&quot;firstHeading&quot; id=&quot;firstHeading&quot;&gt;  &lt;span style=&quot;font-size: small; font-weight: normal;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;1941: Hello World!\n&quot;);&lt;/span&gt;&lt;/h1&gt;&lt;h1 class=&quot;firstHeading&quot; id=&quot;firstHeading&quot;&gt;  &lt;span style=&quot;font-size: small; font-weight: normal;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;2011: RIP Dennis Ritchie\n&quot;);&lt;/span&gt;&lt;/h1&gt;&lt;h1 class=&quot;firstHeading&quot; id=&quot;firstHeading&quot;&gt;  &lt;span style=&quot;font-size: small; font-weight: normal;&quot;&gt;}&lt;/span&gt;&lt;/h1&gt;&lt;h1 class=&quot;firstHeading&quot; id=&quot;firstHeading&quot;&gt;  &lt;span style=&quot;font-size: small; font-weight: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/h1&gt;&lt;h1 class=&quot;firstHeading&quot; id=&quot;firstHeading&quot;&gt;  &lt;span style=&quot;font-size: small; font-weight: normal;&quot;&gt; &lt;/span&gt;&lt;/h1&gt;&lt;h1 class=&quot;firstHeading&quot; id=&quot;firstHeading&quot;&gt;  &lt;span style=&quot;font-size: small; font-weight: normal;&quot;&gt; &lt;/span&gt;&lt;/h1&gt;&lt;h1 class=&quot;firstHeading&quot; id=&quot;firstHeading&quot;&gt;  &lt;/h1&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/3303737793848633930/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/3303737793848633930' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/3303737793848633930'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/3303737793848633930'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2011/10/rip-dennis-ritchie.html' title='RIP Dennis Ritchie'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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/AVvXsEhE_UUMNtF9L09pRp-214MPKuUWBIW-n5NNePX3-JLm1TOTaGDI7EhOYuNawNGmo6kGfdiG8Mkv_s9gZMFJU42fKCjbXqLvkWICwURIuVaBO0-qaoBlK8HtjjywRAEckWryX0_hYw/s72-c/C.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-24710794.post-2327934855403172461</id><published>2011-05-20T03:30:00.027-07:00</published><updated>2012-01-21T01:46:37.103-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><category scheme="http://www.blogger.com/atom/ns#" term="C Programming Language"/><category scheme="http://www.blogger.com/atom/ns#" term="C Questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Technical Interview questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Test your C Programming skills"/><title type='text'>Test your own C Programming skills</title><content type='html'>&lt;script type=&quot;text/javascript&quot;&gt;
&lt;!--
google_ad_client = &quot;ca-pub-7390990723809521&quot;;
/* Second Ad */
google_ad_slot = &quot;0521889711&quot;;
google_ad_width = 336;
google_ad_height = 280;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
  var _gaq = _gaq || [];
  _gaq.push([&#39;_setAccount&#39;, &#39;UA-26484561-1&#39;]);
  _gaq.push([&#39;_trackPageview&#39;]);

  (function() {
    var ga = document.createElement(&#39;script&#39;); ga.type = &#39;text/javascript&#39;; ga.async = true;
    ga.src = (&#39;https:&#39; == document.location.protocol ? &#39;https://ssl&#39; : &#39;http://www&#39;) + &#39;.google-analytics.com/ga.js&#39;;
    var s = document.getElementsByTagName(&#39;script&#39;)[0]; s.parentNode.insertBefore(ga, s);
  })();
&lt;/script&gt;     &lt;br /&gt;

Hello World!&lt;br /&gt;
&lt;br /&gt;
Good morning C programmers. Here is a compilation of couple of C and C++ questions to test your C/C++ programming knowledge. Most of the time you will be facing similar questions in job interviews for Software engineer or programmer not only at the fresher level but also at a very senior level. Many companies expect you to be hands on even at senior level. C is a programming language which is easy and at the same time extremely difficult if asked about complex pointer related questions. So, one has to be extremely careful in answering such questions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;script language=&quot;javascript&quot;&gt;
&lt;!--
var state = &#39;hidden&#39;;

function showhide(layer_ref) {
if (state == &#39;visible&#39;) {
state = &#39;hidden&#39;;
}
else {
state = &#39;visible&#39;;
}
if (document.all) { //IS IE 4 or 5 (or 6 beta)
eval( &quot;document.all.&quot; + layer_ref + &quot;.style.visibility = state&quot;);
}
if (document.layers) { //IS NETSCAPE 4 or below
document.layers[layer_ref].visibility = state;
}
if (document.getElementById &amp;&amp; !document.all) {
maxwell_smart = document.getElementById(layer_ref);
maxwell_smart.style.visibility = state;
}
}
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Q1. Find the o/p:&lt;br /&gt;
main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; char *ptr=&quot;hello&quot;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; char ary[]=&quot;world&quot;;&lt;br /&gt;
&lt;br /&gt;
printf(&quot;PTR: &amp;amp;ptr=%x, ptr=%x, *ptr=%x, ptr[0]=%x\n&quot;, &amp;amp;ptr,ptr, *ptr, ptr[0]); &lt;br /&gt;
printf(&quot;ARY: &amp;amp;ary=%x,ary=%x, *ary=%x, ary[0]=%x\n&quot;, &amp;amp;ary, ary, *ary, ary[0]); &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent01&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;

&lt;div id=&quot;agent01&quot; style=&quot;visibility: hidden;&quot;&gt;
PTR: &amp;amp;ptr=bfb86990, ptr=8048524, *ptr=68, ptr[0]=68&lt;br /&gt;
ARY: &amp;amp;ary=bfb8698a,ary=bfb8698a, *ary=77, ary[0]=77&lt;/div&gt;
&lt;hr /&gt;
&lt;br /&gt;
Q2. Find the o/p:&lt;br /&gt;
main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; struct node {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; char a; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int b;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; short c;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct node next;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }n1;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
printf(&quot;Ans1:%d\n&quot;, sizeof(n1));&lt;br /&gt;
&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent02&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent02&quot; style=&quot;visibility: hidden;&quot;&gt;
This program will not compiler.&lt;br /&gt;
Reason: The compiler can&#39;t figure out the space needed for the structure n1.&lt;br /&gt;
[kongkond@jorhat ~]$ gcc Q2.c&lt;br /&gt;
Q2.c: In function ‘main’:&lt;br /&gt;
Q2.c:7: error: field ‘next’ has incomplete type&lt;/div&gt;
&lt;hr /&gt;
&lt;br /&gt;
Q3. Find the o/p:&lt;br /&gt;
main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; struct node {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; char a; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int b;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; short c;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct node *next;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }n1;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
printf(&quot;Ans1:\n\t node=%x\n \t node+2=%x\n&quot;, (char *)&amp;amp;n1, (char *)&amp;amp;n1+2);&lt;br /&gt;
printf(&quot;Ans2:%d\n&quot;, sizeof(n1));&lt;br /&gt;
&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent03&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent03&quot; style=&quot;visibility: hidden;&quot;&gt;
Ans1:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;node=bfcc5c94&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;node+2=bfcc5c96&lt;br /&gt;
Ans2:16&lt;/div&gt;
&lt;hr /&gt;
&lt;br /&gt;
Q4. What is the difference between fopen() and open()? When do you choose to use one over the other?&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent04&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent04&quot; style=&quot;visibility: hidden;&quot;&gt;
FILE * fopen(const char *restrict filename, const char *restrict mode);&lt;br /&gt;
--Upon successful completion fopen() returns a FILE pointer.&amp;nbsp; Otherwise, NULL is returned and the global variable errno is set to indicate the error.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int open(const char *pathname, int flags);&lt;br /&gt;
int open(const char *pathname, int flags, mode_t mode);&lt;br /&gt;
--Given a pathname for a file, open() returns a file descriptor, a small, non-negative integer for use in subsequent system calls (read(2), write(2), lseek(2), fcntl(2), etc.). The file descriptor returned by a successful call will be the lowest-numbered file descriptor not currently open for the process. &lt;/div&gt;
&lt;hr /&gt;
&lt;br /&gt;
&lt;br /&gt;
Q5. Find the o/p:&lt;br /&gt;
main()&lt;br /&gt;
{&lt;br /&gt;
if(!printf(&quot;Hello &quot;)){}&lt;br /&gt;
else&lt;br /&gt;
printf(&quot;World!&quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent05&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent05&quot; style=&quot;visibility: hidden;&quot;&gt;
&lt;br /&gt;
Hello World!&lt;/div&gt;
&lt;hr /&gt;
&lt;br /&gt;
Q6. Find the o/p:&lt;br /&gt;
main()&lt;br /&gt;
{&lt;br /&gt;
struct i{&lt;br /&gt;
int a; &amp;nbsp; &amp;nbsp;//4&lt;br /&gt;
double b; &amp;nbsp; &amp;nbsp;//8&lt;br /&gt;
char * c; &amp;nbsp; &amp;nbsp;//4&lt;br /&gt;
char d[7]; &amp;nbsp; &amp;nbsp;//8&lt;br /&gt;
short e; &amp;nbsp; &amp;nbsp;//4&lt;br /&gt;
int f; &amp;nbsp; &amp;nbsp;//4&lt;br /&gt;
};&lt;br /&gt;
printf(&quot;sizeof(i)= %d&quot;, sizeof(struct i));&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent06&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent06&quot; style=&quot;visibility: hidden;&quot;&gt;
&amp;nbsp;4+8+4+8+4+4=32&lt;/div&gt;
&lt;hr /&gt;
&lt;br /&gt;
Q6.1. Find the o/p:&lt;br /&gt;
main()&lt;br /&gt;
{&lt;br /&gt;
struct i{&lt;br /&gt;
int a; &amp;nbsp; &amp;nbsp;//4&lt;br /&gt;
double b; &amp;nbsp; &amp;nbsp;//8&lt;br /&gt;
char * c; &amp;nbsp; &amp;nbsp;//4&lt;br /&gt;
char d[3]; &amp;nbsp; &amp;nbsp;//4&lt;br /&gt;
short e; &amp;nbsp; &amp;nbsp;//4&lt;br /&gt;
int f; &amp;nbsp; &amp;nbsp;//4&lt;br /&gt;
};&lt;br /&gt;
printf(&quot;sizeof(i)= %d&quot;, sizeof(struct i));&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent061&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent061&quot; style=&quot;visibility: hidden;&quot;&gt;
&amp;nbsp;4+8+4+4+4+4=28&lt;/div&gt;
&lt;hr /&gt;
&lt;br /&gt;
&lt;br /&gt;
Q7. Find the o/p:&lt;br /&gt;
# include &amp;lt; stdio.h &amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
printf(NULL) ;&lt;br /&gt;
return ;&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent07&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent07&quot; style=&quot;visibility: hidden;&quot;&gt;
&lt;br /&gt;
&amp;gt; ./a.out&lt;br /&gt;
&amp;gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;br /&gt;
Q8. Find the o/p:&lt;br /&gt;
# include &amp;lt; stdio.h &amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
int i = 0;&lt;br /&gt;
printf(i) ;&lt;br /&gt;
return ;&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent08&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent08&quot; style=&quot;visibility: hidden;&quot;&gt;
In newer gcc compiler this will not compile. In older ones:&lt;br /&gt;
&amp;gt; ./a.out&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But,&lt;br /&gt;
# include &amp;lt; stdio.h &amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
int i = 0;&lt;br /&gt;
printf(&quot;%f\n&quot;, i) ;&lt;br /&gt;
return ;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Ans: random number like:&lt;br /&gt;
-0.008430&lt;br /&gt;
&lt;br /&gt;
And the result of the following will be like this:&lt;br /&gt;
# include &amp;lt; stdio.h &amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
int i = 0;&lt;br /&gt;
printf(&quot;%f %d\n&quot;, i) ;&lt;br /&gt;
return ;&lt;br /&gt;
}&lt;br /&gt;
Ans:random number like:&lt;br /&gt;
-0.008430 &amp;nbsp; 134513785&lt;/div&gt;
&lt;hr /&gt;
&lt;br /&gt;
Q9. Find the o/p:&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
printf(&quot;%s&quot;,NULL) ;&lt;br /&gt;
return ;&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent09&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent09&quot; style=&quot;visibility: hidden;&quot;&gt;
&lt;br /&gt;
&amp;gt; ./a.out&lt;br /&gt;
(null)&lt;br /&gt;
&lt;br /&gt;
But,&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
int i = -10;&lt;br /&gt;
printf(&quot;%s\n&quot;,i) ;&lt;br /&gt;
return ;&lt;br /&gt;
}&lt;br /&gt;
will result in &quot;Segmentation fault&quot; if the value of i is other than zero.&lt;/div&gt;
&lt;hr /&gt;
&lt;br /&gt;
Q10. Find the o/p of this last one:&lt;br /&gt;
main()&lt;br /&gt;
{&lt;br /&gt;
printf(&quot;%%&quot;,7);&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent10&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent10&quot; style=&quot;visibility: hidden;&quot;&gt;
&lt;br /&gt;
Try yourself&lt;/div&gt;
&lt;hr /&gt;
&lt;br /&gt;
Q11. How do I declare an array of N pointers to functions returning pointers to functions returning pointers to characters?&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent11&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent11&quot; style=&quot;visibility: hidden;&quot;&gt;
Well, first you need to know how to declare an array of N items of type T - that&#39;s&lt;br /&gt;
&lt;br /&gt;
T foo[N];&lt;br /&gt;
&lt;br /&gt;
Now you need to look at how to declare a pointer to function returning something, say, an object of type S. That&#39;s like this:&lt;br /&gt;
&lt;br /&gt;
S (*bar)();&lt;br /&gt;
&lt;br /&gt;
Now assume that S is ``pointer to function returning pointer to char&#39;&#39;. We get&lt;br /&gt;
&lt;br /&gt;
(char *) (*)() (*bar)().&lt;br /&gt;
&lt;br /&gt;
So, the whole thing turns out to be (with appropriate parentheses)&lt;br /&gt;
&lt;br /&gt;
(((char)(*))((*)())(((*)((foo)))())([(N)]));&lt;br /&gt;
&lt;br /&gt;
If your compiler complains, break this down into subexpressions.&lt;br /&gt;
&lt;br /&gt;
To call it, just use&lt;br /&gt;
&lt;br /&gt;
foo[i]();&lt;br /&gt;
&lt;br /&gt;
This works because, in C, declaration reflects use, but it&#39;s one of those weird distorted mirrors.&lt;/div&gt;
&lt;hr /&gt;
&lt;br /&gt;
Q12. What is asmlinkage and what is it&#39;s use?&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent12&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent12&quot; style=&quot;visibility: hidden;&quot;&gt;
&quot;asmlinkage&quot; is defined, for example, in the header file&lt;br /&gt;
&quot;include/asm-i386/linkage.h&quot; as&lt;br /&gt;
__attribute__((regparm(0)))&lt;br /&gt;
that tells compiler put all function parameters in the stack (i.e.&lt;br /&gt;
disables call optimization). &lt;br /&gt;
In simple terms, a) you are using assembly code using asmlinkage, and b) all the function parameters are pushed into the stack and optimization is disabled for this purpose.&lt;br /&gt;
For more details check this &lt;a href=&quot;http://kernelnewbies.org/FAQ/asmlinkage&quot;&gt;link&lt;/a&gt;.&lt;/div&gt;
&lt;hr /&gt;
&lt;br /&gt;
Q13. What is output?&lt;br /&gt;
main()&lt;br /&gt;
{&lt;br /&gt;
printf(&quot;%x&quot;,-1&amp;lt;&amp;lt;4); } &lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent13&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div id=&quot;agent13&quot; style=&quot;visibility: hidden;&quot;&gt;
[root@monday kongkon]# gcc 2.c&lt;br /&gt;
2.c: In function âmainâ:&lt;br /&gt;
2.c:3: warning: incompatible implicit declaration of built-in function âprintfâ&lt;br /&gt;
[root@monday kongkon]# ./a.out&lt;br /&gt;
fffffff0[root@monday kongkon]#&lt;br /&gt;
&lt;br /&gt;
(1)10=(0000 0000 0000 0001)2&lt;br /&gt;
(-1)10=(2&#39;s complement of binary 1)=(1&#39;s complement of 1 added with 1) =(1111 1111 1111 1110 + 1 )2=(1111 1111 1111 1111)2&lt;br /&gt;
Now,&lt;br /&gt;
(-1)10 &amp;lt;&amp;lt; 4 = (1111 1111 1111 0000)2=(F F F 0)16 Note: In Computer, Negative numbers are represented in 2&#39;s complement form, which is 1&#39;s complement +1.  &lt;/div&gt;
Link to the earlier post: &lt;a href=&quot;http://testyourprogrammingskills.blogspot.com/2011/05/q1.html&quot;&gt;Test your programming skills&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Enjoy yourself.&lt;br /&gt;
Regards,&lt;br /&gt;
Kongkon&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;hr /&gt;
&lt;br /&gt;
&lt;script src=&quot;http://www.assoc-amazon.com/s/link-enhancer?tag=cques-20&amp;amp;o=1&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/2327934855403172461/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/2327934855403172461' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/2327934855403172461'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/2327934855403172461'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2011/05/test-c.html' title='Test your own C Programming skills'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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-24710794.post-599214901241983148</id><published>2011-03-08T01:43:00.005-08:00</published><updated>2011-12-10T20:00:02.110-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><category scheme="http://www.blogger.com/atom/ns#" term="C Programming Language"/><category scheme="http://www.blogger.com/atom/ns#" term="C Questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Data Structures in C"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Technical Interview questions"/><title type='text'>Single Linked List using C</title><content type='html'>&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-7390990723809521&quot;;
/* Second Ad */
google_ad_slot = &quot;0521889711&quot;;
google_ad_width = 336;
google_ad_height = 280;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;

  var _gaq = _gaq || [];
  _gaq.push([&#39;_setAccount&#39;, &#39;UA-26484561-1&#39;]);
  _gaq.push([&#39;_trackPageview&#39;]);

  (function() {
    var ga = document.createElement(&#39;script&#39;); ga.type = &#39;text/javascript&#39;; ga.async = true;
    ga.src = (&#39;https:&#39; == document.location.protocol ? &#39;https://ssl&#39; : &#39;http://www&#39;) + &#39;.google-analytics.com/ga.js&#39;;
    var s = document.getElementsByTagName(&#39;script&#39;)[0]; s.parentNode.insertBefore(ga, s);
  })();

&lt;/script&gt;    &lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Here is a single linked list data structure using C Language:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &lt;stdio.h&gt;&lt;br /&gt;
&lt;br /&gt;
struct node {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;int data;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;struct node * next;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
struct node *first = NULL;&lt;br /&gt;
&lt;br /&gt;
int menu();&lt;br /&gt;
&lt;br /&gt;
struct node * insert_node(int data);&lt;br /&gt;
struct node * delete_node(int data);&lt;br /&gt;
int count_node(struct node *);&lt;br /&gt;
int traverse_list(struct node *);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int menu()&lt;br /&gt;
{&lt;br /&gt;
int item = 0;&lt;br /&gt;
&lt;br /&gt;
return item;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
* This routine will insert a new node to the left hand side of a linked list. And make this new node as the first node after insertion.&lt;br /&gt;
*/&lt;br /&gt;
struct node * insert_node(int data)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;struct node * temp = NULL;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;temp = (struct node *)malloc(sizeof(struct node));&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (!temp)&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;printf(&quot;Not enough memory in the system\n&quot;);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// insert data;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;temp-&amp;gt;data = data;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(first == NULL)&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;first = temp;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;temp-&amp;gt;next = NULL;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//printf(&quot;data=%d\n&quot;, temp-&amp;gt;data);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;temp-&amp;gt;next = first;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;first = temp;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&lt;br /&gt;
return first;&lt;br /&gt;
}&lt;br /&gt;
/*&lt;br /&gt;
delete_node(int data) deletes the first node from the singly linked list where the data matches, and returns the starting of the list.&lt;br /&gt;
*/&lt;br /&gt;
struct node * delete_node(int data)&lt;br /&gt;
{&lt;br /&gt;
struct node * current = first, *prev;&lt;br /&gt;
//search the list for the first occurance of &quot;data&quot;. If no node with &quot;data&quot; found then the list remains the same.&lt;br /&gt;
&lt;div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;while(current &amp;amp;&amp;amp; current-&amp;gt;data!=data)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;prev = current;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;current=current-&amp;gt;next;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;prev-&amp;gt;next = current-&amp;gt;next;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;free(current);&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;return first;&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;int traverse_list(struct node *list_head)&lt;/div&gt;&lt;div&gt;{&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;struct node * current, *prev;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (!first)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;printf(&quot;Empty list\n&quot;);&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;current = first;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;prev = current-&amp;gt;next;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;printf(&quot;\n\nList = &quot;);&lt;/div&gt;&lt;div&gt;#if 1&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;while(current)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;printf(&quot;\t %d&quot;, current-&amp;gt;data);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;current = current-&amp;gt;next;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/div&gt;&lt;div&gt;#endif&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;printf(&quot;\n\n&quot;);&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;main()&lt;/div&gt;&lt;div&gt;{&lt;/div&gt;&lt;div&gt;insert_node(30);&lt;/div&gt;&lt;div&gt;insert_node(40);&lt;/div&gt;&lt;div&gt;insert_node(50);&lt;/div&gt;&lt;div&gt;insert_node(60);&lt;/div&gt;&lt;div&gt;insert_node(70);&lt;/div&gt;&lt;div&gt;traverse_list(first);&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;delete_node(50);&lt;/div&gt;&lt;div&gt;traverse_list(first);&lt;/div&gt;&lt;div&gt;return 0;&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Result of running this program:&lt;/div&gt;&lt;div&gt;&lt;div&gt;kongkon@Linkat-Luidia:~/sea&amp;gt; ./a.out&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;List = &amp;nbsp; 70 &amp;nbsp; &amp;nbsp; &amp;nbsp;60 &amp;nbsp; &amp;nbsp; &amp;nbsp;50 &amp;nbsp; &amp;nbsp; &amp;nbsp;40 &amp;nbsp; &amp;nbsp; &amp;nbsp;30&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;List = &amp;nbsp; 70 &amp;nbsp; &amp;nbsp; &amp;nbsp;60 &amp;nbsp; &amp;nbsp; &amp;nbsp;40 &amp;nbsp; &amp;nbsp; &amp;nbsp;30&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/599214901241983148/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/599214901241983148' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/599214901241983148'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/599214901241983148'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2011/03/single-linked-list-using-c.html' title='Single Linked List using C'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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-24710794.post-6106517531565417398</id><published>2010-06-07T09:15:00.004-07:00</published><updated>2011-12-10T20:00:19.664-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><category scheme="http://www.blogger.com/atom/ns#" term="C Programming Language"/><category scheme="http://www.blogger.com/atom/ns#" term="C Questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Technical Interview questions"/><title type='text'>C</title><content type='html'>&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-7390990723809521&quot;;
/* Second Ad */
google_ad_slot = &quot;0521889711&quot;;
google_ad_width = 336;
google_ad_height = 280;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;

  var _gaq = _gaq || [];
  _gaq.push([&#39;_setAccount&#39;, &#39;UA-26484561-1&#39;]);
  _gaq.push([&#39;_trackPageview&#39;]);

  (function() {
    var ga = document.createElement(&#39;script&#39;); ga.type = &#39;text/javascript&#39;; ga.async = true;
    ga.src = (&#39;https:&#39; == document.location.protocol ? &#39;https://ssl&#39; : &#39;http://www&#39;) + &#39;.google-analytics.com/ga.js&#39;;
    var s = document.getElementsByTagName(&#39;script&#39;)[0]; s.parentNode.insertBefore(ga, s);
  })();

&lt;/script&gt;    &lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;Today we shall discuss about a simple C program.&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;I would like to explain the difference between array and &amp;amp;array address.&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;So, let&#39;s start by taking a live question.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;Q. Find the o/p:&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;main()&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;{&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char *ptr=&quot;hello&quot;;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char ary[]=&quot;world&quot;;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;printf(&quot;Ans:\n&quot;);&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;printf(&quot;PTR: &amp;amp;ptr=%x, ptr=%x, *ptr=%x, ptr[0]=%x\n&quot;, &amp;amp;ptr,ptr, *ptr, ptr[0]);&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;printf(&quot;ARY: &amp;amp;ary=%x,ary=%x, *ary=%x, ary[0]=%x\n&quot;, &amp;amp;ary, ary, *ary, ary[0]);&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;}&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;Ans:&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;PTR: &amp;amp;ptr=bfb86990, ptr=8048524, *ptr=68, ptr[0]=68&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;ARY: &amp;amp;ary=bfb8698a,ary=bfb8698a, *ary=77, ary[0]=77&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;When you look at the output of array and &amp;amp;array you will find that they both are same. Why? But, whereas in the case of a character pointer (not a character array), they seems to differ. Why again?&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;We all know that an array is like a constant pointer, and the address of the arrary is also indicated by the name of the array itself. Hence, when we mention arrary and when we mention &amp;amp;array they both mean the same and point to the same location. Memory allocation also happens in the same area as the starting address of the array.&lt;/div&gt;&lt;div&gt;But, but in case of a character pointer, prt and &amp;amp;ptr points to two distinct and different locations. &amp;amp;ptr is the place which is used by the compiler itself to store the actual data string that is pointed by ptr. &amp;amp;ptr points to a .rodata area inside the data segment,&amp;nbsp;accessible&amp;nbsp;and allocated by the compiler itself.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;That is the only reason, why you get a segmentation fault while trying to modify the data pointed by the ptr character pointer.&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;</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/6106517531565417398/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/6106517531565417398' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/6106517531565417398'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/6106517531565417398'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2010/06/c_07.html' title='C'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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-24710794.post-6752814561335597923</id><published>2010-05-14T11:15:00.005-07:00</published><updated>2011-12-10T20:00:49.026-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++ Programming Language"/><category scheme="http://www.blogger.com/atom/ns#" term="C++ Questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Technical Interview questions"/><title type='text'>C++ questions: Part 8</title><content type='html'>&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-7390990723809521&quot;;
/* Second Ad */
google_ad_slot = &quot;0521889711&quot;;
google_ad_width = 336;
google_ad_height = 280;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;

  var _gaq = _gaq || [];
  _gaq.push([&#39;_setAccount&#39;, &#39;UA-26484561-1&#39;]);
  _gaq.push([&#39;_trackPageview&#39;]);

  (function() {
    var ga = document.createElement(&#39;script&#39;); ga.type = &#39;text/javascript&#39;; ga.async = true;
    ga.src = (&#39;https:&#39; == document.location.protocol ? &#39;https://ssl&#39; : &#39;http://www&#39;) + &#39;.google-analytics.com/ga.js&#39;;
    var s = document.getElementsByTagName(&#39;script&#39;)[0]; s.parentNode.insertBefore(ga, s);
  })();

&lt;/script&gt;   &lt;span class=&quot;tdvamseebig&quot;&gt;Q. Why the size of empty Class is one byte?&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;tdvamseebig&quot;&gt;Ans:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;tdvamseel&quot;&gt;Yes, the compiler will generate 1 byte of memory  to mark the existence of the class.&amp;nbsp; This doesn&#39;t answer WHY though.&amp;nbsp;  The reason is the language standard states that all classes must have a  memory size of at least 1 byte so that the class doesn&#39;t occupy the same  memory space with another class.&amp;nbsp; This is to prevent name mangling.&amp;nbsp;  i.e., if I declare a class A {};, the compiler will still generate an  entry in its table to something called &quot;A&quot;.&amp;nbsp; If behind that I declare  another class, say class B, if A takes 0 bytes of memory, and B&#39;s data  gets written in the place where A was declared.&amp;nbsp; In this case, an  instantiation of A would take on the properties of B.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;tdvamseel&quot;&gt;Q. What are the default methods of every object?&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;tdvamseel&quot;&gt;Ans:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;tdvamseel&quot;&gt;http://qiang-ma.blogspot.com/2007/06/c-default-methods.html&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;tdvamseel&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: red; font-weight: bold;&quot;&gt;+---------------------------------------------------------+&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red; font-weight: bold;&quot;&gt; |What                   Name                               |&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red; font-weight: bold;&quot;&gt;  +---------------------------------------------------------+&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red; font-weight: bold;&quot;&gt; |Default Constructor    A::A()                             |&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red; font-weight: bold;&quot;&gt; |Copy Constructor       A::A(const A &amp;amp;)                    |&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red; font-weight: bold;&quot;&gt; |Assignment             [const] A &amp;amp;A::operator=(const A &amp;amp;) |&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red; font-weight: bold;&quot;&gt; |Destructor             A::~A()                            |&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red; font-weight: bold;&quot;&gt;  +---------------------------------------------------------+&lt;/span&gt;&lt;span class=&quot;tdvamseebig&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red; font-weight: bold;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;Q. Why a constructor can&#39;t be virtual?&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;Ans:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana; font-size: 12px;&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;b&gt;&lt;b&gt;&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;10&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: Verdana; font-size: 9pt;&quot;&gt;&lt;table bgcolor=&quot;#E6F2FF&quot; border=&quot;0&quot; cellpadding=&quot;5&quot; cellspacing=&quot;1&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td bgcolor=&quot;#FFFFFF&quot; style=&quot;font-family: Verdana; font-size: 9pt;&quot; valign=&quot;top&quot; width=&quot;80%&quot;&gt;&lt;div align=&quot;Justify&quot; style=&quot;font-family: Verdana; font-size: 10pt; margin-left: 10px;&quot;&gt;A constructor can not be virtual because at the time when the constructor is invoked the virtual table (vtable) would not be available in the memory.&lt;br /&gt;
&lt;br /&gt;
Virtual allows us to call a function knowing only the interfaces and not the exact type of the object. To create an object you need complete information. In particular, you need to know the what you want to create exactly. Hence call to a constructor can&#39;t be virtual.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/b&gt;&lt;/b&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/6752814561335597923/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/6752814561335597923' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/6752814561335597923'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/6752814561335597923'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2010/05/c.html' title='C++ questions: Part 8'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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-24710794.post-8421072839545347369</id><published>2009-11-13T16:11:00.004-08:00</published><updated>2011-12-10T20:01:08.859-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="C++ Questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Technical Interview questions"/><title type='text'>C++ questions: Part 7</title><content type='html'>&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-7390990723809521&quot;;
/* Second Ad */
google_ad_slot = &quot;0521889711&quot;;
google_ad_width = 336;
google_ad_height = 280;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family:Arial,Helvetica,sans-serif;&quot;&gt; &lt;div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;C++ Q1&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;: What are the steps involved in designing? &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Answer:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt; Before getting into the design the designer should go through the SRS prepared by the System &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Analyst. &lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;The main tasks of design are Architectural Design and Detailed Design. &lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In Architectural Design we find what are the main modules in the problem domain. &lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In Detailed Design we find what should be done within each module.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;C++ Q2&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;: What are the main underlying concepts of object orientation? &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Answer&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;: Objects, messages, class, inheritance and polymorphism are the main concepts of object orientation.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;C++ Q3&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;: What do you meant by &quot;SBI&quot; of an object? &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Answer&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;: SBI stands for State, Behavior and Identity. Since every object has the above three. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;Ø State: &lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;It is just a value to the attribute of an object at a particular time. &lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Ø Behaviour: &lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;It describes the actions and their reactions of that object. &lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Ø Identity: &lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;An object has an identity that characterizes its own existence. The identity makes it possible to distinguish any object in an unambiguous way, and independently from its state.&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;C++ Q4&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;: Differentiate persistent &amp;amp; non-persistent objects? &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Answer&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;: Persistent refers to an object&#39;s ability to transcend time or space. A persistent object stores/saves its state in a permanent storage system with out losing the information represented by the object. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;A non-persistent object is said to be transient or ephemeral. By default objects are considered as non-persistent.&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;C++ Q5&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;: What do you meant by active and passive objects? &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Answer&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;: Active objects are one which instigate an interaction which owns a thread and they are responsible for handling control to other objects. In simple words it can be referred as client.  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;            Passive objects are one, which passively waits for the message to be processed. It waits for another object that requires its services. In simple words it can be referred as server.&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;C++ Q6&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;: What is meant by software development method? &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Answer&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;: Software development method describes how to model and build software systems in a reliable and reproducible way. To put it simple, methods that are used to represent ones&#39; thinking using graphical notations.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://cquestion.blogspot.com/feeds/8421072839545347369/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/24710794/8421072839545347369' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/8421072839545347369'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/24710794/posts/default/8421072839545347369'/><link rel='alternate' type='text/html' href='http://cquestion.blogspot.com/2009/11/c-questions-part-7.html' title='C++ questions: Part 7'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</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>