<?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-4690837514005213557</id><updated>2025-05-28T20:39:12.059+05:30</updated><category term="C++"/><category term="c language"/><category term="Qt Programming Examples"/><category term="Linux C Programming"/><category term="Linux System Programming"/><category term="Qt C++"/><category term="socket programming"/><category term="My Sql"/><category term="QGraphicsScene"/><category term="QgraphicsView examples"/><category term="Qt QML"/><category term="Anonymous Unions"/><category term="Bit set clear example"/><category term="Bitwise Operators"/><category term="C++ Debugging"/><category term="C++ Dynamic memory"/><category term="C++ Unions"/><category term="C++ dynamic_cast"/><category term="C++ new operator"/><category term="C++ static_cast"/><category term="C++11"/><category term="C++11 Auto"/><category term="C++11 Range based for loop"/><category term="C++11 Strongly typed enums"/><category term="How to swap two variables in different methods"/><category term="Linux OS issues"/><category term="Linux Shell Scripting"/><category term="Maria DB"/><category term="Maria DB Storage Engines"/><category term="Multi-character literal"/><category term="Network Programming"/><category term="Object Slicing in C++"/><category term="Object slicing"/><category term="QML Examples"/><category term="QT C++ to Qml communication"/><category term="QUdpSocket examples"/><category term="Qt C++ qmlRegisterUncreatableType() example"/><category term="Qt Creator"/><category term="Qt issues"/><category term="RDMS"/><category term="SIGINT example in linux"/><category term="Shell Scripting"/><category term="Shell script to add two numbers"/><category term="Sizeof array in function"/><category term="Sql queries"/><category term="Unix Shell Scripting"/><category term="XOR swap"/><category term="gethostbyname example in c"/><category term="memset"/><category term="new operator"/><category term="signal example program in linux"/><category term="swapping algorithms"/><category term="type casting in C++"/><category term="valgrind usage"/><title type='text'>Developers Factory</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</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>26</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4690837514005213557.post-7368498431770328392</id><published>2017-03-09T08:33:00.001+05:30</published><updated>2017-03-09T08:33:56.686+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="c language"/><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="Multi-character literal"/><title type='text'>Multi-character literal (Multiple characters inside single quotes) Vs char literal in C, C++</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Any character with in single quotes(&#39;a&#39;) is a character literal&amp;nbsp; (character constant) and a string literal is a set of characters with in double quotes (&quot;Hello&quot;).&lt;br /&gt;
And if we have multiple characters in side single quote(&#39;aa&#39;) ,it is a multi-character literal&lt;br /&gt;
&lt;br /&gt;
Before going to the multi-character literal we will check how these literals are considered (as value and type) by compiler. In C language type of character literal is int. So size of char literal is &lt;b&gt;4 bytes&lt;/b&gt; in 32 bit architecture. Where as in C++ the type of character literal is char and size is &lt;b&gt;1 byte.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Save&amp;nbsp;&lt;b&gt;&lt;/b&gt;following program with .c and .cpp extension and run with c and cpp compiler.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; int main()  
 {  
 printf(&quot;Size of char literal %d\n&quot;,sizeof(&#39;a&#39;));  
 return 0;  
 }  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;What is the value of&amp;nbsp; multiple characters inside single quotes?&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
But for multi-character literal, type is &lt;b&gt;int&lt;/b&gt; in C, C++ and the value is implementation defined. &lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;cite&gt;The value of an integer character constant containing more than one
character or containing a character or escape sequence that does not map
to a single-byte execution character (C90 6.1.3.4, C99 and C11 6.4.4.4). It is implementation defined. &lt;a href=&quot;https://gcc.gnu.org/onlinedocs/gcc/Characters-implementation.html&quot; target=&quot;_blank&quot;&gt;Reference &lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; target=&quot;_blank&quot;&gt;LINK&lt;/a&gt;&lt;/cite&gt;&lt;/blockquote&gt;
The value of multi character literal as implementation for &lt;i&gt;&lt;b&gt;gnu compiler&lt;/b&gt;&lt;/i&gt;&amp;nbsp; is as follows.&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;i&gt;The compiler evaluates a multi-character character constant a character
at a time, shifting the previous value left by the number of bits per
target character, and then or-ing in the bit-pattern of the new
character truncated to the width of a target character.  The final
bit-pattern is given type &lt;code&gt;int&lt;/code&gt;, and is therefore signed,
regardless of whether single characters are signed or not.
If there are more
characters in the constant than would fit in the target &lt;code&gt;int&lt;/code&gt; the
compiler issues a warning, and the excess leading characters are
ignored.
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;For example, &lt;code&gt;&#39;ab&#39;&lt;/code&gt; for a target with an 8-bit &lt;code&gt;char&lt;/code&gt; would be
interpreted as ‘&lt;samp&gt;(int)&amp;nbsp;((unsigned&amp;nbsp;char)&amp;nbsp;&#39;a&#39;&amp;nbsp;*&amp;nbsp;256&amp;nbsp;+&amp;nbsp;(unsigned&amp;nbsp;char)&amp;nbsp;&#39;b&#39;)&lt;/samp&gt;’, and &lt;code&gt;&#39;\234a&#39;&lt;/code&gt; as ‘&lt;samp&gt;(int)&amp;nbsp;((unsigned&amp;nbsp;char)&amp;nbsp;&#39;\234&#39;&amp;nbsp;*&amp;nbsp;256&amp;nbsp;+&amp;nbsp;(unsigned&amp;nbsp;char)&amp;nbsp;&#39;a&#39;)&lt;/samp&gt;’.&amp;nbsp; &lt;/i&gt;&lt;br /&gt;
&lt;a href=&quot;https://gcc.gnu.org/onlinedocs/cpp/Implementation-defined-behavior.html#Implementation-defined-behavior&quot; target=&quot;_blank&quot;&gt;&lt;cite&gt;&lt;/cite&gt;&lt;/a&gt;&lt;i&gt;&lt;a href=&quot;https://gcc.gnu.org/onlinedocs/cpp/Implementation-defined-behavior.html#Implementation-defined-behavior&quot; target=&quot;_blank&quot;&gt;Reference &lt;/a&gt;&lt;a href=&quot;https://gcc.gnu.org/onlinedocs/cpp/Implementation-defined-behavior.html#Implementation-defined-behavior&quot; target=&quot;_blank&quot;&gt;LINK&lt;/a&gt;&lt;/i&gt;&lt;/blockquote&gt;
&lt;b&gt;Example calculation&lt;/b&gt;: &lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&amp;nbsp;&lt;cite&gt;&lt;/cite&gt;The So for the multi character literal &#39;aa&#39;,&amp;nbsp; the value is calculated as in GNU&lt;/li&gt;
&lt;/ul&gt;
&lt;i&gt;(int)&lt;/i&gt; &#39;a&#39; * 256 + &lt;i&gt;(int) &lt;/i&gt;&#39;a&#39;&amp;nbsp; (Here 256 = 16^2)&lt;br /&gt;
(97*256) + 97&amp;nbsp; = 24929&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&amp;nbsp;&#39;aaa&#39; is valued as &lt;/li&gt;
&lt;/ul&gt;
&lt;i&gt;(int)&#39;a&#39; * 65536 + (int)&lt;/i&gt; &#39;a&#39; * 256 + &lt;i&gt;(int) &lt;/i&gt;&#39;a&#39;&amp;nbsp; (Here 65536 = 16^4)&lt;br /&gt;
(97*&lt;i&gt;65536)&lt;/i&gt; + (97*256) + 97&amp;nbsp; = 6381921&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Example Program:&lt;/b&gt;&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; #include&amp;lt;iostream&amp;gt;  
 using namespace std;  
 int main()  
 {  
 cout&amp;lt;&amp;lt;&#39;aaa&#39;&amp;lt;&amp;lt;endl;  
 return 0;  
 }  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;Output&lt;/b&gt;&lt;/span&gt;:&lt;br /&gt;
6381921&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/7368498431770328392/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2017/03/multi-character-literal-multiple.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/7368498431770328392'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/7368498431770328392'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2017/03/multi-character-literal-multiple.html' title='Multi-character literal (Multiple characters inside single quotes) Vs char literal in C, C++'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</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-4690837514005213557.post-2819685604679256779</id><published>2017-03-08T20:19:00.000+05:30</published><updated>2017-03-08T20:19:46.448+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="C++ dynamic_cast"/><category scheme="http://www.blogger.com/atom/ns#" term="C++ static_cast"/><category scheme="http://www.blogger.com/atom/ns#" term="type casting in C++"/><title type='text'>When to use dynamic_cast and static_cast in C++</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;Dynamic Cast&lt;/span&gt;&lt;/b&gt;:&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Dynamic cast is used to convert a pointer (or reference) to base type to pointer (or reference) to derived type, iff the base pointer/reference refers to derived type. This is called &lt;i&gt;&lt;b&gt;down casting&lt;/b&gt;&lt;/i&gt;. (Base -&amp;gt; Derived)&lt;/li&gt;
&lt;li&gt;This type of casting is used when these two types are &lt;b&gt;polymorphic &lt;/b&gt;(means base class should have virtual methods).&lt;/li&gt;
&lt;li&gt;No need of explicit type casting when we want to convert a pointer (or reference) to derived type to pointer (or reference) to base type. This is called &lt;b&gt;&lt;i&gt;up casting&lt;/i&gt;&lt;/b&gt;. (Derived-&amp;gt; Base )&lt;/li&gt;
&lt;li&gt;If you use&amp;nbsp;dynamic_cast for non-polymorphic classed it will through compile time error&lt;/li&gt;
&lt;li&gt;This cast is mainly used to execute the derived type specific functionality when we have base class pointer/reference. (Throgh base pointer/reference we cannot access derived type specific fucntionality)&lt;/li&gt;
&lt;li&gt;dynamic_cast safely convers to derived type in run-time, if it fails to convert it will return &lt;span style=&quot;color: red;&quot;&gt;NULL &lt;/span&gt;when target is pointer type, throws &lt;span style=&quot;color: red;&quot;&gt;bad_cast&lt;/span&gt; exception when target type to convert is reference.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;b&gt;Example&lt;/b&gt;:&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;pre&gt;&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; #include&amp;lt;iostream&amp;gt;  
 #include&amp;lt;typeinfo&amp;gt;  
 using namespace std;  
   
 class Base  
 {  
 public:  
   virtual void display() {  
     cout&amp;lt;&amp;lt;&quot;Base: Display &quot;&amp;lt;&amp;lt;endl;  
   }  
 };  
   
 class Derived: public Base  
 {  
 public:  
   void display() {  
     cout&amp;lt;&amp;lt;&quot;Derived: Display &quot;&amp;lt;&amp;lt;endl;  
   }  
   void myderfun() {  
     cout&amp;lt;&amp;lt;&quot;Derived: myderfun &quot;&amp;lt;&amp;lt;endl;  
   
   }  
 };  
   
 int main()  
 {  
   Base baseobj;  
   Derived derivedobj;  
   
   Base *pbaseobj = new Base();  
   pbaseobj-&amp;gt;display();  
   
   Base *pbaseRefDerived = new Derived();  
   pbaseRefDerived-&amp;gt;display();  
   
   Derived *pderivedobj1 = dynamic_cast&amp;lt;Derived*&amp;gt;(pbaseRefDerived); // valid  
   pderivedobj1-&amp;gt;display();  
   
   Derived *pderivedobj2 = dynamic_cast&amp;lt;Derived*&amp;gt;(&amp;amp;baseobj); // invalid, returns null pointer  
   if(pderivedobj2)  
     pderivedobj2-&amp;gt;display();  
   
   Derived &amp;amp;rderivedobj1= dynamic_cast&amp;lt;Derived&amp;amp;&amp;gt;(*pbaseRefDerived); // valid  
   rderivedobj1.display();  
   
   try {  
   Derived &amp;amp;rderivedobj2= dynamic_cast&amp;lt;Derived&amp;amp;&amp;gt;(baseobj); // invalid, throws bad_cast exception  
   rderivedobj2.display();  
   }  
   catch(bad_cast e) {  
     cout&amp;lt;&amp;lt;&quot;exception caught:: &quot;&amp;lt;&amp;lt;e.what()&amp;lt;&amp;lt;endl;  
   }  
   return 0;
 }  
   
   
&lt;/code&gt;&lt;/pre&gt;
&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;Output:&amp;nbsp;&lt;/b&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/AVvXsEgyHcP5ozyydwh5x2vTTgQoIQZstPbeW4-rWLyZRbCCyvjPwWkxBrXmFLqJKOwLqV13WKJ8NwvJeQi6l64WNnHhvnzBWrcVGmqeGOaXvahu4fubusy9cAPE33peYPpnj5xXqebrpmJrLmI/s1600/dynamic_cast.png&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/AVvXsEgyHcP5ozyydwh5x2vTTgQoIQZstPbeW4-rWLyZRbCCyvjPwWkxBrXmFLqJKOwLqV13WKJ8NwvJeQi6l64WNnHhvnzBWrcVGmqeGOaXvahu4fubusy9cAPE33peYPpnj5xXqebrpmJrLmI/s1600/dynamic_cast.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;Static Cast&lt;/span&gt;&lt;/b&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Static cast is used to convert pointers of &lt;b&gt;related &lt;/b&gt;class types (should have inheritance relation for class types)&lt;/li&gt;
&lt;li&gt;It can not convert between unrelated class types&lt;/li&gt;
&lt;li&gt;It is used to force the implicit conversion ex: short to int, int to float conversion&lt;/li&gt;
&lt;li&gt;It can also used to convert void* to specific pointer type iff void* was obtained from that specific pointer type.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;There is no overhead of runtime type checking in static_cast as in dynamic_cast &lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Example:&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;b&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; #include&amp;lt;iostream&amp;gt;  
 using namespace std;  
 class Base  
 {  
 public:  
   void display() {  
     cout&amp;lt;&amp;lt;&quot;Base: Display b:&quot;&amp;lt;&amp;lt;b&amp;lt;&amp;lt;endl;  
   }  
   int b;  
 };  
   
 class Derived: public Base  
 {  
 public:  
   void display() {  
     cout&amp;lt;&amp;lt;&quot;Derived: Display b:&quot;&amp;lt;&amp;lt;b&amp;lt;&amp;lt;&quot; d:&quot;&amp;lt;&amp;lt;d&amp;lt;&amp;lt;endl;  
   }  
   void myderfun() {  
     cout&amp;lt;&amp;lt;&quot;Derived: myderfun &quot;&amp;lt;&amp;lt;endl;  
   }  
   int d;  
 };  
   
  int main()   
  {   
   Base *pbaseobj = new Base();  
   pbaseobj-&amp;gt;b = 1;  
   pbaseobj-&amp;gt;display();  
   
   Derived *pDerived = new Derived();  
   pDerived-&amp;gt;b = 2;  
   pDerived-&amp;gt;d = 3;  
   
   Base *pbaseRefDerived = pDerived;  
   pbaseRefDerived-&amp;gt;display();  // &lt;/code&gt;&lt;/b&gt;&lt;b&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;&lt;b&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;display() &lt;/code&gt;&lt;/b&gt;not a virtual function 
   
   Derived *pderivedobj1 = static_cast&amp;lt;Derived*&amp;gt;(pbaseobj);  
   pderivedobj1-&amp;gt;display();  
   
   Derived *pderivedobj2 = static_cast&amp;lt;Derived*&amp;gt;(pbaseRefDerived);  
   pderivedobj2-&amp;gt;display();  
   
  return 0;  
   
  }  
   
&lt;/code&gt;&lt;/b&gt;&lt;/pre&gt;
&lt;b&gt;Output:&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUtVzl7x14hbSdBohAPg_eFKGTsq2oJlBe3AyAVqfKeqQ-del9xTOhZsc9ChW_HZ2rejeNNXAdwMRTwEOXIt_eQU4HnUlh_yreRpAgPYQ2jUqjFBZ1VU66WVPkVEMmq0ANf0uKEq9ybIE/s1600/static_cast.png&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/AVvXsEjUtVzl7x14hbSdBohAPg_eFKGTsq2oJlBe3AyAVqfKeqQ-del9xTOhZsc9ChW_HZ2rejeNNXAdwMRTwEOXIt_eQU4HnUlh_yreRpAgPYQ2jUqjFBZ1VU66WVPkVEMmq0ANf0uKEq9ybIE/s1600/static_cast.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/2819685604679256779/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2017/03/when-to-use-dynamiccast-and-staticcast.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/2819685604679256779'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/2819685604679256779'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2017/03/when-to-use-dynamiccast-and-staticcast.html' title='When to use dynamic_cast and static_cast in C++'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</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/AVvXsEgyHcP5ozyydwh5x2vTTgQoIQZstPbeW4-rWLyZRbCCyvjPwWkxBrXmFLqJKOwLqV13WKJ8NwvJeQi6l64WNnHhvnzBWrcVGmqeGOaXvahu4fubusy9cAPE33peYPpnj5xXqebrpmJrLmI/s72-c/dynamic_cast.png" height="72" width="72"/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4690837514005213557.post-3630986404690743221</id><published>2017-01-08T15:35:00.001+05:30</published><updated>2017-01-08T15:35:11.118+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="C++11"/><category scheme="http://www.blogger.com/atom/ns#" term="C++11 Auto"/><category scheme="http://www.blogger.com/atom/ns#" term="C++11 Range based for loop"/><category scheme="http://www.blogger.com/atom/ns#" term="C++11 Strongly typed enums"/><title type='text'>C++11 Features (Part 1)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;style type=&quot;text/css&quot;&gt;P { margin-bottom: 0.08in; }&lt;/style&gt;


&lt;br /&gt;
Here i&#39;m listing some of the C++ 11
features we can use frequently.
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
1.Auto&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
2.Range Based for loop&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
3.Strongly typed enums&lt;br /&gt;
4.Forward enum declaration &lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;
To use C++ 11 features when compiling
in commad line use any of the following flags&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;  $g++ -o myprog myprog.cpp -std=c++0x  (or)  
  $g++ -o myprog myprog.cpp -std=gnu++0x (or)  
  $g++ -o myprog myprog.cpp -std=c++11    
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;Auto&lt;/b&gt;&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
Before C++11 auto keyword is used in
the storage class, from C++11 it is used as type inference, means
automatic deduction of data type of an expression.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
We can use auto inside the blocks,
namespaces, and for loop initialization etc. Using auto we can reduce
writing the some complex type declarations like iterators
intialization in loop. 
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
We cannot use auto in return type in
fuction definition, but we can use auto for the return type when
calling function.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
Example:&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; #include&amp;lt;iostream&amp;gt;  
 #include&amp;lt;map&amp;gt;  
 using namespace std;  
 int add(int a,int b)  
 {  
 return a+b;  
 }  
 auto g=7;  
 int main()  
 {  
 int arr[5] = {0,1,2,3,4};  
 std::map&amp;lt;int,std::string&amp;gt; mapNumbers;  
 mapNumbers[1] = &quot;One&quot;;  
 mapNumbers[2] = &quot;two&quot;;  
 mapNumbers[3] = &quot;three&quot;;  
 mapNumbers[4] = &quot;four&quot;;  
 auto temp = add(1,2);  
 cout&amp;lt;&amp;lt;g&amp;lt;&amp;lt;endl;  
 for(auto i : arr) //range based for loop  
 {  
 cout&amp;lt;&amp;lt;i&amp;lt;&amp;lt;&quot; &quot;;  
 }  
 cout&amp;lt;&amp;lt;endl;  
 for(auto itm: mapNumbers) //range based for loop  
 {  
 cout&amp;lt;&amp;lt;itm.first&amp;lt;&amp;lt;&quot; &quot;&amp;lt;&amp;lt;itm.second&amp;lt;&amp;lt;&quot;\n&quot;;  
 }  
 return 0;  
 }  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
$ g++ -o autoexample  autoexample.cpp&amp;nbsp; -std=c++0x&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
$./ autoexample&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
7 
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
0 1 2 3 4 
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
1 One 
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
2 two 
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
3 three 
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
4 four 
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Range Based for loop&lt;/span&gt;:&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;
Range based for
loops allows us &#39;foreach&#39; like accessing of elements of an array,
list, initializer list or containers. When we are doing operations on
the elements of the array/containers but we don&#39;t need index of the
array/containers we are accessing, then this range based for loops
are  useful.&lt;/div&gt;
&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;
Example:&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; #include&amp;lt;iostream&amp;gt;  
 #include&amp;lt;vector&amp;gt;  
 using namespace std;  
 int main()  
 {  
 std::vector&amp;lt;int&amp;gt; vec = {1,2,3,4,5};  
 float farr[] = {6,7,8,9,10};  
 for(int i: vec)  
 {  
 cout&amp;lt;&amp;lt;i&amp;lt;&amp;lt;&quot; &quot;;  
 }  
 cout&amp;lt;&amp;lt;endl;  
 for(float f: farr)  
 {  
 cout&amp;lt;&amp;lt;f&amp;lt;&amp;lt;&quot; &quot;;  
 }  
 cout&amp;lt;&amp;lt;endl;  
 for(int t: {1,3,5,7,9})  
 {  
 cout&amp;lt;&amp;lt;t&amp;lt;&amp;lt;&quot; &quot;;  
 }  
 cout&amp;lt;&amp;lt;endl;  
 return 0;  
 }  
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Strongly typed enum&lt;/span&gt;:&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;
To overcome the
limitations and drawbacks of the old style enums C++11 introduces
strongly types enums. 
&lt;/div&gt;
&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;
In Old style&lt;/div&gt;
&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;enums are
implicitly converted into integers&lt;/li&gt;
&lt;li&gt;enum constants
 are exposed to  surrounding name scope, so name clashes happens&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&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; enum colors {
RED,GREEN, ORANGE};&lt;/div&gt;
&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&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; enum fruits {
ORANGE, APPLE, BANANA}; // name clash for ORANGE&lt;/div&gt;
&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;We cannot
specify the underlying enum type (size of enum)&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;
So to overcome
these drawbacks, c++11 introduces strongly typed enums.&lt;/div&gt;
&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;
&lt;b&gt;Ex&lt;/b&gt;: enum &lt;b&gt;class&lt;/b&gt;
colors { RED,GREEN, ORANGE };&lt;/div&gt;
&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; enum &lt;b&gt;class&lt;/b&gt;
xyz : unsigned long {x1, x2, x3};&lt;/div&gt;
&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; enum &lt;b&gt;class&lt;/b&gt;
abc : char {a1, a2, a3};&lt;/div&gt;
&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;
We can access this
enum with scope (colors::RED) or like old style (RED)&lt;/div&gt;
&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Forward enum declaration&lt;/span&gt;:&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;
We can have
forward declaration of enums like below, and after that we will
define&amp;nbsp;&amp;nbsp; enum xyz &lt;/div&gt;
&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; enum class xyz ;  
 void fun(xyz var);  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;
&lt;b&gt;Example&lt;/b&gt;:&lt;/div&gt;
&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; #include&amp;lt;iostream&amp;gt;  
 using namespace std;  
 class Sample  
 {  
 public:  
 enum class color; //forward declarion  
 void fun(color c)  
 {  
 cout&amp;lt;&amp;lt;&quot;fun &quot;&amp;lt;&amp;lt;(int)c; // no implicit conversion, explicitly convert  
 }  
 enum class color: int  
 {  
 RED=1, GREEN, ORANGE  
 };  
 enum class fruits : char  
 {  
 APPLE=1, MANGO, ORANGE // same name ORANGE, this leads to error in old style  
 };  
 };  
 int main()  
 {  
 Sample s;  
 s.fun(Sample::color::ORANGE);  
 }&amp;nbsp; &lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/3630986404690743221/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2017/01/c11-features-part-1.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/3630986404690743221'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/3630986404690743221'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2017/01/c11-features-part-1.html' title='C++11 Features (Part 1)'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</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-4690837514005213557.post-8068701743627870034</id><published>2016-12-19T09:27:00.001+05:30</published><updated>2016-12-19T09:33:02.718+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="C++ Debugging"/><category scheme="http://www.blogger.com/atom/ns#" term="valgrind usage"/><title type='text'>How to use Valgrind for debugging C/C++ program</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;style type=&quot;text/css&quot;&gt;P { margin-bottom: 0.08in; }&lt;/style&gt;


&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
Valgrind tool is used to for memory
leaks, uninitialized memory,  reading or writing to memory that has
been freed, invalid access to memory(boundary conditions for the
dynamic arrays), mismatched use of malloc/new/new[] with
free/delete/delete[] , double free/delete. 
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;b&gt;How to use Valgrind&lt;/b&gt;&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&amp;gt;Compile the program with -g option
(this option will add debugging symbols), so that we can see line
numbers of the program when debugging  
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; $ g++ -o test -g test.cpp  
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&amp;gt;use valgrind command to analyze 
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; $ valgrind --tool=memcheck --leak-check=yes ./test
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;Example&lt;/span&gt;: test.cpp&lt;br /&gt;
The following example demonstrates the debugging C++ program for&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;memory leak when the memory allocated with new don’t find delete &lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;mismatched new/new[] with delete/delete[] operators. When we create heap memory for arrays of objects/variables we use [], and when delete also we have to use []&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Boundary conditions for the allocated memory(index out of range).&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;uninitialised variable when used in the conditions.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; #include&amp;lt;iostream&amp;gt;  
 using namespace std;  
 int main()   
 {  
  int i;  
  char *c = new char;  //no delete for this memory allocated  
  char *s = new char[10];   
  s[10] = &#39;w&#39;; //Invalid access  
  if(i) { //Uninitialised variable i  
  cout&amp;lt;&amp;lt;&quot;Hello &quot;;  
  }  
  delete s; //mis matched delete  
  return 0;  
 }  
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;
when you compile above program and run valgrind tool the following result will come&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
$ g++ -o test -g test.cpp &lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
$valgrind --tool=memcheck --leak-check=yes&amp;nbsp; ./test&lt;/div&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; ==5455== Memcheck, a memory error detector  
 ==5455== Copyright (C) 2002-2011, and GNU GPL&#39;d, by Julian Seward et al.  
 ==5455== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info  
 ==5455== Command: ./test  
 ==5455==   
 ==5455== &lt;span style=&quot;color: red;&quot;&gt;Invalid write of size 1&lt;/span&gt;  
 ==5455==  at 0x8048634: main (&lt;/code&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;test&lt;/code&gt;.cpp:11)  
 ==5455== Address 0x432906a is 0 bytes after a block of size 10 alloc&#39;d  
 ==5455==  at 0x402B454: operator new[](unsigned int) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)  
 ==5455==  by 0x8048628: main (&lt;/code&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;test&lt;/code&gt;.cpp:10)  
 ==5455==   
 ==5455== &lt;span style=&quot;color: red;&quot;&gt;Conditional jump or move depends on uninitialised value(s)&lt;/span&gt;  
 ==5455==  at 0x804863C: main (&lt;/code&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;test&lt;/code&gt;.cpp:13)  
 ==5455==   
 ==5455== &lt;span style=&quot;color: red;&quot;&gt;Mismatched free() / delete / delete [] &lt;/span&gt; 
 ==5455==  at 0x402ACFC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)  
 ==5455==  by 0x804865D: main (&lt;/code&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;test&lt;/code&gt;.cpp:17)  
 ==5455== Address 0x4329060 is 0 bytes inside a block of size 10 alloc&#39;d  
 ==5455==  at 0x402B454: operator new[](unsigned int) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)  
 ==5455==  by 0x8048628: main (&lt;/code&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;test&lt;/code&gt;.cpp:10)  
 ==5455==   
 Hello ==5455==   
 ==5455== &lt;span style=&quot;color: red;&quot;&gt;HEAP SUMMARY&lt;/span&gt;:  
 ==5455==   in use at exit: 1 bytes in 1 blocks  
 ==5455==  total heap usage: 2 allocs, 1 frees, 11 bytes allocated  
 ==5455==   
 ==5455== 1 bytes in 1 blocks are definitely lost in loss record 1 of 1  
 ==5455==  at 0x402B9B4: operator new(unsigned int) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)  
 ==5455==  by 0x8048618: main (&lt;/code&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;test&lt;/code&gt;.cpp:8)  
 ==5455==   
 ==5455== &lt;span style=&quot;color: red;&quot;&gt;LEAK SUMMARY&lt;/span&gt;:  
 ==5455==  definitely lost: 1 bytes in 1 blocks  
 ==5455==  indirectly lost: 0 bytes in 0 blocks  
 ==5455==   possibly lost: 0 bytes in 0 blocks  
 ==5455==  still reachable: 0 bytes in 0 blocks  
 ==5455==     suppressed: 0 bytes in 0 blocks  
 ==5455==   
 ==5455== For counts of detected and suppressed errors, rerun with: -v  
 ==5455== Use --track-origins=yes to see where uninitialised values come from  
 ==5455== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&amp;nbsp; &lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: #274e13;&quot;&gt;&amp;gt;&lt;span style=&quot;color: blue;&quot;&gt;Corrected Version of the above program&lt;/span&gt;&lt;/span&gt;: The following program is the modified version of the above program with all the above problems corrected.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; #include&amp;lt;iostream&amp;gt;  
 using namespace std;  
 int main()   
 {  
  int i=1;  
  char *c = new char;    
  char *s = new char[10];   
  s[9] = &#39;w&#39;;   
  if(i) {   
  cout&amp;lt;&amp;lt;&quot;Hello &quot;;  
  }  
  delete c;  
  delete s[];   
  return 0;  
 }  
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;pre class=&quot;brush: csharp&quot;&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;
PS: valgrind will not check for the
invalid access(boundary conditions) of arrays allocated in stack.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/8068701743627870034/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2016/12/how-to-use-valgrind-for-debugging-cc.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/8068701743627870034'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/8068701743627870034'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2016/12/how-to-use-valgrind-for-debugging-cc.html' title='How to use Valgrind for debugging C/C++ program'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</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-4690837514005213557.post-6866551246053582448</id><published>2016-09-06T22:15:00.000+05:30</published><updated>2016-09-06T22:15:10.203+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="C++ Dynamic memory"/><category scheme="http://www.blogger.com/atom/ns#" term="C++ new operator"/><category scheme="http://www.blogger.com/atom/ns#" term="new operator"/><title type='text'>Dynamic memory allocator: new in C++</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;In c++ we will use new operator to allocate memory dynamically . In this post we will know how this process happens and what are the steps involved while using new. Basic syntax for new is&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;new [placemenet-params] typename;&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;This expression will allocate the memory available from the free store and returns the pointer to the object of type &#39;typename&#39;. And in case of class, struct types it will allocate memory and intialise the object then retun the pointer to the object &#39;typename&#39;.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Here &#39;placemenet-params&#39; is optional and it will be usefull when we overload the new operator. This will be usefull particularly when hardware dependent objects to be allocated at a specified address.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Example&lt;/b&gt;:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;int *p = new int;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;char *arr = new char[10]; //for array of 10 chars&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;ExampleClass *obj = new ExampleClass();&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;gt; Call to new internally invokes &#39;operator new&#39; function available globally to allocate memory for all types. If you overload operator new function for the particular class then the overloaded version will be called (operator new function of the class). This function will take size_t type as argument to allocate the number of bytes and returns the pointer to the object of typename.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;And we can pass any number of arguments to this overloaded operator new function which are passed as placemenet-params.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Ex&lt;/b&gt;: ExampleClass *obj = new (0x00AA) ExampleClass();&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;here (0x00AA) will be the extra parameter for the operator new function.&lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;gt; If you want to meke a call to the globally available operator new function , rather the class specific operator new function used scope resolution(::) before new&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Example&lt;/b&gt;: Type-name t = ::new Type-name;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/6866551246053582448/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2016/09/dynamic-memory-allocator-new-in-cpp.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/6866551246053582448'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/6866551246053582448'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2016/09/dynamic-memory-allocator-new-in-cpp.html' title='Dynamic memory allocator: new in C++'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</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-4690837514005213557.post-5896071713092906722</id><published>2016-07-02T18:50:00.002+05:30</published><updated>2016-07-02T18:50:48.301+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="Object slicing"/><category scheme="http://www.blogger.com/atom/ns#" term="Object Slicing in C++"/><title type='text'>Object Slicing in C++ with example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;What is Object Slicing?&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
When an instance of derived class&amp;nbsp; is copied to base class object &lt;span style=&quot;color: red;&quot;&gt;by value&lt;/span&gt; , part of members associated with derived object will be lost(sliced) . Here base class object discards the data related to the derived class because base class object don&#39;t have information about the derived members&lt;br /&gt;
&lt;br /&gt;
When we copy derived obj &lt;b&gt;by value&lt;/b&gt; to base obj,&amp;nbsp; the&lt;span style=&quot;color: #274e13;&quot;&gt; &lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;base class copy constructor /assignment operator&lt;/b&gt;&lt;/span&gt;&lt;/span&gt; will call (copy constructor will call at assigning object at the time of declaration (or) pass by value argument to function and assignment operator will call when assigning object after declarion), so base class don&#39;t have information about the derived members to copy.&amp;nbsp; This means the base copy/assignment will copy members related to base class only.&lt;br /&gt;
&lt;br /&gt;
The following sample c++ code will explain the above description.&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
#include&amp;lt;iostream&amp;gt;&lt;br /&gt;using namespace std;&lt;br /&gt;class Base&lt;br /&gt;{&lt;br /&gt;public :&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Base(){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Base default constructor\n &quot;&amp;lt;&amp;lt;endl;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Base(const Base &amp;amp;obj)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Base copy constructor\n &quot;&amp;lt;&amp;lt;endl;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Base&amp;amp; operator=(const Base &amp;amp;ob)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Base assignment op overload\n&quot;&amp;lt;&amp;lt;endl;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return *this;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; virtual void display() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Base disp &quot;&amp;lt;&amp;lt;&quot;\n\n&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;class Derived:public Base&lt;br /&gt;{&lt;br /&gt;public :&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Derived():Base()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Derived default constructor\n&quot;&amp;lt;&amp;lt;&quot;\n&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Derived(const Derived &amp;amp;obj):Base(obj)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Derived copy constructor\n &quot;&amp;lt;&amp;lt;endl;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Derived&amp;amp; operator=(const Derived &amp;amp;ob)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Derived assignment op overload\n&quot;&amp;lt;&amp;lt;endl;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; virtual void display() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Derived disp &quot;&amp;lt;&amp;lt;&quot;\n\n&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;void copyByVal(Base obj)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Copy by Val fun:&amp;nbsp; &quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; obj.display();&lt;br /&gt;}&lt;br /&gt;void copyByRef(Base &amp;amp;obj)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Copy by Ref fun:&amp;nbsp; &quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; obj.display();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int main() {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Version1: to call copy constructor&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Derived d1;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Base default constructor&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Derived default constructor&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Base b = d1;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Base copy constructor&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.display();&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; //Base disp &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Base &amp;amp;b1 = d1;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; b1.display();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Derived disp &lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Version1: to call assignment operator&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Derived d2;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Base default constructor&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Derived default constructor&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Base b2;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; //Base default constructor&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; copyByVal(d2);&amp;nbsp; //Base copy constructor&lt;/blockquote&gt;
&lt;blockquote&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; //Copy by Val fun:&amp;nbsp; Base disp &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; copyByRef(d2); //Copy by Ref fun:&amp;nbsp; Derived disp &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;br /&gt;}&lt;/blockquote&gt;
&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;OUTPUT:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
Base default constructor&lt;br /&gt;&lt;br /&gt;Derived default constructor&lt;br /&gt;&lt;br /&gt;Base copy constructor&lt;br /&gt;&lt;br /&gt;Base disp &lt;br /&gt;&lt;br /&gt;Derived disp &lt;br /&gt;&lt;br /&gt;Base default constructor&lt;br /&gt;&lt;br /&gt;Derived default constructor&lt;br /&gt;&lt;br /&gt;Base default constructor&lt;br /&gt;&lt;br /&gt;Base copy constructor&lt;br /&gt;&lt;br /&gt;Copy by Val fun:&amp;nbsp; Base disp &lt;br /&gt;&lt;br /&gt;Copy by Ref fun:&amp;nbsp; Derived disp &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;gt;&lt;/span&gt;And the following program will explain you how object slicing occurs when we copy derived class object &lt;b&gt;by value&lt;/b&gt; to base class object&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
#include&amp;lt;iostream&amp;gt;&lt;br /&gt;using namespace std;&lt;br /&gt;class Base&lt;br /&gt;{&lt;br /&gt;public :&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Base(int a){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; baseVal=a;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Base &quot;&amp;lt;&amp;lt;baseVal&amp;lt;&amp;lt;&quot;\n&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; virtual void display() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Base disp &quot;&amp;lt;&amp;lt;baseVal&amp;lt;&amp;lt;&quot;\n&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;protected:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int baseVal;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;class Derived:public Base&lt;br /&gt;{&lt;br /&gt;public :&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Derived(int a,int b):Base(a),derVal(b)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Derived &quot;&amp;lt;&amp;lt;a&amp;lt;&amp;lt;&quot; &quot;&amp;lt;&amp;lt;b&amp;lt;&amp;lt;&quot;\n&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; virtual void display() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Derived disp base &amp;amp; der vals &quot;&amp;lt;&amp;lt;baseVal&amp;lt;&amp;lt;&quot; &quot;&amp;lt;&amp;lt;derVal&amp;lt;&amp;lt;&quot;\n&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;private: &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int derVal;&lt;br /&gt;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;void copyByVal(Base obj)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Copy by Val fun:&amp;nbsp; &quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; obj.display();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void copyByRef(Base &amp;amp;obj)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Copy by Ref fun:&amp;nbsp; &quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; obj.display();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int main() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Base b(1);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Derived d(4,5);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; copyByVal(d);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; copyByRef(d);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Base b2(2);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Derived d2(5,6);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; b2 = d2;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; b2.display();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;br /&gt;}&lt;/blockquote&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;OUTPUT:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
Base 1&lt;br /&gt;Base 4&lt;br /&gt;Derived 4 5&lt;br /&gt;Copy by Val fun:&amp;nbsp; Base disp 4&lt;br /&gt;Copy by Ref fun:&amp;nbsp; Derived disp base &amp;amp; der vals 4 5&lt;br /&gt;Base 2&lt;br /&gt;Base 5&lt;br /&gt;Derived 5 6&lt;br /&gt;Base disp 5&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above example&lt;br /&gt;
 &lt;b&gt;b2 = d2 &lt;/b&gt;and &lt;b&gt;copyByVal(d);&lt;/b&gt;&amp;nbsp; statements copied only part of the base members (sliced away derived members) to derived object from derived object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/5896071713092906722/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2016/07/object-slicing-in-c-with-example.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/5896071713092906722'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/5896071713092906722'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2016/07/object-slicing-in-c-with-example.html' title='Object Slicing in C++ with example'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</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-4690837514005213557.post-101457388162317964</id><published>2016-06-08T20:54:00.000+05:30</published><updated>2016-06-11T00:02:45.035+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="My Sql"/><category scheme="http://www.blogger.com/atom/ns#" term="RDMS"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql queries"/><title type='text'>Some Useful My Sql Queries for beginners</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;head&gt;
&lt;script async=&quot;&quot; src=&quot;https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
  (adsbygoogle = window.adsbygoogle || []).push({
    google_ad_client: &quot;ca-pub-2098074799369613&quot;,
    enable_page_level_ads: true
  });
&lt;/script&gt;
&lt;/head&gt;

&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
My Sql is a popularly used Relational Database Management System.&amp;nbsp; Database is used store and retrieve data efficiently with the proven algorithms. Here i&#39;m providing some sql commands which are useful for beginners in my sql queries.&lt;br /&gt;
&lt;br /&gt;
Here information_schema is the default database comes with Mysql installation.&lt;br /&gt;
&lt;br /&gt;
&amp;gt;To check the engine used for the table - mytable&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES WHERE TABLE_NAME=&#39;mytable&#39; AND TABLE_SCHEMA=&#39;mydatabase&#39;;&lt;/blockquote&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&amp;gt;To see the database create statement&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
SHOW CREATE DATABASE mydatabase;&lt;/blockquote&gt;
&lt;br /&gt;
&amp;gt;TO see the current database name&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
SELECT DATABASE();&lt;/blockquote&gt;
&lt;br /&gt;
&amp;gt;To see the table structure (create table statement)&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
SHOW CREATE TABLE mydatabase.mytable;&lt;/blockquote&gt;
&lt;br /&gt;
&amp;gt; Describes the all the columns and datatypes for the table&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
DESCRIBE mytable (or) DESC mytable;&lt;/blockquote&gt;
&lt;br /&gt;
&amp;gt;To see the warnings of the previous command&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
SHOW WARNINGS;&lt;/blockquote&gt;
&amp;gt;To concatenate (Combine) and show the column vaues&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
SELECT CONCAT(firstname, &#39; . &#39;, lastname) AS `Full Name`, marks FROM mytable; &lt;/blockquote&gt;
&lt;br /&gt;
&amp;gt;To Select rows in random order every time&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
SELECT * FROM mytable ORDER BY RAND();&lt;/blockquote&gt;
&lt;br /&gt;
&amp;gt;&amp;nbsp; To retrieve multiple rows with the given values, for example to fetch 3 records data with column &quot;uid&quot; values as 5,6,8&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
SELECT * FROM mytable WHERE uid IN (5,6,8);&lt;/blockquote&gt;
&lt;br /&gt;
&amp;gt; To get summary report for the groups use GROUP BY aggregate functions(COUNT, MIN, MAX, AVG, SUM...) on the groups, for example to get the total number of students for each branch &lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
SELECT COUNT(*) from mytable GROUP BY branchname;&lt;/blockquote&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;To get the average marks in subject-wise&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp;SELECT AVG(marks) from classtable GROUP BY subjectname;&lt;/blockquote&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;To get the sum of the items in the stock&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp;SELECT SUM(items) from stock GROUP BY itemname;&lt;/blockquote&gt;
&lt;br /&gt;
&amp;gt;To combine the results of two or more tables(identical) use UNION, for example to get the highest marks in the particular subject from class9table, class10table&lt;br /&gt;
&lt;br /&gt;
SELECT MAX(science) FROM (SELECT MAX(science) from class9table UNION SELECT MAX(science) from class10table) as t1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/101457388162317964/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2016/06/some-useful-my-sql-queries.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/101457388162317964'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/101457388162317964'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2016/06/some-useful-my-sql-queries.html' title='Some Useful My Sql Queries for beginners'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</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-4690837514005213557.post-4211535258047116577</id><published>2016-05-26T21:27:00.001+05:30</published><updated>2016-05-26T21:27:34.616+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Maria DB"/><category scheme="http://www.blogger.com/atom/ns#" term="Maria DB Storage Engines"/><category scheme="http://www.blogger.com/atom/ns#" term="My Sql"/><title type='text'>Maria DB Storage Engines and Alogorithms used for Indexing</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;head&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
  (adsbygoogle = window.adsbygoogle || []).push({
    google_ad_client: &quot;ca-pub-2098074799369613&quot;,
    enable_page_level_ads: true
  });
&lt;/script&gt;
&lt;/head&gt;

&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Maria DB is a Open source database and is a replacement for My SQL data base after My Sql (Sun Micro Systems) has been acquired by Oracle.&lt;br /&gt;
&lt;br /&gt;
Database can have multiple tables and each table will use one storage engine, and we can use different storage engines for different tables in the database.&lt;br /&gt;
&lt;br /&gt;
In this article i&#39;m discussing about the storage engines of Maria DB. There are many storage engines that supports Maria DB, and these are pluggable engines.&lt;br /&gt;
&lt;br /&gt;
To see the available storage engines in maria db, execute the following query&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; show storage engines;&amp;nbsp; (or)&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
MariaDB [(none)]&amp;gt; show engines;&lt;/blockquote&gt;
And for all these storage differ from one another with the following properties..&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&amp;gt;Storage, indexes, data types, transactions(for data reliability), locking level(concurrent access), caching, memory usage ...&lt;br /&gt;
&lt;br /&gt;
Here i&#39;m providing the some of the Maria DB engines and their details..&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: orange;&quot;&gt;&lt;b&gt;1. Inno DB&lt;/b&gt;&lt;/span&gt;:&lt;br /&gt;
&amp;gt;This is the default storage engine for the Maria DB&lt;br /&gt;
&amp;gt;Transaction Safe : means automatic recovery, backup, rollback can be executed&lt;br /&gt;
&amp;gt;Memory caching&lt;br /&gt;
&amp;gt;Supports Row level locking &lt;br /&gt;
&amp;gt;Indexes are B-Tree data structures (R-Trees data structure for spatial indexes)&lt;br /&gt;
&amp;gt;adaptive Hash indexes (fastest way to perform querying)&lt;br /&gt;
&amp;gt;Crash recovery &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: orange;&quot;&gt;&lt;b&gt;2.MyISAM&lt;/b&gt;&lt;/span&gt;:&lt;br /&gt;
&amp;gt;Execellent &lt;b&gt;INSERT &lt;/b&gt;performance. &lt;br /&gt;
&amp;gt;Non-transaction safe&lt;br /&gt;
&amp;gt;No foreign key support&lt;br /&gt;
&amp;gt;Usage : logging&lt;br /&gt;
&amp;gt;This default storage engine in Mysql from v3.23 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: orange;&quot;&gt;&lt;b&gt;3.MEMORY&lt;/b&gt;&lt;/span&gt;:&lt;br /&gt;
&amp;gt;Hash indexes &lt;br /&gt;
&amp;gt;Indexes are Red-black binary tree data structures&lt;br /&gt;
&amp;gt;Not support BLOB, TEXT&amp;nbsp; data types&lt;br /&gt;
&amp;gt;Excellent &lt;b&gt;INSERT&lt;/b&gt; and &lt;b&gt;SELECT&lt;/b&gt; query performance&lt;br /&gt;
&amp;gt;Data stored in RAM rather than disk (the tables will empty after system restart)&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: orange;&quot;&gt;&lt;b&gt;4.ARCHIVE&lt;/b&gt;&lt;/span&gt;:&lt;br /&gt;
&amp;gt;Stores large amounts of data by compressing it&lt;br /&gt;
&amp;gt;Select and INSERT operations only &lt;br /&gt;
&amp;gt;No indexes &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: orange;&quot;&gt;&lt;b&gt;5.CSV&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&amp;gt;No indexes&lt;br /&gt;
&amp;gt;Not supports transactions&lt;br /&gt;
&amp;gt;Columns must be declared as Not NULL&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: orange;&quot;&gt;&lt;b&gt;6.FederatedX (FEDERATED)&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;gt;No data is maintained in local tables.&lt;br /&gt;
&amp;gt;Used to access data from the remote tables without using clustering technology&lt;br /&gt;
&amp;gt;Querying the local FederatedX table will fetch the data from the remote table&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: orange;&quot;&gt;7.ARIA&lt;/span&gt;:&lt;/b&gt;&lt;br /&gt;
&amp;gt;Available in Maria DB only (not in Mysql) &lt;br /&gt;
&amp;gt;Good performance for quries with GROUP BY, DISTINCT as it has better caching mechanism compared to MyISAM&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: orange;&quot;&gt;8.ARCHIEVE&lt;/span&gt;:&lt;/b&gt;&lt;br /&gt;
&amp;gt;No indexes&lt;br /&gt;
&amp;gt;Used to store large amounts of data (internally it will use gzip to compress rows)&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: orange;&quot;&gt;9. CASSANDRA&lt;/span&gt;:&lt;/b&gt;&lt;br /&gt;
&amp;gt;Flexible scheme using Dynamic columns&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: orange;&quot;&gt;10.CONNECT&lt;/span&gt;:&lt;/b&gt; &lt;br /&gt;
&amp;gt;Supports Text&amp;nbsp; (CSV, INI, FMT, XML, FIX) , Binary (BIN, DBF, VEC) file format tables&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: orange;&quot;&gt;&lt;b&gt;11.OQGraph&lt;/b&gt;&lt;/span&gt;&lt;b&gt;:&lt;/b&gt;&lt;br /&gt;
&amp;gt;Transactional and crash-safe&lt;br /&gt;
&amp;gt;Uses Dijkstra&#39;s algorithm and breadth-first search&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: orange;&quot;&gt;12.Sequence&lt;/span&gt;:&lt;/b&gt;&lt;br /&gt;
&amp;gt;Virtual Read-only tables&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: orange;&quot;&gt;&lt;b&gt;13.TokuDB&lt;/b&gt;&lt;/span&gt;&lt;b&gt;:&lt;/b&gt;&lt;br /&gt;
&amp;gt;Transactional&lt;br /&gt;
&amp;gt;fast recovery&lt;br /&gt;
&amp;gt;Fractal-Tree indexexes&lt;br /&gt;
&amp;gt;faster INSERT&lt;br /&gt;
&amp;gt;saving space by comression (space saving upto 90%)&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;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/4211535258047116577/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2016/05/maria-db-storage-engines-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/4211535258047116577'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/4211535258047116577'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2016/05/maria-db-storage-engines-and.html' title='Maria DB Storage Engines and Alogorithms used for Indexing'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</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-4690837514005213557.post-8646644034290573936</id><published>2016-05-12T23:55:00.003+05:30</published><updated>2016-05-16T20:24:49.700+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="QML Examples"/><category scheme="http://www.blogger.com/atom/ns#" term="Qt C++ qmlRegisterUncreatableType() example"/><category scheme="http://www.blogger.com/atom/ns#" term="QT C++ to Qml communication"/><category scheme="http://www.blogger.com/atom/ns#" term="Qt QML"/><title type='text'>Qt C++ to Qml Communication using qmlRegisterUncreatableType()</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;head&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
  (adsbygoogle = window.adsbygoogle || []).push({
    google_ad_client: &quot;ca-pub-2098074799369613&quot;,
    enable_page_level_ads: true
  });
&lt;/script&gt;
&lt;/head&gt;

&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
In this article i will discuss about how to access the C++ class&amp;nbsp; enum types and attributes in qml file using Qt c++ qmlRegisterUncreatableType() template function.&lt;br /&gt;
&lt;br /&gt;
qmlRegisterUncreatableType() will register the c++ class type (derived from QObject) as the &lt;b&gt;non-instantiable&lt;/b&gt; type with QML type system. So we can not create object for the class in qml file, but we can use the properties ans enumerated types belongs to this class in qml file.&lt;br /&gt;
&lt;br /&gt;
To access the enum values in qml , we have to make it available to meta-object system with the following macro, Otherwise we cannot access in qml file.&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
Q_ENUMS(enumType)&lt;/blockquote&gt;
&lt;br /&gt;
To Register the c++ type with qml type system&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp;qmlRegisterUncreatableType(&quot;ModuleName/uri&quot;, MajorVersion, MinorVersion, &quot;QmlName&quot;, &quot;message&quot;);&lt;/blockquote&gt;
&lt;br /&gt;
Here i&#39;m providing the sample code to demonstrate the use of qmlRegisterUncreatableType() to access c++ class attributes and enum types.&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;b&gt;Note&lt;/b&gt;: C++ class must be QObject derived to register with qml type system&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&amp;gt;&lt;span style=&quot;color: #38761d;&quot;&gt;main.cpp&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;
#include &amp;lt;QQmlApplicationEngine&amp;gt;&lt;br /&gt;
#include &amp;lt;QtQml&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &quot;mycppclass.h&quot;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; QApplication app(argc, argv);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; MyCPPClass myCppObj;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; qmlRegisterUncreatableType&amp;lt;MyCPPClass&amp;gt;(&quot;MyModule&quot;,1,0,&quot;MyCPPClass&quot;,&quot;can not instantiate MyCPPClass in qml&quot;);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; QQmlApplicationEngine engine;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; engine.rootContext()-&amp;gt;setContextProperty(&quot;myCppObj&quot;,&amp;amp;myCppObj);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; engine.load(QUrl(QStringLiteral(&quot;qrc:/main.qml&quot;)));&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return app.exec();&lt;br /&gt;
}&lt;/blockquote&gt;
&lt;br /&gt;
&amp;gt;&lt;b&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;MyCPPClass.h&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;
#include &amp;lt;QObject&amp;gt;&lt;br /&gt;
#include &amp;lt;QString&amp;gt;&lt;br /&gt;
#include&amp;lt;QColor&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class MyCPPClass : public QObject&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Q_OBJECT&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Q_PROPERTY(QColor mycolour READ mycolour WRITE setMycolour NOTIFY mycolourChanged)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Q_PROPERTY(int num READ num WRITE setNum NOTIFY numChanged)&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Q_ENUMS(NumbersType)&lt;br /&gt;
&lt;br /&gt;
public:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; explicit MyCPPClass(QObject *parent = 0);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; QColor mycolour();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; void setMycolour(QColor clr);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; int num();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; void setNum(int n);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Q_INVOKABLE QString getClassName();&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; enum NumbersType {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ONE = 1,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TWO = 2,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; THREE = 3,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FOUR= 4,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FIVE = 5,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SIX = 6,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SEVEN =7 ,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EIGHT = 8,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Nine = 9&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;br /&gt;
&lt;br /&gt;
signals:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; void mycolourChanged();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; void numChanged();&lt;br /&gt;
&lt;br /&gt;
public slots:&lt;br /&gt;
&lt;br /&gt;
private:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; QColor m_colour;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; int m_num;&lt;br /&gt;
};&lt;/blockquote&gt;
&lt;b&gt;Note&lt;/b&gt;:To access enum types in qml file we have to start enum values with Capital letter. Ex: Nine = 9&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&lt;b&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;MyCPPClass.cpp&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
#include &quot;mycppclass.h&quot;&lt;br /&gt;
&lt;br /&gt;
MyCPPClass::MyCPPClass(QObject *parent) : QObject(parent)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
QColor MyCPPClass::mycolour()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return m_colour;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void MyCPPClass::setMycolour(QColor clr)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; m_colour = clr;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Q_EMIT mycolourChanged();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int MyCPPClass::num()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return m_num;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void MyCPPClass::setNum(int n)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; m_num = n;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Q_EMIT numChanged();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
QString MyCPPClass::getClassName()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return &quot;MyCPPClass&quot;;&lt;br /&gt;
}&lt;/blockquote&gt;
&lt;br /&gt;
and finally&lt;br /&gt;
&amp;gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;b&gt;main.qml&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;import QtQuick 2.4&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;import MyModule 1.0&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt; &lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
Rectangle {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Component.onCompleted: {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myCppObj.mycolour = &quot;red&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myCppObj.num = 300;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; height: myCppObj.num&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; width: myCppObj.num&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; color: myCppObj.mycolour&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Text {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id: name&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; text: qsTr(&quot;This is from C++ class:\t&quot;+myCppObj.getClassName()+&quot; \n enum value: &quot;+MyCPPClass.EIGHT)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/blockquote&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;&amp;nbsp;Output:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbu8TImxqSw2W6KY50n_G393ZGZur1lAPzgwpREsca5Tw_ozeBjB58hyzXXRiEf1UfX6wvdldsYvhipSDJkpG-LtEsSS_d4r2MubczfiU8yxBYq3SmOvdlm5T3CcMd2KZ-qgIHJfVrfnY/s1600/Qt+c%252B%252B+qmlRegisterUncreatableType+example.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;254&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbu8TImxqSw2W6KY50n_G393ZGZur1lAPzgwpREsca5Tw_ozeBjB58hyzXXRiEf1UfX6wvdldsYvhipSDJkpG-LtEsSS_d4r2MubczfiU8yxBYq3SmOvdlm5T3CcMd2KZ-qgIHJfVrfnY/s320/Qt+c%252B%252B+qmlRegisterUncreatableType+example.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;b&gt;&lt;br /&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/8646644034290573936/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2016/05/c-to-qt-qml-communication-using.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/8646644034290573936'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/8646644034290573936'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2016/05/c-to-qt-qml-communication-using.html' title='Qt C++ to Qml Communication using qmlRegisterUncreatableType()'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</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/AVvXsEgbu8TImxqSw2W6KY50n_G393ZGZur1lAPzgwpREsca5Tw_ozeBjB58hyzXXRiEf1UfX6wvdldsYvhipSDJkpG-LtEsSS_d4r2MubczfiU8yxBYq3SmOvdlm5T3CcMd2KZ-qgIHJfVrfnY/s72-c/Qt+c%252B%252B+qmlRegisterUncreatableType+example.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4690837514005213557.post-2134087825462525091</id><published>2016-05-07T19:57:00.000+05:30</published><updated>2016-05-07T19:57:57.970+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Bit set clear example"/><category scheme="http://www.blogger.com/atom/ns#" term="Bitwise Operators"/><category scheme="http://www.blogger.com/atom/ns#" term="Qt Programming Examples"/><title type='text'>Bit Operations: Qt Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;head&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
  (adsbygoogle = window.adsbygoogle || []).push({
    google_ad_client: &quot;ca-pub-2098074799369613&quot;,
    enable_page_level_ads: true
  });
&lt;/script&gt;
&lt;/head&gt;

&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
In this post i&#39;m going to show you some bit operations with &amp;amp;, |, &amp;lt;&amp;lt;, &amp;gt;&amp;gt;, ~ using Qt example. This example include operations like set a particular bit in the given number, clear bit, check bit is set or not and to check whether the number is even or odd.&lt;br /&gt;
&lt;br /&gt;
Following demonstrates the psuedo code of the operations. &lt;br /&gt;
&lt;br /&gt;
&amp;gt;&lt;b&gt; To Set a bit in the given number&lt;/b&gt; : perform Betwise OR (|) operation with&amp;nbsp; 1 left shift(&amp;lt;&amp;lt;) by index of the bit to set&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; num = num | (1&amp;lt;&amp;lt;index);&lt;/blockquote&gt;
&lt;br /&gt;
&amp;gt;&lt;b&gt;To clear a bit in the given number&lt;/b&gt;: perform Betwise AND (&amp;amp;) operation with the inverted(~) 1 left shift(&amp;lt;&amp;lt;) by index of the bit to clear&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; num = num &amp;amp; ~(1&amp;lt;&amp;lt;index);&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;/blockquote&gt;
&amp;gt;&lt;b&gt;To Check whether &lt;/b&gt;&lt;b&gt;&lt;b&gt;a bit is&lt;/b&gt; set or not:&lt;/b&gt; perform Betwise AND (&amp;amp;) operation between num right shift(&amp;gt;&amp;gt;) by index of the bit to check and 1 &lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
num = (num &amp;gt;&amp;gt; index) &amp;amp; 1;&lt;/blockquote&gt;
&lt;br /&gt;
&amp;gt;&lt;b&gt;To Check whether a num is even or odd&lt;/b&gt;:&amp;nbsp; perform Betwise AND (&amp;amp;) operation with&amp;nbsp; 1. If it returns 1 number is odd, if returns 0 even number&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
bool ret = (num &amp;amp; 1);&lt;/blockquote&gt;
&lt;br /&gt;
And the following code demonstrates the sample Qt application example for the above operations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;
#include &amp;lt;QCoreApplication&amp;gt;&lt;br /&gt;
#include&amp;lt;QDebug&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; QCoreApplication a(argc, argv);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; quint8 testByte = 8;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; qDebug()&amp;lt;&amp;lt;&quot;test byte: &quot;&amp;lt;&amp;lt;testByte;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; //set bit at 2nd index&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; testByte = testByte | (1&amp;lt;&amp;lt;2);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; qDebug()&amp;lt;&amp;lt;&quot;After set bit at 2nd index: &quot;&amp;lt;&amp;lt;testByte;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; //clear bit at 3rd index&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; testByte = testByte &amp;amp; ~(1&amp;lt;&amp;lt;3);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; qDebug()&amp;lt;&amp;lt;&quot;After clear bit at 3rd index: &quot;&amp;lt;&amp;lt;testByte;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; //check bit at 2nd index&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; bool isBitChecked = (testByte&amp;gt;&amp;gt;2) &amp;amp; 1;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; qDebug()&amp;lt;&amp;lt;&quot;check bit at 2nd index: &quot;&amp;lt;&amp;lt;isBitChecked;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; //to find the number is even or odd&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; qint32 num = 3;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; QString evenOdd = (num &amp;amp; 1)? &quot;Odd&quot;:&quot;Even&quot;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; qDebug()&amp;lt;&amp;lt;&quot;num 3 is : &quot;&amp;lt;&amp;lt;evenOdd;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return a.exec();&lt;br /&gt;
}&lt;/blockquote&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;b&gt;output&lt;/b&gt;&lt;/span&gt;:&lt;br /&gt;
test byte: 8&lt;br /&gt;
After set bit at 2nd index: 12&lt;br /&gt;
After clear bit at 3rd index: 4 &lt;br /&gt;
check bit at 2nd index: true&lt;br /&gt;
num 3 is : &quot;odd&quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/2134087825462525091/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2016/05/bit-operations-qt-example.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/2134087825462525091'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/2134087825462525091'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2016/05/bit-operations-qt-example.html' title='Bit Operations: Qt Example'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</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-4690837514005213557.post-2850905793133297184</id><published>2016-05-03T22:08:00.001+05:30</published><updated>2016-05-03T22:10:19.903+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linux OS issues"/><category scheme="http://www.blogger.com/atom/ns#" term="Qt Creator"/><category scheme="http://www.blogger.com/atom/ns#" term="Qt issues"/><title type='text'>&#39;Cannot find -lGL&#39; error while building the Qt widget application in Linux OS?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;head&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
  (adsbygoogle = window.adsbygoogle || []).push({
    google_ad_client: &quot;ca-pub-2098074799369613&quot;,
    enable_page_level_ads: true
  });
&lt;/script&gt;
&lt;/head&gt;

&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hi all,&lt;br /&gt;
&lt;br /&gt;
Did any one get &quot;Cannot find -lGL&quot; error while building the Qt widget application in Ubuntu operating system? Qt installer provides compiler, debugger, make and other tools for the development. But when you want to develop Qt graphical based application it requires Open GL libraries.&lt;br /&gt;
&lt;br /&gt;
Most of the Linux OS will not provide Open GL libraries as default. To continue building Qt graphical applications just install this libraries.&lt;br /&gt;
&lt;br /&gt;
For Ubuntu use the following command&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
$sudo apt-get install build-essential libgl1-mesa-dev&lt;/blockquote&gt;
&lt;br /&gt;
For Fedora/ RHEL&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
$sudo yum groupinstall &quot;C Development Tools and Libraries&quot;&lt;br /&gt;
&lt;br /&gt;
$sudo yum install mesa-libGL-devel&lt;/blockquote&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/2850905793133297184/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2016/05/cannot-find-lgl-error-while-building-qt.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/2850905793133297184'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/2850905793133297184'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2016/05/cannot-find-lgl-error-while-building-qt.html' title='&#39;Cannot find -lGL&#39; error while building the Qt widget application in Linux OS?'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</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-4690837514005213557.post-2064831155529967073</id><published>2013-06-28T20:56:00.000+05:30</published><updated>2013-06-28T20:56:00.276+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Anonymous Unions"/><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="C++ Unions"/><title type='text'>Anonymous Unions in C++</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Unions in C++ are special type of
classes. We can declare member functions and variables with in the
union in c++ (all &#39;C&#39; features of union remain same).&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;But in the unions
all the data members share the same memory location.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; Union members are public by default as
like structures.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Anonymous unions are the special type
unions with the no name and so we can not create object for that
union. All the member data in the anonymous unions share same memory
location. We can directly access the these members without any dot
operator with in the block where these unions declared.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; The scope of
the anonymous union members restricted to the block where it declared
and these members can be treated as the local varibles to that block,
so there shouldn&#39;t be any conflict between the names of the variables
defined with in the unions and variables defined with in the block.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;For example:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhG4uqD-dIT-Plr2nVGp-ha48XF-xRZ8RctDugESlUX_W7vFtebXWK5WkMcvWxMELg6FgJPD7ABcupP9kmh1CQeoWABolU0Rx5Smasggb37Op3jxWBs6O8kswzsUKJkaUZ8Qqh0p07zAAkZ/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; #include&amp;lt;iostream&amp;gt;  
 #include&amp;lt;cstring&amp;gt;  
 using namespace std;  
 int main()  
 {  
   union   
   {  
     int i;  
     char ch[4];  
   };  
   i = 56;  
   cout&amp;lt;&amp;lt;&quot;i val: &quot;&amp;lt;&amp;lt;i&amp;lt;&amp;lt;&quot; ch val:&quot;&amp;lt;&amp;lt;ch&amp;lt;&amp;lt;endl;  
   memcpy(ch,&quot;1&quot;,sizeof(ch));  
   cout&amp;lt;&amp;lt;&quot;i val: &quot;&amp;lt;&amp;lt;i&amp;lt;&amp;lt;&quot; ch val:&quot;&amp;lt;&amp;lt;ch&amp;lt;&amp;lt;endl;  
   return 0;  
 }  
&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre class=&quot;western&quot;&gt;&lt;/pre&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;Output&lt;/span&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;i val: 56 ch val:8 
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;i val: 49 ch val:1&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Here union member data i and ch are
having same scope as the variables declared with in the main block.
Here i and ch share the same memory location so when we set ivalue ch
value is also same. Ascii values 48 to 57 represents 0 to 9 decimal
numbers.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;Note&lt;/span&gt;: Alls the restrictions applicable
to the unions in c++ are also applicable to anonymous unions&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-2098074799369613&quot;;
/* in post */
google_ad_slot = &quot;3899060992&quot;;
google_ad_width = 468;
google_ad_height = 60;
//&lt;/script&gt;
&lt;/div&gt;
--&amp;gt;
&lt;script src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/2064831155529967073/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2013/06/anonymous-unions-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/2064831155529967073'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/2064831155529967073'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2013/06/anonymous-unions-in-c.html' title='Anonymous Unions in C++'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</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-4690837514005213557.post-2876434325824491862</id><published>2013-05-27T08:56:00.000+05:30</published><updated>2016-05-30T22:26:57.128+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Qt C++"/><category scheme="http://www.blogger.com/atom/ns#" term="Qt Programming Examples"/><category scheme="http://www.blogger.com/atom/ns#" term="Qt QML"/><title type='text'>Qt QML Introduction and Simple Example Program</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;head&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
  (adsbygoogle = window.adsbygoogle || []).push({
    google_ad_client: &quot;ca-pub-2098074799369613&quot;,
    enable_page_level_ads: true
  });
&lt;/script&gt;
&lt;/head&gt;

&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;QML is declarative language used to
develop user interface, is a part of the Qt Quick module. Qt Quick
consists of set of technologies including Qml, C++ API&#39;s for
integrating Qml with Qt application, Qt creator IDE, rum time
support.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Qt Quick module comes with the Qt with
4.7 or later versions.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Qml we use elements to draw something
on the screen(output) like text, image, rectangle etc.Every element
in the qml is like a object. We cal also implement javascript code in
side the qml file. Item is the base type for the all the elements.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;To start a Qml Application we need to
import Qt Quick module with version in the beginning of the every qml
file, because the elements we are going to use included in this
module. For example the following element displat a rectangle.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt; Import QtQuick 1.0&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;pre&gt;&lt;!--StartFragment--&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: purple;&quot;&gt;Rectangle&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;id&lt;/span&gt;:&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;rect&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;width&lt;/span&gt;:&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;300&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;height&lt;/span&gt;:&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;300&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;color&lt;/span&gt;:&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;red&quot;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;}&lt;/span&gt;&lt;!--EndFragment--&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Every element will have properties
(with values) to describe it, in the above example id, width, height
and color are some properties of the rectangle. The “id” property
is used to refer the particular element inside another element. We
can put any number of elements inside another element will become
child elements.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Proprty binding is the important
feature of the qml, means we can use the expression or other
properties as the values for the property , so that it will be
updated when ever the corresponding proprty updated&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Ex: Rectangle {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;  width: 300&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;  height: width * 2&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt; }&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Here height will be updated when ever
the width changes&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The basic types for the property values
are int, real, strings, boolean values, constants, color etc&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Comments start with // same as c++
comments.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;Writing a First Qt Qml Program&lt;/span&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;To start first Qml app follow below 
&lt;/span&gt;&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Open Qt Creator&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Click on Create Project in File
 menu (File &amp;gt; New File or Project)&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Select Qt Quick Project then Qt
 Quick Application, then click choose as shown in the following image&lt;/span&gt;&amp;nbsp;&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/AVvXsEi9BO_SPWurmhIh3zmgQPsES14P0ibo4nctb9kZLpQpWIqpbvbARbMQf3Q-O1h2e-1maSyQtQCjiXkLBeY2PXHw0xxoNt-lRYiBMH3kvE1iM8N0-brFQRPJ2ZpCDFzhmGxr198V29kLkHg/s1600/Qt+Quick+Application.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;280&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9BO_SPWurmhIh3zmgQPsES14P0ibo4nctb9kZLpQpWIqpbvbARbMQf3Q-O1h2e-1maSyQtQCjiXkLBeY2PXHw0xxoNt-lRYiBMH3kvE1iM8N0-brFQRPJ2ZpCDFzhmGxr198V29kLkHg/s320/Qt+Quick+Application.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;

 &lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Give the project name and location
 then click next&lt;/span&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/AVvXsEjCc5RRA0VTFkmwNGtwlunLmTQVBA3UTitQx2Oz-BgNTXbbCSYL7K8kLEqTCEZTzKcnJGFcjQ8hCiQeiZ7eItwKd9VSgwyggyeA2ZT5aBbmk4FPpbJBrfoAwJWNc-dgOk4k0Vpg5mjAxYU/s1600/Project+Location.jpg&quot; imageanchor=&quot;1&quot; style=&quot;font-family: &#39;Times New Roman&#39;; margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;169&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCc5RRA0VTFkmwNGtwlunLmTQVBA3UTitQx2Oz-BgNTXbbCSYL7K8kLEqTCEZTzKcnJGFcjQ8hCiQeiZ7eItwKd9VSgwyggyeA2ZT5aBbmk4FPpbJBrfoAwJWNc-dgOk4k0Vpg5mjAxYU/s320/Project+Location.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Select Built-in elements only (for
 all platforms) [depending on our requirement]&lt;/span&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/AVvXsEiw6f3FrFW3gwx8q0JUz0RL3Mesdo1WN7EU-cclJhRFBKRghYpK1ZYYdNX0bl_M_UpqkJ0aHOTGlTM9vTXX6F3sWDt3HmHUkxUD8D3HnPnaIR4hxWC312oMoRvZNQPU5NISN98JwsaYY2k/s1600/Application+type.jpg&quot; imageanchor=&quot;1&quot; style=&quot;font-family: &#39;Times New Roman&#39;; margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;170&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiw6f3FrFW3gwx8q0JUz0RL3Mesdo1WN7EU-cclJhRFBKRghYpK1ZYYdNX0bl_M_UpqkJ0aHOTGlTM9vTXX6F3sWDt3HmHUkxUD8D3HnPnaIR4hxWC312oMoRvZNQPU5NISN98JwsaYY2k/s320/Application+type.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Then select the target type&lt;/span&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/AVvXsEgpEpTMv6EJAP81a7gTE-DD18MoOOWyR4nEgi-XVsuts245kZUrrVfQp7ZvHXRSWLv2IqIPRhlE2drqlfw1pIFt1ui2EcPMOw7xTU7iPaJflzUfLqb3PVWw3oLi5MiUCSlLb41dvBRiuqU/s1600/Target+Setup.jpg&quot; imageanchor=&quot;1&quot; style=&quot;font-family: &#39;Times New Roman&#39;; margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;171&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpEpTMv6EJAP81a7gTE-DD18MoOOWyR4nEgi-XVsuts245kZUrrVfQp7ZvHXRSWLv2IqIPRhlE2drqlfw1pIFt1ui2EcPMOw7xTU7iPaJflzUfLqb3PVWw3oLi5MiUCSlLb41dvBRiuqU/s320/Target+Setup.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Then Click on finish&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;Note&lt;/span&gt;: these steps may slightly change depend on the platform and Qt version
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The default main.qml will open with
some code (try executing that code), remove the code and write your
own code&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The following simple Qml program wil change between two colors on clicking on the rectangle&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;Code&lt;/span&gt;: main.qml&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;pre&gt;&lt;!--StartFragment--&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;QtQuick&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;1.0&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;to&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;target&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;S60&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;5th&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;Edition&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;or&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;Maemo&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;5&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;QtQuick&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;1.1&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: purple;&quot;&gt;Rectangle&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;id&lt;/span&gt;:&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;mainRect&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;property&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;toggle&lt;/span&gt;:&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;false&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;width&lt;/span&gt;:&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;360&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;height&lt;/span&gt;:&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;360&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;MouseArea&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;anchors.fill&lt;/span&gt;:&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;parent&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;onClicked&lt;/span&gt;:&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #0055af; font-style: italic;&quot;&gt;console&lt;/span&gt;.log(&lt;span style=&quot;color: green;&quot;&gt;&quot;parent&quot;&lt;/span&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;toggle&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;!&lt;span style=&quot;font-style: italic;&quot;&gt;toggle&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;if&lt;/span&gt;(&lt;span style=&quot;font-style: italic;&quot;&gt;toggle&lt;/span&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;mainRect&lt;/span&gt;.color&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;red&quot;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;else&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;mainRect&lt;/span&gt;.color&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;blue&quot;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;        &lt;/span&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-2098074799369613&quot;;
/* in post */
google_ad_slot = &quot;3899060992&quot;;
google_ad_width = 468;
google_ad_height = 60;
//&lt;/script&gt;

--&amp;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;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;Output&lt;/span&gt;:&lt;/span&gt;&lt;/pre&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOEPGz5QPwg1OvGpQAzWWwDm3BZWAVzVhQfcsEdppFRl6XzrBO2fyom82UmwNQL28hRBjJcIIgAsheYo0aRxO3rmE56l_0hIh6QFLwXCLqxWCwKeCVJLbmwVXYcC0YUlAe_Fo-alS4Dys/s1600/RedRectangle.png&quot; imageanchor=&quot;1&quot; style=&quot;font-family: &#39;Times New Roman&#39;; margin-left: 1em; margin-right: 1em; text-align: center; white-space: normal;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOEPGz5QPwg1OvGpQAzWWwDm3BZWAVzVhQfcsEdppFRl6XzrBO2fyom82UmwNQL28hRBjJcIIgAsheYo0aRxO3rmE56l_0hIh6QFLwXCLqxWCwKeCVJLbmwVXYcC0YUlAe_Fo-alS4Dys/s320/RedRectangle.png&quot; width=&quot;304&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;!--EndFragment--&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&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/AVvXsEgegHV9Ma-Q46f3w5Z_pov5M8OQA4BLQTNsK98P_pMOzBK_2z-bfFw2X1RA2hdkNTVRk0E9ffvCQqrTf7OkNG1eNElBydFQeLgThyErmFy-T5q4a6iJxwkaKC6aWeUDoGo0b-VCRV3ttrc/s1600/BlueRectangle.png&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/AVvXsEgegHV9Ma-Q46f3w5Z_pov5M8OQA4BLQTNsK98P_pMOzBK_2z-bfFw2X1RA2hdkNTVRk0E9ffvCQqrTf7OkNG1eNElBydFQeLgThyErmFy-T5q4a6iJxwkaKC6aWeUDoGo0b-VCRV3ttrc/s320/BlueRectangle.png&quot; width=&quot;298&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/2876434325824491862/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2013/05/qt-qml-introduction-and-simple-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/2876434325824491862'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/2876434325824491862'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2013/05/qt-qml-introduction-and-simple-example.html' title='Qt QML Introduction and Simple Example Program'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</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/AVvXsEi9BO_SPWurmhIh3zmgQPsES14P0ibo4nctb9kZLpQpWIqpbvbARbMQf3Q-O1h2e-1maSyQtQCjiXkLBeY2PXHw0xxoNt-lRYiBMH3kvE1iM8N0-brFQRPJ2ZpCDFzhmGxr198V29kLkHg/s72-c/Qt+Quick+Application.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4690837514005213557.post-1760297432545199376</id><published>2013-01-25T17:56:00.000+05:30</published><updated>2013-02-01T16:12:14.835+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="c language"/><category scheme="http://www.blogger.com/atom/ns#" term="Sizeof array in function"/><title type='text'>What is the sizeof array type when passed as a function argument?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sizeof() operator is used to find out
the no. of memory bytes occupied by any datatype i.e. it will
calculate the size of the given datatype. So if we pass a variable
called i of type int, it will give output as 4 bytes, or if we pass a array type
say arr which contains declaration as int arr[10] , it will give  40
as output.&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;We generally use sizeof() operator on
array type to find out the number of elements an array contain by
dividing the sizeof array by oth element of array (or any element)..
The following program will illustrate this&lt;/span&gt;&lt;/div&gt;
&lt;pre class=&quot;western&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;western&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;main&lt;span style=&quot;color: black;&quot;&gt;()&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;arr[&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;],s;&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;s=&lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;sizeof&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(arr)/&lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;sizeof&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;arr&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;]);&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;printf&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;sizeof&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;arr&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;%d\n&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;sizeof&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(arr));&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;printf&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;no.&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;of&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;elements&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;of&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;arr&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;%d\n&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,s);&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Here the problem is what is the size of
the array type in function when we pass it as a argument. This is
something different because when we pass array as an argument, the
&lt;span style=&quot;color: red;&quot;&gt;array type decays to pointer&lt;/span&gt;. So we can&#39;t calculate the no.of
elements in the function. This is described by the following program.&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;pre class=&quot;western&quot; style=&quot;margin-bottom: 0.2in;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;western&quot; style=&quot;margin-bottom: 0.2in;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: olive;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;fun&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;arr[])&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;s,i;&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;s=&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;sizeof&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(arr)/&lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;sizeof&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;arr&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;]);&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;printf&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;fun:&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;sizeof&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;arr&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;%d\n&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;sizeof&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(arr));&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;printf&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;fun:&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;no.of&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;elements&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;%d\n&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,s);&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(i=&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;i&amp;lt;s;i++)&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;        &lt;/span&gt;printf&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;arr[%d]&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;%d\n&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,i,arr[i]);&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;
&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;main&lt;span style=&quot;color: black;&quot;&gt;()&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;arr[&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;]={&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;7&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;},s;&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;s=&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;sizeof&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(arr)/&lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;sizeof&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;arr&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;]);&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;printf&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;main:&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;sizeof&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;arr&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;%d\n&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;sizeof&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(arr));&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;printf&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;main:&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;no.of&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;elements&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;%d\n&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,s);&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;fun&lt;span style=&quot;color: black;&quot;&gt;(arr);&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;
Output&lt;/span&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;main: sizeof arr 40
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;main: no.of elements 10
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;fun: sizeof arr 4
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;fun: no.of elements 1
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;arr[0] 1
&lt;/span&gt;&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-2098074799369613&quot;;
/* DF sq */
google_ad_slot = &quot;6528285977&quot;;
google_ad_width = 300;
google_ad_height = 250;
//&lt;/script&gt;
--&amp;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;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;As the array type decays into pointer,
so its size will be size of int (4 bytes). So 4/4 which gives 1 as
the no.of elements.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;To get the no.of elements of array, we need to
pass it as an another argument to the function as below.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;western&quot; style=&quot;margin-bottom: 0.2in;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;             void&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;fun&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;arr[],&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: olive; font-family: Verdana, sans-serif;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;size&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;);&lt;/span&gt;&lt;/pre&gt;
If you like this article &lt;!-- Place this tag where you want the +1 button to render. --&gt;&lt;div class=&quot;g-plusone&quot; data-annotation=&quot;inline&quot; data-width=&quot;300&quot;&gt;
&lt;/div&gt;
&lt;!-- Place this tag after the last +1 button tag. --&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;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/1760297432545199376/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2013/01/what-is-sizeof-array-type-when-passed.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/1760297432545199376'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/1760297432545199376'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2013/01/what-is-sizeof-array-type-when-passed.html' title='What is the sizeof array type when passed as a function argument?'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</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-4690837514005213557.post-7813839088693804149</id><published>2012-12-31T20:56:00.000+05:30</published><updated>2016-05-07T20:53:10.594+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="c language"/><category scheme="http://www.blogger.com/atom/ns#" term="How to swap two variables in different methods"/><category scheme="http://www.blogger.com/atom/ns#" term="swapping algorithms"/><category scheme="http://www.blogger.com/atom/ns#" term="XOR swap"/><title type='text'>Which algorithm is efficient for swapping?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;head&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
  (adsbygoogle = window.adsbygoogle || []).push({
    google_ad_client: &quot;ca-pub-2098074799369613&quot;,
    enable_page_level_ads: true
  });
&lt;/script&gt;
&lt;/head&gt;

&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Swapping of two numbers/characters can be done by different ways. Generally all people know swapping using a temporary variable.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;In this post i will tell you how to swap two variables in 3 different ways, &amp;nbsp;and which algorithm is efficient to swap the variables.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Here all the below examples are shown in C code(executed in linux environment with gcc compiler).&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Method 1:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Swapping using a temporary variable:&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;!--StartFragment--&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;swap(&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;*,&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;*);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;main()&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;a,b;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;printf(&lt;span style=&quot;color: green;&quot;&gt;&quot;enter&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;numbers\n&quot;&lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;scanf(&lt;span style=&quot;color: green;&quot;&gt;&quot;%d&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;%d&quot;&lt;/span&gt;,&amp;amp;a,&amp;amp;b);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;printf(&lt;span style=&quot;color: green;&quot;&gt;&quot;before&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;swapping:&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;a=%d&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;b=%d\n&quot;&lt;/span&gt;,a,b);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;swap(&amp;amp;a,&amp;amp;b);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;printf(&lt;span style=&quot;color: green;&quot;&gt;&quot;After&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;swapping:&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;a=%d&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;b=%d\n&quot;&lt;/span&gt;,a,b);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;swap(&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*a&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;,&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*b)&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;temp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;temp=*a;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;*a=*b;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;*b=temp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;!--EndFragment--&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Method 2:&lt;/b&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Swapping without using a 3rd variable&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;swap(&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*a,&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*b)&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;*a&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*a&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;+&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*b;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;*b&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*a&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;-&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*b;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;*a&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*a&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;-&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*b;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;}&lt;/span&gt;&lt;!--EndFragment--&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;Method 3:&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;XOR swap&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/pre&gt;
&lt;pre&gt;&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;XORswap(&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*a,&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*b)&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;*a&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*a&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;^&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*b;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;*b&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*a&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;^&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*b;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;   &lt;/span&gt;*a&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*a&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;^&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*b;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/pre&gt;
&lt;/pre&gt;
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-2098074799369613&quot;;
/* in post */
google_ad_slot = &quot;3899060992&quot;;
google_ad_width = 468;
google_ad_height = 60;
//&lt;/script&gt;
&lt;/div&gt;
--&amp;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;pre&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Which algorithm is efficient for swapping?&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;SO, which algorithm is efficient for swapping..each algorithm has its own limitations.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;In the 2nd method if the addition of the two numbers more than the integer limt, then we can get un expected result.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt; XOR swap algorithm is doesn&#39;t give right result for the floating point swapping&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;And also XOR swapping algorithm gives you zero as result if you try to perform swapping on the two variables which contains the same address. So you need to check the address before swapping, like&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;But the XOR swap is useful in some low memory systems like microcontrollers&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;XORswap(&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*a,&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*b)&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;      if(a==b)&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;          return;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;*a&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*a&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;^&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*b;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;*b&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*a&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;^&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*b;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;*a&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*a&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;^&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*b;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;  Finally, swapping using temporary variable is effficient, as todays systems are having more memory.
&lt;/span&gt;&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
If you like this article &lt;!-- Place this tag where you want the +1 button to render. --&gt;&lt;div class=&quot;g-plusone&quot; data-annotation=&quot;inline&quot; data-width=&quot;300&quot;&gt;
&lt;/div&gt;
&lt;!-- Place this tag after the last +1 button tag. --&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;/pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/7813839088693804149/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2012/12/which-algorithm-is-efficient-for.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/7813839088693804149'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/7813839088693804149'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2012/12/which-algorithm-is-efficient-for.html' title='Which algorithm is efficient for swapping?'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</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-4690837514005213557.post-1552681307980792525</id><published>2012-12-07T17:56:00.000+05:30</published><updated>2016-05-30T22:25:16.388+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Qt C++"/><category scheme="http://www.blogger.com/atom/ns#" term="Qt Programming Examples"/><category scheme="http://www.blogger.com/atom/ns#" term="QUdpSocket examples"/><category scheme="http://www.blogger.com/atom/ns#" term="socket programming"/><title type='text'>How to write a UDP socket program in Qt</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;head&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
  (adsbygoogle = window.adsbygoogle || []).push({
    google_ad_client: &quot;ca-pub-2098074799369613&quot;,
    enable_page_level_ads: true
  });
&lt;/script&gt;
&lt;/head&gt;

&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;We have seen how to write a simple UDP socket program in C (Linux) in the &lt;a href=&quot;http://developersfactory.blogspot.in/2012/11/udp-client-server-c-program.html&quot; target=&quot;_blank&quot;&gt;earlier post&lt;/a&gt;..&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Now we are going to learn how to write a simple UDP socket program in Qt..&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;In the following example we used to send and receive data on localhost address.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;And the readyRead() signal and slot is used whenever the data receives on the given socket (i.e. socket reday for read data), the control goes to slot method.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;writeDatagram() and readDatagram() API&#39;s used for sending and receiving data on the given udp socket.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Before starting the Program to write, create a Project using following steps&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;open Qt creator&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Create Project&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Select &lt;/span&gt;&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Other Project&lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt; in Projects tab then select &lt;/span&gt;&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Qt Console Application, &lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;then click on &lt;/span&gt;&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;choose...&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Then give the Project name&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;And then click on &lt;/span&gt;&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Next&lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;, &lt;/span&gt;&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Finish&lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt; in the following dialog boxes&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Then open the &lt;b&gt;.pro&lt;/b&gt; file and write&amp;nbsp;&lt;/span&gt;QT&lt;span style=&quot;color: silver;&quot;&gt;       &lt;/span&gt;+=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;network&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;To create the cpp file Right click on the project then choose &lt;b&gt;Add new&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;u&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;myudp.h:&lt;/span&gt;&lt;/u&gt;&lt;/div&gt;
&lt;div&gt;
&lt;u&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/u&gt;&lt;/div&gt;
&lt;div&gt;
&lt;pre&gt;&lt;!--StartFragment--&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#ifndef&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;MYUDP_H&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;MYUDP_H&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;QObject&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;QUdpSocket&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;MyUDP&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;:&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QObject&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;Q_OBJECT&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;public&lt;/span&gt;:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;explicit&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;MyUDP&lt;/span&gt;(&lt;span style=&quot;color: purple;&quot;&gt;QObject&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*parent&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;WriteData();&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;signals&lt;/span&gt;:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: silver;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;slots&lt;/span&gt;:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;readReady();&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;private&lt;/span&gt;:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QUdpSocket&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*&lt;span style=&quot;color: maroon;&quot;&gt;socket&lt;/span&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: silver;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;};&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#endif&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;MYUDP_H&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: green;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: green;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;u&gt;myudp.c&lt;/u&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;pre&gt;&lt;!--StartFragment--&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;myudp.h&quot;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: purple;&quot;&gt;MyUDP&lt;/span&gt;::&lt;span style=&quot;color: purple;&quot;&gt;MyUDP&lt;/span&gt;(&lt;span style=&quot;color: purple;&quot;&gt;QObject&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*parent)&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;:&lt;/span&gt;&lt;span style=&quot;color: purple; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;QObject&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;(parent)&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;socket&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QUdpSocket&lt;/span&gt;(&lt;span style=&quot;color: olive;&quot;&gt;this&lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;socket&lt;/span&gt;-&amp;gt;bind(&lt;span style=&quot;color: purple;&quot;&gt;QHostAddress&lt;/span&gt;::&lt;span style=&quot;color: purple;&quot;&gt;LocalHost&lt;/span&gt;,&lt;span style=&quot;color: navy;&quot;&gt;5678&lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;connect(&lt;span style=&quot;color: maroon;&quot;&gt;socket&lt;/span&gt;,&lt;span style=&quot;color: olive;&quot;&gt;SIGNAL&lt;/span&gt;(readyRead()),&lt;span style=&quot;color: olive;&quot;&gt;this&lt;/span&gt;,&lt;span style=&quot;color: olive;&quot;&gt;SLOT&lt;/span&gt;(readReady()));&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;MyUDP&lt;/span&gt;::WriteData()&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QByteArray&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;msg;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;msg.append(&lt;span style=&quot;color: green;&quot;&gt;&quot;Hello!!!&quot;&lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;socket&lt;/span&gt;-&amp;gt;writeDatagram(msg,&lt;span style=&quot;color: purple;&quot;&gt;QHostAddress&lt;/span&gt;::&lt;span style=&quot;color: purple;&quot;&gt;LocalHost&lt;/span&gt;,&lt;span style=&quot;color: navy;&quot;&gt;5678&lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;MyUDP&lt;/span&gt;::readReady()&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QByteArray&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;buffer;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;buffer.resize(&lt;span style=&quot;color: maroon;&quot;&gt;socket&lt;/span&gt;-&amp;gt;pendingDatagramSize());&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QHostAddress&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;sender;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;quint16&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;port;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;socket&lt;/span&gt;-&amp;gt;readDatagram(buffer.data(),buffer.size(),&amp;amp;sender,&amp;amp;port);&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;qDebug()&amp;lt;&amp;lt;&lt;span style=&quot;color: green;&quot;&gt;&quot;Message&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;From:&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&amp;lt;&amp;lt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;sender.toString();&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;qDebug()&amp;lt;&amp;lt;&lt;span style=&quot;color: green;&quot;&gt;&quot;With&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;Port&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;Number&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&amp;lt;&amp;lt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;port;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;qDebug()&amp;lt;&amp;lt;&lt;span style=&quot;color: green;&quot;&gt;&quot;Message:&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&amp;lt;&amp;lt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;buffer;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;u style=&quot;color: red; font-family: Verdana, sans-serif;&quot;&gt;main.c&lt;/u&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;QtCore/QCoreApplication&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;myudp.h&quot;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;main(&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;argc,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*argv[])&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QCoreApplication&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;a(argc,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;argv);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;MyUDP&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;client;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;client.WriteData();&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;a.exec();&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;--&amp;gt;&lt;/pre&gt;
&lt;/pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;pre&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEik8cp3QozE37ECaAEO0AIgKPD-8KRVHrxaLumy00x0cSpsoGrBo1XBGOjU92BAFX1MakSGiJKVQrSq463tPaJcBCCh-zAn761210HDLIfTJWr_8ncMFTBnS2auvI5FMIYBPxk6zQV3buU/s1600/UDP+socket+example+Program+in+Qt.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;227&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEik8cp3QozE37ECaAEO0AIgKPD-8KRVHrxaLumy00x0cSpsoGrBo1XBGOjU92BAFX1MakSGiJKVQrSq463tPaJcBCCh-zAn761210HDLIfTJWr_8ncMFTBnS2auvI5FMIYBPxk6zQV3buU/s320/UDP+socket+example+Program+in+Qt.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;&lt;!--EndFragment--&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;!--EndFragment--&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;!--EndFragment--&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/1552681307980792525/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2012/12/how-to-write-udp-socket-program-in-qt.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/1552681307980792525'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/1552681307980792525'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2012/12/how-to-write-udp-socket-program-in-qt.html' title='How to write a UDP socket program in Qt'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</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/AVvXsEik8cp3QozE37ECaAEO0AIgKPD-8KRVHrxaLumy00x0cSpsoGrBo1XBGOjU92BAFX1MakSGiJKVQrSq463tPaJcBCCh-zAn761210HDLIfTJWr_8ncMFTBnS2auvI5FMIYBPxk6zQV3buU/s72-c/UDP+socket+example+Program+in+Qt.jpg" height="72" width="72"/><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4690837514005213557.post-3582031233522742872</id><published>2012-11-26T17:08:00.000+05:30</published><updated>2016-05-07T20:53:28.282+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linux Shell Scripting"/><category scheme="http://www.blogger.com/atom/ns#" term="Shell script to add two numbers"/><category scheme="http://www.blogger.com/atom/ns#" term="Shell Scripting"/><category scheme="http://www.blogger.com/atom/ns#" term="Unix Shell Scripting"/><title type='text'>Linux Shell scripting basics and Simple example to add two numbers</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;head&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
  (adsbygoogle = window.adsbygoogle || []).push({
    google_ad_client: &quot;ca-pub-2098074799369613&quot;,
    enable_page_level_ads: true
  });
&lt;/script&gt;
&lt;/head&gt;

&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Shell scripting is a file which
contains the list of commands for executing. What is Shell? Shell is
special program or application provided for the user interaction.&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;There are different kinds of shells in
Unix/Linux, they are&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Sh: Bourne Shell&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Csh: C Shell&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Ksh: Korn Shell&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Bash: Bourne again Shell.. etc&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Some of the advantages of the shell
scripting are,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Automation of tasks such as backups,log
monitoring etc&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;To do repetition of of tasks&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Save lots of time..&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Unix/Linux Shell scripting also
containg the functions, control statements,loops like other
programming languages C, C++...&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;To create a variable, we use the
following syntax,&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;variablename=value&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;Note&lt;/span&gt;: there is no semicolon(;) at the end of each line like other languages&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;variable name can contain alphabet,
digits.Remember Spaces and special characters are not allowed except
underscore( _ )  like in other programming languages C,C++.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Comments in the shell script are start with &lt;b&gt;#&lt;/b&gt; symbol&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;To retrieve the value of a variable use &lt;b&gt;$&lt;/b&gt; symbol&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;To do arithmetic operations use &lt;b&gt;((&lt;/b&gt;expression&lt;b&gt;))&lt;/b&gt; syntax&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;To start shell scripting program, we need any text editor like vi, vim etc. 
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Here is the simple Linux Shell
Scripting program.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;u&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/u&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;u&gt;&lt;span style=&quot;color: red;&quot;&gt;firstscript.sh:&lt;/span&gt;&lt;/u&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;u&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/u&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;pre&gt;&lt;!--StartFragment--&gt;&lt;span style=&quot;color: green;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;#!/bin/bash&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;variable&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;declaration&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;str=&lt;span style=&quot;color: green;&quot;&gt;&quot;Hello&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;World&quot;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;#echo&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;command&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;used&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;to&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;display&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;text&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: #880088;&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;&lt;/span&gt;$str&lt;span style=&quot;color: green;&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: #880088;&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;From&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;DevelopersFactory&quot;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;!--EndFragment--&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;To execute the shell script we should
use any of the following methods,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: red; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;First Method&lt;/span&gt;&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Give executable permissions to the
 file&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $chmod 0755 filename&lt;/span&gt;&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Then execute it&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $./filename&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;2nd Method&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;$sh filename &lt;span style=&quot;color: red;&quot;&gt;or&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$bash filename&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Output&lt;/span&gt;&lt;/b&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;$chmod 0755 firstscript.sh&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;$./firstscript.sh&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;Hello World&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;From DevelopersFactory&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-2098074799369613&quot;;
/* in post */
google_ad_slot = &quot;3899060992&quot;;
google_ad_width = 468;
google_ad_height = 60;
//&lt;/script&gt;
&lt;/div&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;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The following code snippet will describe arithmetic operations in shell script&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;pre&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt; &lt;u&gt;add.sh:&lt;/u&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;u&gt;
&lt;/u&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;!--StartFragment--&gt;&lt;span style=&quot;color: green;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;#!/bin/bash&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;sum=0&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: #880088;&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;enter&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;two&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;numbers&quot;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: #880088;&quot;&gt;read&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;a&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: #880088;&quot;&gt;read&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;b&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;#we&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;can&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;of&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;the&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;following&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;sum=$(($a+$b))&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;#sum=`expr&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;$a&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;$b`&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;bc&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;command&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;can&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;calucate&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;accurately&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;with&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;floating&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;point&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;#here&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;we&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;division&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;to&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;examine&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;the&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;floating&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;point&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;result&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;#echo&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;$a/$b&quot;&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;bc&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;-l;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: #880088;&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;sum&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;of&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;the&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;two&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;numbers&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;is&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;$sum&lt;span style=&quot;color: green;&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;Output&lt;/b&gt;:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;$chmod 0755 add.sh&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;$./add.sh&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;enter two numbers
3
5
sum of the two numbers is 8&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;div&gt;
&lt;span style=&quot;color: red; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;!--EndFragment--&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/3582031233522742872/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2012/11/linux-shell-scripting-basics-and-simple.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/3582031233522742872'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/3582031233522742872'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2012/11/linux-shell-scripting-basics-and-simple.html' title='Linux Shell scripting basics and Simple example to add two numbers'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</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-4690837514005213557.post-5541424725538407076</id><published>2012-11-12T20:56:00.000+05:30</published><updated>2012-11-12T22:15:03.973+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linux C Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux System Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="SIGINT example in linux"/><category scheme="http://www.blogger.com/atom/ns#" term="signal example program in linux"/><title type='text'>Signal handling in Linux using signal() call</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;signal() function in linux is used to
sets of handler for the given signal number, the handler is any of
&lt;/span&gt;&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;SIG_DFL&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;(default action) or &lt;/span&gt;&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;SIG_IGN&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;(ignore signal) or &lt;/span&gt;&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;address of&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt; user
defined function which we called &lt;/span&gt;&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;signal handler&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;syntax&lt;/span&gt;&lt;/b&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sighandler_t signal(int signum,
sighandler_t handler);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;the second parameter is the address of
the signal handler function (function pointer), which has the
following syntax&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;typedef void (*sighandler_t)(int ); 
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Here the parameter int represents the
Signal number.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Here is the simple C program which
describes the &lt;span style=&quot;color: red;&quot;&gt;SIGINT&lt;/span&gt; Signal  handling in linux&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: red; font-family: Verdana, sans-serif;&quot;&gt;&lt;u&gt;signal.c&lt;/u&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;pre&gt;&lt;!--StartFragment--&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;signal.h&amp;gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: olive; font-family: Verdana, sans-serif;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: silver; font-family: Verdana, sans-serif;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;sig_handler(&lt;/span&gt;&lt;span style=&quot;color: olive; font-family: Verdana, sans-serif;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver; font-family: Verdana, sans-serif;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;signum)&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;printf(&lt;span style=&quot;color: green;&quot;&gt;&quot;I&#39;m&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;INT_SIGNAL&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;handler:%d\n&quot;&lt;/span&gt;,signum);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;main()&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;signal(SIGINT,sig_handler);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;while&lt;/span&gt;(&lt;span style=&quot;color: navy;&quot;&gt;1&lt;/span&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;        &lt;/span&gt;printf(&lt;span style=&quot;color: green;&quot;&gt;&quot;hello&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;i&#39;m&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;main\n&quot;&lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;        &lt;/span&gt;sleep(&lt;span style=&quot;color: navy;&quot;&gt;1&lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;!--EndFragment--&gt;&lt;/pre&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-2098074799369613&quot;;
/* in post */
google_ad_slot = &quot;3899060992&quot;;
google_ad_width = 468;
google_ad_height = 60;
//&lt;/script&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;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Output&lt;/span&gt;&lt;/b&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;$gcc -o signal signal.c&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;$./signal&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: #6fa8dc; font-family: Verdana, sans-serif;&quot;&gt;hello i&#39;m in main
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: #6fa8dc; font-family: Verdana, sans-serif;&quot;&gt;hello i&#39;m in main
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: #6fa8dc; font-family: Verdana, sans-serif;&quot;&gt;^CI&#39;m in INT_SIGNAL handler:2
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: #6fa8dc; font-family: Verdana, sans-serif;&quot;&gt;hello i&#39;m in main
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: #6fa8dc; font-family: Verdana, sans-serif;&quot;&gt;hello i&#39;m in main
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: #6fa8dc; font-family: Verdana, sans-serif;&quot;&gt;hello i&#39;m in main
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: #6fa8dc; font-family: Verdana, sans-serif;&quot;&gt;^CI&#39;m in INT_SIGNAL handler:2
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: #6fa8dc; font-family: Verdana, sans-serif;&quot;&gt;hello i&#39;m in main
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: #6fa8dc; font-family: Verdana, sans-serif;&quot;&gt;hello i&#39;m in main
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: #6fa8dc; font-family: Verdana, sans-serif;&quot;&gt;^Z
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: #6fa8dc; font-family: Verdana, sans-serif;&quot;&gt;[2]+  Stopped                 ./signal&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Note&lt;/span&gt;&lt;/b&gt;: to send the SIGINT signal
to the process, use shortcut key &lt;span style=&quot;color: red;&quot;&gt;CTRL+c&lt;/span&gt;  in the keyboard while
program being executed, then our handler will invoked. To stop the
program press &lt;span style=&quot;color: red;&quot;&gt;CTRL+z&lt;/span&gt; keys.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Note&lt;/span&gt;&lt;/b&gt;: to see list of signals in
linux system open terminal, then enter the command&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$kill -l&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/5541424725538407076/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2012/11/signal-handling-in-linux-using-signal.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/5541424725538407076'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/5541424725538407076'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2012/11/signal-handling-in-linux-using-signal.html' title='Signal handling in Linux using signal() call'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4690837514005213557.post-6730230219289079916</id><published>2012-11-08T17:56:00.000+05:30</published><updated>2012-11-08T17:56:00.154+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="c language"/><category scheme="http://www.blogger.com/atom/ns#" term="gethostbyname example in c"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux C Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux System Programming"/><title type='text'>gethostbyname example in C</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;gethostbyname() function will return the host details such as hostname, aliase names of the host,type of address, and length of host address of the given hostname.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
This function will return the hostent (host entry) structure which contain the all the above details. h_addr_list[0] &amp;nbsp;field of “hostent” structure will contain struct in_addr equivalent of the host address.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;Sysntax&lt;/span&gt;:&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;struct hostent *gethostbyname(const char *name);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
Here name is any valid hostname &amp;nbsp;(or) IPV4 address in standard dot notation (or) IPV6 &amp;nbsp;address in colon or dot notation&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
Here is the simple C Program in Linux that illustrates the gethostbyname() function.&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;u style=&quot;color: red; font-family: Verdana, sans-serif;&quot;&gt;hostinfobyname.c&lt;/u&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-2098074799369613&quot;;
/* in post */
google_ad_slot = &quot;3899060992&quot;;
google_ad_width = 468;
google_ad_height = 60;
//&lt;/script&gt;
&lt;/div&gt;
&lt;/div&gt;
--&amp;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;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;


&lt;br /&gt;
&lt;pre&gt;&lt;!--StartFragment--&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;stdlib.h&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;unistd.h&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;//for&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;gethostname()&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;netinet/in.h&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;arpa/inet.h&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;inet_ntoa()&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;netdb.h&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;hostent&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;structure,&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;gethostbyname()&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;string.h&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;main(&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;argc,&lt;span style=&quot;color: olive;&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*argv[])&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*hname,**aliases,**address;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;hostent&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*hostinfo;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;in_addr&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;ipadd;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;if&lt;/span&gt;(argc&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;==&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;1&lt;/span&gt;)&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;myname[&lt;span style=&quot;color: navy;&quot;&gt;256&lt;/span&gt;];&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;  &lt;/span&gt;gethostname(myname,&lt;span style=&quot;color: navy;&quot;&gt;255&lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;  &lt;/span&gt;hname&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;myname;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;//printf(&quot;host&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;%s&quot;,hname);&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;  &lt;/span&gt;hname&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;argv[&lt;span style=&quot;color: navy;&quot;&gt;1&lt;/span&gt;];&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: silver;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: silver;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;hostinfo&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;gethostbyname(hname);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;if&lt;/span&gt;(!hostinfo)&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;  &lt;/span&gt;fprintf(stderr,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;can&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;not&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;info&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;the&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;HOST&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;%s\n&quot;&lt;/span&gt;,hname);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;  &lt;/span&gt;exit(&lt;span style=&quot;color: navy;&quot;&gt;1&lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;printf(&lt;span style=&quot;color: green;&quot;&gt;&quot;Result&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;Host&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;%s&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;\n&quot;&lt;/span&gt;,hname);&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;printf(&lt;span style=&quot;color: green;&quot;&gt;&quot;Host&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;name:&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;%s&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;\n&quot;&lt;/span&gt;,hostinfo-&amp;gt;h_name);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;printf(&lt;span style=&quot;color: green;&quot;&gt;&quot;Aliases:&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;&lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;aliases&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;hostinfo-&amp;gt;h_aliases;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;while&lt;/span&gt;(*aliases)&lt;span style=&quot;color: silver;&quot;&gt;  &lt;/span&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;  &lt;/span&gt;printf(&lt;span style=&quot;color: green;&quot;&gt;&quot;%s&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;&lt;/span&gt;,*aliases);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;  &lt;/span&gt;aliases++;&lt;span style=&quot;color: silver;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;printf(&lt;span style=&quot;color: green;&quot;&gt;&quot;\n&quot;&lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: silver;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;if&lt;/span&gt;(hostinfo-&amp;gt;h_addrtype&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;!=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;AF_INET)&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;  &lt;/span&gt;fprintf(stderr,&lt;span style=&quot;color: green;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;Not&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;IP&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;host&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;\n&quot;&lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;  &lt;/span&gt;exit(&lt;span style=&quot;color: navy;&quot;&gt;1&lt;/span&gt;);&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;printf(&lt;span style=&quot;color: green;&quot;&gt;&quot;Type:&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;%s\n&quot;&lt;/span&gt;,hostinfo-&amp;gt;h_addrtype==AF_INET?&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;AF_INET&quot;&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;:&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;AF_INET6&quot;&lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: silver;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;printf(&lt;span style=&quot;color: green;&quot;&gt;&quot;Length&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;of&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;addrs&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;bytes&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;%d&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;\n&quot;&lt;/span&gt;,hostinfo-&amp;gt;h_length);&lt;span style=&quot;color: silver;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: silver;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;printf(&lt;span style=&quot;color: green;&quot;&gt;&quot;Address&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;list:&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;&lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;address&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;hostinfo-&amp;gt;h_addr_list;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;while&lt;/span&gt;(*(address))&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;  &lt;/span&gt;printf(&lt;span style=&quot;color: green;&quot;&gt;&quot;%s&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;&lt;/span&gt;,inet_ntoa(*(&lt;span style=&quot;color: olive;&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;in_addr&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*)*address));&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;  &lt;/span&gt;address++;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;}&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;ipadd=*(&lt;span style=&quot;color: olive;&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;in_addr&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*)hostinfo-&amp;gt;h_addr_list[&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;];&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;printf(&lt;span style=&quot;color: green;&quot;&gt;&quot;\n&quot;&lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;printf(&lt;span style=&quot;color: green;&quot;&gt;&quot;IP&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;Address:&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;%s\n&quot;&lt;/span&gt;,inet_ntoa(ipadd));&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: silver;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;!--EndFragment--&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;script src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;
&lt;span style=&quot;color: red; font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;Output&lt;/b&gt;:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;$gcc -o hostinfo hostinfobyname.c&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;$./hostinfo&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
Result for Host developersFactory-LAP08&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Host name: developersFactory-LAP08&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Aliases:&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Type: AF_INET&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Length of addrs in bytes : 4&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Address list: 127.0.1.1&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;IP Address: 127.0.1.1&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/6730230219289079916/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2012/11/gethostbyname-example-in-c.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/6730230219289079916'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/6730230219289079916'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2012/11/gethostbyname-example-in-c.html' title='gethostbyname example in C'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</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-4690837514005213557.post-1810994184892623935</id><published>2012-11-03T20:56:00.000+05:30</published><updated>2012-11-05T09:00:04.922+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linux C Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux System Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="socket programming"/><title type='text'>UDP Client Server C Program</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Hii all,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;n this Post you will learn how to write a simple UDP Socket Program in C in linux to send a message to the server and server will reply you.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Unlike TCP, UDP does not have connection establishment.So there is no connet() system call in client and accept() systemcall in server.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
So the System calls in the server are&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;1.socket()&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;2.bind()&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;3.recvfrom()&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;4.sendto(&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;
and I client the system calls are&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;1.socket()&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;2.sendto()&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;3.recvfrom()&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
The simple UDP Client-Server Program is as follows&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;u&gt;udp_server.c&lt;/u&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;sys/types.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;sys/socket.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;netinet/in.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;arpa/inet.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;string.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;errno.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#define MAXSIZE 512&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#define MYPORT 5608&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
int main()&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;int sockfd,len,ret,numbytes;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;struct sockaddr_in saddr,caddr;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;char recvbuf[MAXSIZE],sendbuf[MAXSIZE];&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;sockfd = socket(AF_INET,SOCK_DGRAM,0);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if(sockfd &amp;lt; 0) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;printf(&quot;soket: %s\n&quot;,strerror(errno));&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;return -1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;saddr.sin_family = AF_INET;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;saddr.sin_port = htons(MYPORT);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;saddr.sin_addr.s_addr = INADDR_ANY;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;len = sizeof(struct sockaddr);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;ret &amp;nbsp;= bind(sockfd,(struct sockaddr *)&amp;amp;saddr,len);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if(ret == -1) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;printf(&quot;bind server: %s\n&quot;,strerror(errno));&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return -1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;while(1) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;printf(&quot;UDP Server Waiting for Client\n&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;numbytes = recvfrom(sockfd,recvbuf,sizeof(recvbuf),0,(struct sockaddr *)&amp;amp;caddr,&amp;amp;len);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if(numbytes == -1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;printf(&quot;recv error: %s\n&quot;,strerror(errno));&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;else&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;recvbuf[numbytes] = &#39;\0&#39;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;printf(&quot;Message received from client [%s :%d]:&quot;,inet_ntoa(caddr.sin_addr),ntohs(caddr.sin_port));&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;printf(&quot;%s\n&quot;,recvbuf);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;strcpy(sendbuf,&quot;hai&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;numbytes = sendto(sockfd,sendbuf,sizeof(sendbuf),0,(struct sockaddr *)&amp;amp;caddr,len);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if(numbytes == -1)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;printf(&quot;send error: %s\n&quot;,strerror(errno));&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;return 0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-2098074799369613&quot;;
/* in post */
google_ad_slot = &quot;3899060992&quot;;
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;
&lt;span style=&quot;color: red; font-family: Verdana, sans-serif;&quot;&gt;&lt;br/&gt;&lt;u&gt;udp_client.c&lt;/u&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;
&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;sys/types.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;sys/socket.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;netinet/in.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;arpa/inet.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;string.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;errno.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#define MAXSIZE 512&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#define MYPORT 5608&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#define ADDR &quot;127.0.0.1&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
int main()&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;int sockfd,len,ret,numbytes;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;struct sockaddr_in saddr;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;char sendbuf[MAXSIZE],recvbuf[MAXSIZE];&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;sockfd = socket(AF_INET,SOCK_DGRAM,0);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if(sockfd &amp;lt; 0) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;printf(&quot;soket: %s\n&quot;,strerror(errno));&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return -1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;saddr.sin_family = AF_INET;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;saddr.sin_port = htons(MYPORT);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;saddr.sin_addr.s_addr = inet_addr(ADDR);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;len = sizeof(struct sockaddr);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;strcpy(sendbuf,&quot;hello&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;numbytes = &amp;nbsp;sendto(sockfd,sendbuf,sizeof(sendbuf),0,(struct sockaddr *)&amp;amp;saddr,len);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if(numbytes == -1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;printf(&quot;Send error: %s\n&quot;,strerror(errno));&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;else&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;printf(&quot;Message %s sent Successfully to [%s :%d]:\n&quot;,sendbuf,inet_ntoa(saddr.sin_addr),ntohs(saddr.sin_port));&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;numbytes = recvfrom(sockfd,recvbuf,sizeof(recvbuf),0,(struct sockaddr*)&amp;amp;saddr,&amp;amp;len);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if(numbytes == -1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;printf(&quot;receive error: %s\n&quot;,strerror(errno));&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;else&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;printf(&quot;Data Received from server: &amp;nbsp;%s\n&quot;,recvbuf);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
return 0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;
&lt;br /&gt;
&lt;span style=&quot;color: red; font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;How to Compile and Run?&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;open two terminals and in&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red; font-family: Verdana, sans-serif;&quot;&gt;Terminal1&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                                     &lt;/span&gt;Terminal2&lt;/span&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-2098074799369613&quot;;
/* in post */
google_ad_slot = &quot;3899060992&quot;;
google_ad_width = 468;
google_ad_height = 60;
//&lt;/script&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;$gcc -o server udp_server.c&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt;             &lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;$gcc -o client udp_client.c&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;$./server&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                                      &lt;/span&gt;$./client&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;Result:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red; font-family: Verdana, sans-serif;&quot;&gt;Terminal1:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;UDP Server Waiting for Client&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Message received from client [127.0.0.1 :46342]:hello&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;UDP Server Waiting for Client&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;Terminal2:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Message hello sent Successfully to [127.0.0.1 :5608]:&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Data Received from server: &amp;nbsp;hai&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/1810994184892623935/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2012/11/udp-client-server-c-program.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/1810994184892623935'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/1810994184892623935'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2012/11/udp-client-server-c-program.html' title='UDP Client Server C Program'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</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-4690837514005213557.post-8437858013869516160</id><published>2012-10-19T21:26:00.000+05:30</published><updated>2012-10-21T00:20:34.532+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="c language"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux C Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux System Programming"/><title type='text'>C program for getting Linux system information </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;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;In most of the Linux systems we use the
command “uname”  to print the system information in the terminal.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Ex:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$uname -a&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;which gives the information about the
system such as OS name, kernel version, release,domain name etc...
Similerly we can get that information through C Programming.&lt;/span&gt;&lt;/div&gt;

&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-2098074799369613&quot;;
/* in post */
google_ad_slot = &quot;3899060992&quot;;
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;

&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Now I will let you how to print Linux
system information through C programming in Linux, by using the
structure “struct utsname”, and the system call uname() which
return 0 on success, -1 on error.. See the code snnippet given
below...&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;uname.c&lt;/span&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;sys/utsname.h&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;int main()&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;int ret;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;struct utsname buf;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;ret = uname(&amp;amp;buf);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if(!ret) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;printf(&quot;OperatingSystem name: %s\n&quot;,buf.sysname);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;printf(&quot;Node(Host) name: %s\n&quot;,buf.nodename);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;printf(&quot;Kernel Release Version: %s\n&quot;,buf.release);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;printf(&quot;OS Version: %s\n&quot;,buf.version);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;printf(&quot;Hardware: %s\n&quot;,buf.machine);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;else {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;printf(&quot;Error in the System call&quot;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return -1;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;return 0;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;
 
 
 


&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;OUTPUT&lt;/b&gt;&lt;/span&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;
&lt;/span&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;OperatingSystem name: Linux
&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
Node(Host) name: SAI-LAP
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
Kernel Release Version:
3.2.0-32-generic-pae
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
OS Version: #51-Ubuntu SMP Wed Sep 26
21:54:23 UTC 2012
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
Hardware: i686
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;Note&lt;/span&gt;: We can also access these details
through /proc/sys/kernel directory, for example&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$cat /proc/sys/kernel/ostype&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
which gives Operating system
type...similerly we can get  osrelease,hostname,version,domainname
(replace “ostype” with any of these).&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/8437858013869516160/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2012/10/c-program-for-getting-linux-system.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/8437858013869516160'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/8437858013869516160'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2012/10/c-program-for-getting-linux-system.html' title='C program for getting Linux system information '/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4690837514005213557.post-7906476141506788008</id><published>2012-10-04T06:26:00.000+05:30</published><updated>2016-05-30T22:25:45.883+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="QGraphicsScene"/><category scheme="http://www.blogger.com/atom/ns#" term="QgraphicsView examples"/><category scheme="http://www.blogger.com/atom/ns#" term="Qt C++"/><category scheme="http://www.blogger.com/atom/ns#" term="Qt Programming Examples"/><title type='text'>QGraphicsView Example Program by inheriting QGraphicsView class</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;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;In the prevoius qgraphicsview example we created the view (QgraphicsView) and placed the scene in this view.Now in this example we created a class and inherit this class from QGraphicsView class, so the class being inherited acts like view and we will set the scene for this inherited class.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Check the example program and the output below...&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;graphics.h&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;pre class=&quot;western&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: navy;&quot;&gt;#ifndef&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;GRAPHICS_H&lt;/b&gt;
&lt;span style=&quot;color: navy;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;GRAPHICS_H
&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;QtGui/QWidget&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;QGraphicsEllipseItem&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;QGraphicsScene&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;QGraphicsView&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: olive;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;graphics&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QGraphicsView&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;Q_OBJECT&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QGraphicsScene&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;scene&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QGraphicsEllipseItem&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;itm_ellipse&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QGraphicsTextItem&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;itm_txt&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QGraphicsLineItem&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;itm_line&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QGraphicsPolygonItem&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;itm_poly&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;
&lt;span style=&quot;color: olive;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;graphics&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QWidget&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;*&lt;/span&gt;parent&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;~&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;i&gt;graphics&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;();&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;};&lt;/span&gt;
&lt;span style=&quot;color: navy;&quot;&gt;#endif&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;GRAPHICS_H&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;graphics.cpp&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;pre class=&quot;western&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;graphics.h&quot;&lt;/span&gt;&lt;/b&gt;
&lt;span style=&quot;color: purple;&quot;&gt;graphics&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;graphics&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QWidget&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;*parent)&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QGraphicsView&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(parent)&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: maroon; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;scene&lt;/span&gt;&lt;span style=&quot;color: silver; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: silver; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: silver; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;QGraphicsScene&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: olive; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;);&lt;/span&gt;&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;scene&lt;/span&gt;-&amp;gt;setSceneRect(&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;-&lt;span style=&quot;color: navy;&quot;&gt;300&lt;/span&gt;,-&lt;span style=&quot;color: navy;&quot;&gt;300&lt;/span&gt;,&lt;span style=&quot;color: navy;&quot;&gt;600&lt;/span&gt;,&lt;span style=&quot;color: navy;&quot;&gt;600&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: olive; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;setScene&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;scene&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;);&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;itm_ellipse&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QGraphicsEllipseItem&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;scene&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;itm_ellipse&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;setRect&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;100.0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;100.0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;100.0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;100.0&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;itm_ellipse&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;setFlag&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QGraphicsItem&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;ItemIsMovable&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;western&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;itm_txt&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QGraphicsTextItem&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;hello&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;scene&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;itm_txt&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;setPos&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;western&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;itm_line&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QGraphicsLineItem&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;scene&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;western&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;itm_poly&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QGraphicsPolygonItem&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;scene&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QPolygonF&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;poly;&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;poly&amp;lt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QPoint&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&amp;lt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QPoint&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;200&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&amp;lt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QPoint&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;200&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;200&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&amp;lt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QPoint&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;200&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;itm_poly&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;setPolygon&lt;span style=&quot;color: black;&quot;&gt;(poly);&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;western&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;color: purple;&quot;&gt;graphics&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;::~&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;i&gt;graphics&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;()&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;main.cpp&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;pre class=&quot;western&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;QtGui/QApplication&amp;gt;&lt;/span&gt;&lt;/b&gt;
&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;graphics.h&quot;&lt;/span&gt;
&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;main&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;argc,&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;*argv[])&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QApplication&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;a(argc,&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;argv);&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;graphics&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;w;&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;w.&lt;/span&gt;show&lt;span style=&quot;color: black;&quot;&gt;();&lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;
&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;a.&lt;/span&gt;exec&lt;span style=&quot;color: black;&quot;&gt;();&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Output:&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxsc2UBUB71j-rGpnCt1f7DvIFrDSuTU6ehqX5iGQRq_yFBRMrJa_KHnK_2DrSeaDdGiUCvhUtyaf-ZNvP2dCUMbUbSyCQeWuIN5t0elW151zrBKLqIomZq1WZqMcGDTUAzRAp6o-0btE/s1600/Qgraphics+view+example+program+with+output.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;288&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxsc2UBUB71j-rGpnCt1f7DvIFrDSuTU6ehqX5iGQRq_yFBRMrJa_KHnK_2DrSeaDdGiUCvhUtyaf-ZNvP2dCUMbUbSyCQeWuIN5t0elW151zrBKLqIomZq1WZqMcGDTUAzRAp6o-0btE/s320/Qgraphics+view+example+program+with+output.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/7906476141506788008/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2012/10/qgraphicsview-example-program-by.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/7906476141506788008'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/7906476141506788008'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2012/10/qgraphicsview-example-program-by.html' title='QGraphicsView Example Program by inheriting QGraphicsView class'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</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/AVvXsEjxsc2UBUB71j-rGpnCt1f7DvIFrDSuTU6ehqX5iGQRq_yFBRMrJa_KHnK_2DrSeaDdGiUCvhUtyaf-ZNvP2dCUMbUbSyCQeWuIN5t0elW151zrBKLqIomZq1WZqMcGDTUAzRAp6o-0btE/s72-c/Qgraphics+view+example+program+with+output.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4690837514005213557.post-6674858553127924547</id><published>2012-10-01T05:38:00.000+05:30</published><updated>2016-05-30T22:26:06.716+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="QGraphicsScene"/><category scheme="http://www.blogger.com/atom/ns#" term="QgraphicsView examples"/><category scheme="http://www.blogger.com/atom/ns#" term="Qt C++"/><category scheme="http://www.blogger.com/atom/ns#" term="Qt Programming Examples"/><title type='text'>QgraphicsView simple example program</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;head&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
  (adsbygoogle = window.adsbygoogle || []).push({
    google_ad_client: &quot;ca-pub-2098074799369613&quot;,
    enable_page_level_ads: true
  });
&lt;/script&gt;
&lt;/head&gt;

&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Here is a simple QgraphicsView example program in &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Qt.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;In this example we created a scene (QGraphicsScene) and placed all the items  in this scene by specifying the scene object while creating the graphics item.Andat last we created the view (QGraphicsView) and scene is placed in this view by using setScene() method of QgraphicsView.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;!--StartFragment--&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;QtGui/QApplication&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;QGraphicsView&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;QGraphicsScene&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;QGraphicsSimpleTextItem&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;QGraphicsRectItem&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;QGraphicsEllipseItem&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;QVector&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&amp;lt;QGraphicsPolygonItem&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;main(&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;argc,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;**argv&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QApplication&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;app(&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;argc,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;argv&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QGraphicsScene&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;scene(&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QRect&lt;/span&gt;(&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;-&lt;span style=&quot;color: navy;&quot;&gt;100&lt;/span&gt;,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;-&lt;span style=&quot;color: navy;&quot;&gt;100&lt;/span&gt;,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;400&lt;/span&gt;,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;400&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;)&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;scene.setBackgroundBrush(&lt;span style=&quot;color: purple;&quot;&gt;Qt&lt;/span&gt;::&lt;span style=&quot;color: purple;&quot;&gt;cyan&lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QGraphicsSimpleTextItem&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*textItem&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QGraphicsSimpleTextItem&lt;/span&gt;(&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;technoyouth10&quot;&lt;/span&gt;,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&amp;amp;scene&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;textItem-&amp;gt;setPos(&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;-&lt;span style=&quot;color: navy;&quot;&gt;50&lt;/span&gt;,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;-&lt;span style=&quot;color: navy;&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;textItem-&amp;gt;setFlag(&lt;span style=&quot;color: purple;&quot;&gt;QGraphicsItem&lt;/span&gt;::&lt;span style=&quot;color: purple;&quot;&gt;ItemIsMovable&lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QGraphicsRectItem&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*rectItem&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QGraphicsRectItem&lt;/span&gt;(&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QRect&lt;/span&gt;(&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;-&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;200&lt;/span&gt;,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;40&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;),&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&amp;amp;scene&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;rectItem-&amp;gt;setPen(&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QPen&lt;/span&gt;(&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;Qt&lt;/span&gt;::&lt;span style=&quot;color: purple;&quot;&gt;red&lt;/span&gt;,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;3&lt;/span&gt;,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;Qt&lt;/span&gt;::&lt;span style=&quot;color: purple;&quot;&gt;DashDotLine&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;)&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;rectItem-&amp;gt;setBrush(&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;Qt&lt;/span&gt;::&lt;span style=&quot;color: purple;&quot;&gt;green&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QGraphicsEllipseItem&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*ellipseItem&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QGraphicsEllipseItem&lt;/span&gt;(&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QRect&lt;/span&gt;(&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;80&lt;/span&gt;,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;-&lt;span style=&quot;color: navy;&quot;&gt;80&lt;/span&gt;,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;100&lt;/span&gt;,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;75&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;),&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&amp;amp;scene&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;ellipseItem-&amp;gt;setPen(&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QPen&lt;/span&gt;(&lt;span style=&quot;color: purple;&quot;&gt;Qt&lt;/span&gt;::&lt;span style=&quot;color: purple;&quot;&gt;yellow&lt;/span&gt;)&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;ellipseItem-&amp;gt;setBrush(&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;Qt&lt;/span&gt;::&lt;span style=&quot;color: purple;&quot;&gt;magenta&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QVector&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: purple;&quot;&gt;QPointF&lt;/span&gt;&amp;gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;points;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;points&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&amp;lt;&amp;lt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QPointF&lt;/span&gt;(&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;20&lt;/span&gt;,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;)&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&amp;lt;&amp;lt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QPointF&lt;/span&gt;(&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;80&lt;/span&gt;,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;)&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&amp;lt;&amp;lt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QPointF&lt;/span&gt;(&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;110&lt;/span&gt;,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;80&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;           &lt;/span&gt;&amp;lt;&amp;lt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QPointF&lt;/span&gt;(&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;50&lt;/span&gt;,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;130&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;)&amp;lt;&amp;lt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QPointF&lt;/span&gt;(&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;-&lt;span style=&quot;color: navy;&quot;&gt;10&lt;/span&gt;,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;80&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;)&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QGraphicsPolygonItem&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;*polygonItem&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QGraphicsPolygonItem&lt;/span&gt;(&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QPolygonF&lt;/span&gt;(&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;points&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;),&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;,&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&amp;amp;scene&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;polygonItem-&amp;gt;setPen(&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QPen&lt;/span&gt;(&lt;span style=&quot;color: purple;&quot;&gt;Qt&lt;/span&gt;::&lt;span style=&quot;color: purple;&quot;&gt;red&lt;/span&gt;)&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;polygonItem-&amp;gt;setBrush(&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;Qt&lt;/span&gt;::&lt;span style=&quot;color: purple;&quot;&gt;yellow&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;QGraphicsView&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;view;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;view.setScene(&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;&amp;amp;scene&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;view.show();&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: silver;&quot;&gt; &lt;/span&gt;app.exec();&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Output&lt;/span&gt;&lt;/b&gt;:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Run the program by pressing Ctrl+r...&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkpOKBb_gL_pkkK5LwXTWB3iwwVurs774sRfRynFOGXIo0eoBSz6bTP5f693YA5SMkTVd6gzMEULirPnWuLrdAQY5_ZxaM5sO-1Q4K_Du4vxJ8ntu7UrGNkDMCe04i5ftdTeFJHiakkNY/s1600/Simple+graphics+View+Example+in+Qt.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/AVvXsEgkpOKBb_gL_pkkK5LwXTWB3iwwVurs774sRfRynFOGXIo0eoBSz6bTP5f693YA5SMkTVd6gzMEULirPnWuLrdAQY5_ZxaM5sO-1Q4K_Du4vxJ8ntu7UrGNkDMCe04i5ftdTeFJHiakkNY/s320/Simple+graphics+View+Example+in+Qt.jpg&quot; width=&quot;299&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;!--EndFragment--&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/6674858553127924547/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2012/09/qgraphicsview-simple-example-program.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/6674858553127924547'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/6674858553127924547'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2012/09/qgraphicsview-simple-example-program.html' title='QgraphicsView simple example program'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</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/AVvXsEgkpOKBb_gL_pkkK5LwXTWB3iwwVurs774sRfRynFOGXIo0eoBSz6bTP5f693YA5SMkTVd6gzMEULirPnWuLrdAQY5_ZxaM5sO-1Q4K_Du4vxJ8ntu7UrGNkDMCe04i5ftdTeFJHiakkNY/s72-c/Simple+graphics+View+Example+in+Qt.jpg" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4690837514005213557.post-392716296514929007</id><published>2012-08-18T06:26:00.012+05:30</published><updated>2012-11-21T08:56:57.174+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Network Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="socket programming"/><title type='text'>TCP Daytime client Program using C in linux</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;This is the client program to get the time and date. Daytime server is the server program which is provided by the linux, and it has a specific name in the system i.e. &quot;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;daytime&lt;/span&gt;&lt;/b&gt;&quot;.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt; &lt;br /&gt;
&lt;div style=&quot;text-align: right;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;daytimecli.c&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;stdlib.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;unistd.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;sys/socket.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;netinet/in.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;netdb.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;int main(int argc,char *argv[])&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int sockfd,len,ret;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct sockaddr_in saddr;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char *hname,buff[256];&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct hostent *hostinfo;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct servent *servinfo;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if(argc == 1)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; hname = &quot;localhost&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; hname = argv[1];&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; hostinfo = gethostbyname(hname);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(!hostinfo) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; fprintf(stderr,&quot;No host: %s\n &quot;,hname);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; exit(1);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; servinfo = getservbyname(&quot;daytime&quot;,&quot;tcp&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(!servinfo) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; fprintf(stderr,&quot;No day time server \n&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; exit(1);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;Day time server Port: %d\n&quot;, ntohs(servinfo-&amp;gt;s_port));&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // creating tcp socket&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sockfd = socket(AF_INET,SOCK_STREAM,0);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; saddr.sin_family = AF_INET;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; saddr.sin_port = servinfo-&amp;gt;s_port;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; saddr.sin_addr = *(struct in_addr *) *(hostinfo-&amp;gt;h_addr_list);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; len = sizeof(saddr);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ret = connect(sockfd,(struct sockaddr *)&amp;amp;saddr,len);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(ret == -1) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; perror(&quot;connect &quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; exit(1);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ret = read(sockfd,buff,sizeof(buff));&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; buff[ret] = &#39;\0&#39;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;Result: %s and %d bytes read\n&quot;,buff,ret);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; close(sockfd);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;return 0;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt; &lt;br /&gt;
&lt;div style=&quot;color: red;&quot;&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt; &lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #274e13;&quot;&gt;$gcc -o daytimecli daytimecli.c&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #274e13;&quot;&gt;$./daytimecli&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;color: blue;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;o/p&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Day time server Port: 13&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;connect : Connection refused&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;You may get output like this, because your daytime server port is not in active state to receive request. To get enable daytime server port on &lt;/span&gt;&lt;a href=&quot;http://technoyouth10.blogspot.com/2012/07/how-to-enableopen-daytime-service-port.html&quot; target=&quot;_blank&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Click Here&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt; and follow procedure.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;The Output will be as after enable daytime server&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #274e13;&quot;&gt;$gcc -o daytimecli daytimecli.c&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #274e13;&quot;&gt;$./daytimecli&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;o/p &lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Day time server Port: 13&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Result: 17 AUG 2012 17:56:08 IST&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;and 26 bytes read&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt; &lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/392716296514929007/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2012/08/tcp-daytime-client-program-using-c-in.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/392716296514929007'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/392716296514929007'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2012/08/tcp-daytime-client-program-using-c-in.html' title='TCP Daytime client Program using C in linux'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</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-4690837514005213557.post-5474737497115656242</id><published>2012-08-02T21:52:00.000+05:30</published><updated>2012-08-02T21:52:52.706+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="socket programming"/><title type='text'>Simple Client-Server network Program using TCP/IP stream sockets</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;color: red;&quot;&gt;&lt;style type=&quot;text/css&quot;&gt;
 &lt;!--
  @page { margin: 0.79in }
  P { margin-bottom: 0.08in }
 --&gt;
 
&lt;/style&gt;   &lt;br /&gt;
&lt;div style=&quot;color: black; margin-bottom: 0in;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;This is a simple socket program, in which client sends a message to the server and server replies to the client. The server is waiting for the client process connections.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: black; margin-bottom: 0in;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;color: red;&quot;&gt;&lt;u&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Server Program:&lt;/span&gt;&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;server.c&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;sys/types.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;sys/socket.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;netinet/in.h&amp;gt; // for networkbyte order (htons(),htonl())&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;arpa/inet.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;string.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;unistd.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;int main()&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct sockaddr_in saddr,caddr;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int len,listenfd,sessfd,ret,retb;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char buff[10]={0};&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; listenfd = socket(AF_INET,SOCK_STREAM,0);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(listenfd == -1) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; perror(&quot;socket &quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; return -1;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; saddr.sin_family = AF_INET;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; saddr.sin_addr.s_addr = inet_addr(&quot;127.0.0.1&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; saddr.sin_port = htons(5678);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; len = sizeof(saddr);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; retb=bind(listenfd,(struct sockaddr *) &amp;amp;saddr, len);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(retb == -1) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; perror(&quot;bind &quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; return -1;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; listen(listenfd,5);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while(1) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;Server Waiting...\n&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; sessfd = accept(listenfd,(struct sockaddr *)&amp;amp;caddr,&amp;amp;len);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if( sessfd&amp;lt; 0 ) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; perror(&quot;accept: &quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; return -1;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; read(sessfd,&amp;amp;buff,sizeof(buff));&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;server read: %s \n&quot;,buff);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; memset(buff,&#39;\0&#39;,sizeof(buff));&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; strcpy(buff,&quot;hai user&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; write(sessfd,&amp;amp;buff,sizeof(buff));&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; close(sessfd);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; close(listenfd);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;return 0;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;color: red;&quot;&gt;&lt;u&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Client Program:&lt;/span&gt;&lt;/b&gt;&lt;/u&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;b&gt;client.c&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;sys/types.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;sys/socket.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;netinet/in.h&amp;gt; // for networkbyte order (htons(),htonl())&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;arpa/inet.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;string.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#include&amp;lt;unistd.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;int main()&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct sockaddr_in saddr;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int len,sockfd,ret;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char buff[10]=&quot;hello&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sockfd = socket(AF_INET,SOCK_STREAM,0);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(sockfd == -1) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; perror(&quot;socket: &quot;);&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; saddr.sin_family = AF_INET;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; saddr.sin_addr.s_addr = inet_addr(&quot;127.0.0.1&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; saddr.sin_port = htons(5678);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; len = sizeof(saddr);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ret = connect(sockfd,(struct sockaddr *)&amp;amp;saddr,len);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(ret &amp;lt;0 ) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; perror(&quot;connect: &quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; return -1;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; write(sockfd,&amp;amp;buff,sizeof(buff));&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; memset(buff,&#39;\0&#39;,sizeof(buff));&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; read(sockfd,&amp;amp;buff,sizeof(buff));&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;Client Read: %s\n&quot;,buff);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; close(sockfd);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;return 0;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developersfactory.blogspot.com/feeds/5474737497115656242/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developersfactory.blogspot.com/2012/08/simple-client-server-network-program.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/5474737497115656242'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4690837514005213557/posts/default/5474737497115656242'/><link rel='alternate' type='text/html' href='http://developersfactory.blogspot.com/2012/08/simple-client-server-network-program.html' title='Simple Client-Server network Program using TCP/IP stream sockets'/><author><name>Saikrishna</name><uri>http://www.blogger.com/profile/07211653249699054691</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>