<?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-2782932974377163522</id><updated>2024-08-30T10:40:31.453+05:30</updated><category term="C++"/><category term="string"/><category term="C"/><category term="CPP"/><category term="Data Structure"/><category term="recursive"/><category term="single linked list"/><category term="2d"/><category term="Circular Queue"/><category term="Queue"/><category term="call by reference in C++"/><category term="call by value"/><category term="dynamic memory allocation in C"/><category term="linked list"/><category term="linked listed"/><category term="multi dimensional array"/><category term="sorted linked list"/><category term="stack"/><category term="virtual destructor"/><category term="3d"/><category term="Accepting an object by reference in copy constructors"/><category term="BST"/><category term="Binary Search Tree"/><category term="Circular Que using Linked List"/><category term="Circular Queue using Array"/><category term="Cpp Program to Add Two Numbers using Class"/><category term="Crash"/><category term="Division of two numbers using BITWISE operat...bitwise operators"/><category term="Getter and Setter Methods in C++"/><category term="IPC"/><category term="Linux"/><category term="Memory Leak"/><category term="New features in C++"/><category term="access private member function in CPP"/><category term="bitwise operators"/><category term="bool"/><category term="call by address"/><category term="callback"/><category term="cast operator"/><category term="concatenate"/><category term="constructors"/><category term="divisionof two numbers using bitwise operators"/><category term="explicit"/><category term="fibonacci number"/><category term="fibonacci series"/><category term="for"/><category term="function pointer"/><category term="how to use getter and setter methods in c++"/><category term="how to use new and delete in c++"/><category term="loop"/><category term="make"/><category term="make utility"/><category term="makefile"/><category term="malloc"/><category term="msg queue"/><category term="multiplication of two numbers  using bitwise operators"/><category term="namespace"/><category term="new delete"/><category term="pass an object"/><category term="pass by address"/><category term="pass by reference"/><category term="pass by value"/><category term="private data member function"/><category term="return an object"/><category term="strcat"/><category term="strcmp"/><category term="strcpy"/><category term="string compare"/><category term="string length"/><category term="string reverse"/><category term="strlen"/><category term="strrev"/><category term="strstr"/><category term="substring"/><category term="system programming"/><category term="template"/><category term="tricky while loop"/><category term="virtual function"/><category term="virtual pointer"/><category term="virtual table"/><category term="vptr"/><category term="vtable"/><category term="wchar_t"/><category term="while loop"/><title type='text'>How to Program in CPP / C++ and C in Linux</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16009977468138578543</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>99</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2782932974377163522.post-3636300882705931240</id><published>2014-01-08T21:04:00.003+05:30</published><updated>2014-01-08T21:04:48.316+05:30</updated><title type='text'>Array and Pointers in C FAQ in Interviews 2014</title><content type='html'>&lt;ul style=&quot;background-color: #fefdfa; color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px; line-height: 1.2; list-style: none; margin: -8px -15px 0px; padding: 0px;&quot;&gt;
&lt;li style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; border-top-style: none; color: #666666; margin: 0px; padding: 0.5em 15px;&quot;&gt;&lt;a href=&quot;http://clinuxcode.blogspot.in/2013/09/c-linux-code-for-user-defined-string.html&quot; style=&quot;color: #7d171d; text-decoration: none;&quot;&gt;C Linux Code for user defined string routines strcmp strcpy strcat strrev strstr strlen&lt;/a&gt;&lt;/li&gt;
&lt;li style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; border-top-color: rgb(170, 177, 34); border-top-style: solid; border-top-width: 0px; color: #666666; margin: 0px; padding: 0.5em 15px;&quot;&gt;&lt;a href=&quot;http://clinuxcode.blogspot.in/2013/09/c-linux-code-for-multi-threaded-socket.html&quot; style=&quot;color: #7d171d; text-decoration: none;&quot;&gt;C Linux Code for multi threaded socket client/Server file sharing ftp&lt;/a&gt;&lt;/li&gt;
&lt;li style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; border-top-color: rgb(170, 177, 34); border-top-style: solid; border-top-width: 0px; color: #666666; margin: 0px; padding: 0.5em 15px;&quot;&gt;&lt;a href=&quot;http://clinuxcode.blogspot.in/2013/09/c-linux-code-to-count-number-of-times.html&quot; style=&quot;color: #7d171d; text-decoration: none;&quot;&gt;C Linux Code to count number of times given word repeated in a file&lt;/a&gt;&lt;/li&gt;
&lt;li style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; border-top-color: rgb(170, 177, 34); border-top-style: solid; border-top-width: 0px; color: #666666; margin: 0px; padding: 0.5em 15px;&quot;&gt;&lt;a href=&quot;http://clinuxcode.blogspot.in/2013/11/c-codeprogram-for-linked-list-tree-and_8.html&quot; style=&quot;color: #7d171d; text-decoration: none;&quot;&gt;C code/program for linked list, tree and other data structure&lt;/a&gt;&lt;/li&gt;
&lt;li style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; border-top-color: rgb(170, 177, 34); border-top-style: solid; border-top-width: 0px; color: #666666; margin: 0px; padding: 0.5em 15px;&quot;&gt;&lt;a href=&quot;http://clinuxcode.blogspot.in/2013/12/pointer-to-array-of-pointers-in-c.html&quot; style=&quot;color: #7d171d; text-decoration: none;&quot;&gt;Pointer to Array of Pointers in C&lt;/a&gt;&lt;/li&gt;
&lt;li style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; border-top-color: rgb(170, 177, 34); border-top-style: solid; border-top-width: 0px; color: #666666; margin: 0px; padding: 0.5em 15px;&quot;&gt;&lt;a href=&quot;http://clinuxcode.blogspot.in/2013/10/c-code-for-sorting-linked-list-elements.html&quot; style=&quot;color: #7d171d; text-decoration: none;&quot;&gt;C Code for sorting linked list elements nodes&lt;/a&gt;&lt;/li&gt;
&lt;li style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; border-top-color: rgb(170, 177, 34); border-top-style: solid; border-top-width: 0px; color: #666666; margin: 0px; padding: 0.5em 15px;&quot;&gt;&lt;a href=&quot;http://clinuxcode.blogspot.in/2013/09/c-linux-code-for-replacing-word-with.html&quot; style=&quot;color: #7d171d; text-decoration: none;&quot;&gt;C Linux Code for replacing a word with another word in a file&lt;/a&gt;&lt;/li&gt;
&lt;li style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; border-top-color: rgb(170, 177, 34); border-top-style: solid; border-top-width: 0px; color: #666666; margin: 0px; padding: 0.5em 15px;&quot;&gt;&lt;a href=&quot;http://clinuxcode.blogspot.in/2013/09/c-linux-code-for-grepping-pattern-and_12.html&quot; style=&quot;color: #7d171d; text-decoration: none;&quot;&gt;C Linux Code for grepping pattern and replacing with other word&lt;/a&gt;&lt;/li&gt;
&lt;li style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; border-top-color: rgb(170, 177, 34); border-top-style: solid; border-top-width: 0px; color: #666666; margin: 0px; padding: 0.5em 15px;&quot;&gt;&lt;a href=&quot;http://clinuxcode.blogspot.in/2013/12/array-of-pointers-in-c.html&quot; style=&quot;color: #7d171d; text-decoration: none;&quot;&gt;Array of Pointers to integer in C&lt;/a&gt;&lt;/li&gt;
&lt;li style=&quot;border-bottom-style: none; border-top-color: rgb(170, 177, 34); border-top-style: solid; border-top-width: 0px; color: #666666; margin: 0px; padding: 0.5em 15px;&quot;&gt;&lt;a href=&quot;http://clinuxcode.blogspot.in/2013/09/c-linux-code-for-multi-threaded-socket_16.html&quot; style=&quot;color: #7d171d; text-decoration: none;&quot;&gt;C Linux Code for multi threaded socket chat&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;You may Like to visit.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
&lt;ul style=&quot;background-color: #fefdfa; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; line-height: 1.2; list-style: none; margin: -8px -15px 0px; padding: 0px;&quot;&gt;
&lt;li style=&quot;border-bottom-style: none; border-top-color: rgb(170, 177, 34); border-top-style: solid; border-top-width: 0px; margin: 0px; padding: 0.5em 15px;&quot;&gt;&lt;a href=&quot;http://clinuxcode.blogspot.in/&quot;&gt;&lt;span style=&quot;color: #666666; font-size: 14px;&quot;&gt;http://&lt;/span&gt;&lt;span style=&quot;color: orange; font-size: large;&quot;&gt;clinuxcode&lt;/span&gt;&lt;span style=&quot;color: #666666; font-size: 14px;&quot;&gt;.blogspot.in/&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;a href=&quot;http://lealmitra.blogspot.in/&quot; style=&quot;line-height: 1.2;&quot;&gt;&lt;span style=&quot;color: #666666; font-size: 14px; line-height: 1.2;&quot;&gt;http://&lt;/span&gt;&lt;span style=&quot;color: lime; font-family: Courier New, Courier, monospace; font-size: large; line-height: 1.2;&quot;&gt;lealmitra&lt;/span&gt;&lt;span style=&quot;color: #666666; font-size: 14px; line-height: 1.2;&quot;&gt;.blogspot.in/&lt;/span&gt;&lt;/a&gt;&amp;nbsp; &amp;nbsp;&lt;a href=&quot;http://codefora.blogspot.in/&quot; style=&quot;line-height: 1.2;&quot;&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&lt;span style=&quot;font-size: 14px;&quot;&gt;http://&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: large;&quot;&gt;codefora&lt;/span&gt;&lt;span style=&quot;font-size: 14px;&quot;&gt;.blogspot.in/&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/h3&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/3636300882705931240/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2014/01/array-and-pointers-in-c-faq-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/3636300882705931240'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/3636300882705931240'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2014/01/array-and-pointers-in-c-faq-in.html' title='Array and Pointers in C FAQ in Interviews 2014'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16009977468138578543</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-2782932974377163522.post-9197483614741973786</id><published>2013-05-11T11:23:00.003+05:30</published><updated>2013-05-24T15:32:16.815+05:30</updated><title type='text'>How to prepare C++/CPP/C for interview</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;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Frequently asked C++ questions in interviews:&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2013/05/how-to-compare-two-strings-using.html&quot;&gt;How
to compare two strings using pointer without strcmp&lt;/a&gt;&lt;/span&gt;&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2013/05/how-to-copy-string-without-using-strcp.html&quot;&gt;How
to copy a string without using strcp with pointer&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2013/05/how-to-find-length-of-string-without.html&quot;&gt;How
to find the length of a string without using library function strlen&lt;/a&gt;&lt;/span&gt;

&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2013/05/how-to-reverse-string-using-pointer-or.html&quot;&gt;How
to reverse a string using pointer or array in cpp without using
strrev library function&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2013/04/cpp-program-for-concatenating-two.html&quot;&gt;CPP
program for concatenating two strings without using inbuilt library
function strcat&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-search-substring-in-ccpp-without.html&quot;&gt;How
to search a substring in C++/Cpp without using library function
strstr&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-use-make-file-in-cpp-c-c.html&quot;&gt;How
to use make file in CPP C+++ C&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-implement-msgq-message-queue-in.html&quot;&gt;How
to implement msgq message queue in CPP C C++&lt;/a&gt;&lt;/span&gt;
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-use-function-pointer-in-cppcc.html&quot;&gt;How
to use callback function pointer in cpp/C/C++&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-use-malloc-for-2d-array-dynamic.html&quot;&gt;How
to use malloc for 2d array dynamic memory allocation&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-use-new-to-allocate-memory-for.html&quot;&gt;How
to use new to allocate memory for 3d array in CPP C++&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-learn-stack-and-flow-of-function.html&quot;&gt;How
to learn stack and flow of function call and control in cpp&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-learn-recursive-function-call-in.html&quot;&gt;How
to learn recursive function call in cpp/C++/C&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-distinguish-between-call-by.html&quot;&gt;How
to distinguish between call by value, call by reference, call by
address&lt;/a&gt;&lt;/span&gt;&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-for-circular.html&quot;&gt;How
to write cpp program for Circular Queue using Array&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-for-cirrcular.html&quot;&gt;How
to write cpp program for Circular Queue using Linked List&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-for-bst-binary.html&quot;&gt;How
to write cpp program for BST Binary Search Tree&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-to-reverse.html&quot;&gt;How
to write cpp program to reverse a linked list&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-sorted-linked-list-program.html&quot;&gt;How
to write sorted linked list program in cpp with class&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2012/10/how-to-use-template-in-cpp.html&quot;&gt;How
to use template in cpp&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2012/10/why-to-use-explicit-keyword-in-c.html&quot;&gt;Why
to use explicit keyword in C++&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2012/10/how-to-use-new-and-delete-in-c.html&quot;&gt;How
to use new and delete in C++&lt;/a&gt;&lt;/span&gt;&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2012/09/getter-and-setter-methods-in-c.html&quot;&gt;Getter
and Setter Methods in C++&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2012/08/c-program-to-add-two-numbers-using-class.html&quot;&gt;C++
Program to Add Two Numbers using Class&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2012/08/c-program-for-fibonacci-series.html&quot;&gt;C++
Program for Fibonacci series&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2012/07/simple-program-for-malloc-in-c.html&quot;&gt;Simple
Program for malloc in C&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2012/07/is-it-necessary-to-accept-object-by.html&quot;&gt;Is
it necessary to accept an object by reference in copy constructor?&lt;/a&gt;&lt;/span&gt;

&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2012/07/multiplication-of-two-numbers-using.html&quot;&gt;Multiplication
of two numbers using BITWISE operators&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2012/07/new-features-in-ansi-c-standard.html&quot;&gt;New
Features in ANSI C++ Standard&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2012/07/bitwise-operation-for-division.html&quot;&gt;Bitwise
operation for division&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2012/01/how-to-pass-object-and-return-object-in.html&quot;&gt;How
to pass a object and return a object in C++/Cpp&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2012/01/how-to-acces-private-member-function-in.html&quot;&gt;How
to acces private member function in C++/CPP&lt;/a&gt;&lt;/span&gt;&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2012/01/why-destructor-should-be-virtual-in-c.html&quot;&gt;Why
destructor should be virtual in C++ ?&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2012/01/how-to-use-tricky-while-loop-in-cppcc.html&quot;&gt;How
to use tricky while loop in CPP,C++,C&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2012/01/how-to-use-for-loop-in-c-cpp-c.html&quot;&gt;How
to use for loop in C++ CPP C&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2012/01/program-in-c-to-learn-virtual-function.html&quot;&gt;Program
in C++ to learn virtual function&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2012/01/how-to-use-virtual-function-c.html&quot;&gt;How
to use Virtual function C++&lt;/a&gt;&lt;/span&gt; 
&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2012/01/program-to-create-table-in-c.html&quot;&gt;Program
to create a table in C&lt;/a&gt;&lt;a href=&quot;http://www.howtocpp.com/2012/01/program-to-create-table-in-c.html&quot;&gt;


 
 
 
 &lt;style type=&quot;text/css&quot;&gt;
 &lt;!--
  @page { margin: 0.79in }
  P { margin-bottom: 0.08in }
  A:link { so-language: zxx }
 &lt;/style&gt;
 &lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;a href=&quot;http://www.howtocpp.com/2013/05/how-to-compare-two-strings-using.html&quot;&gt;Next &lt;span style=&quot;font-size: small;&quot;&gt;Page&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.howtocpp.com/2012/01/program-to-create-table-in-c.html&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;/span&gt;

&lt;br /&gt;
&lt;h1 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
 
&lt;/h1&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/9197483614741973786/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/05/how-to-prepare-ccppc-for-interview.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/9197483614741973786'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/9197483614741973786'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/05/how-to-prepare-ccppc-for-interview.html' title='How to prepare C++/CPP/C for interview'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16009977468138578543</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-2782932974377163522.post-4804926171919944187</id><published>2013-05-09T21:30:00.001+05:30</published><updated>2013-05-19T12:43:05.536+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="strcmp"/><category scheme="http://www.blogger.com/atom/ns#" term="string"/><category scheme="http://www.blogger.com/atom/ns#" term="string compare"/><title type='text'>How to compare two strings using pointer without strcmp</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;
 &lt;!--
  @page { margin: 0.79in }
  P { margin-bottom: 0.08in; direction: ltr; color: #000000; widows: 2; orphans: 2 }
 &lt;/style&gt;
 &lt;br /&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;b&gt;/*C++/CPP/C program to
compare two strings without using&amp;nbsp; library function strcmp*/&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include&amp;lt;string.h&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int strCmp(char *p1,
char *p2);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int main()&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
char arr1[20];&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;Enter a
String:\n&quot;);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
scanf(&quot;%s&quot;,&amp;amp;arr1);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
char arr2[20];&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;Enter a
String:\n&quot;);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
scanf(&quot;%s&quot;,&amp;amp;arr2);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;You
entered:%s and %s\n&quot;,arr1,arr2);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int result;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
result=strCmp(arr1,
arr2);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(result==0)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;Equal\n&quot;);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
else&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;Not
Equal.\n&quot;);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
return 0;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int strCmp(char *p1,
char *p2)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
while(*p1++==*p2++)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(*p1==&#39;\0&#39;|| *p2==&#39;\0&#39;)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
break;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}//end of while&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(*p1==&#39;\0&#39;
&amp;amp;&amp;amp; *p2==&#39;\0&#39;)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
return
0;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
else&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;else\n&quot;);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
return -1;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
/*&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
* $ gcc strCmp.c&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
$ ./a.out&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Enter a String:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
India&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Enter a String:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Indi&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
You entered:India
and Indi&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
else&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Not Equal.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
$ ./a.out&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Enter a String:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Indi&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Enter a String:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
India&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
You entered:Indi and
India&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
else&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Not Equal.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
$ ./a.out&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Enter a String:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
India&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Enter a String:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
India&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
You entered:India
and India&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Equal&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
*/&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;


 
 
 
 &lt;style type=&quot;text/css&quot;&gt;
 &lt;!--
  @page { margin: 0.79in }
  P { margin-bottom: 0.08in }
  A:link { so-language: zxx }
 --&gt;
 &lt;/style&gt;


&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/05/how-to-compare-two-strings-using.html&quot;&gt;Previous&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;a href=&quot;http://howtocpp.com/&quot;&gt;Home&lt;/a&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;a href=&quot;http://www.howtocpp.com/2013/05/how-to-copy-string-without-using-strcp.html&quot;&gt;Next&lt;/a&gt; 
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/4804926171919944187/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/05/how-to-compare-two-strings-using.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/4804926171919944187'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/4804926171919944187'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/05/how-to-compare-two-strings-using.html' title='How to compare two strings using pointer without strcmp'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16009977468138578543</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-2782932974377163522.post-2884306828658110118</id><published>2013-05-05T23:17:00.002+05:30</published><updated>2013-05-19T12:46:50.570+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="strcpy"/><category scheme="http://www.blogger.com/atom/ns#" term="string"/><title type='text'>How to copy a string without using strcp with pointer</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;line-height: 100%; margin-bottom: 0in;&quot;&gt;
/*How to copy a string without using library function strcpy.&lt;br /&gt;
How to use pointer/array to copy a string/sentence. C++/CPP/C 
program/code to copy a string/word/sentence without using inbuilt
 function strcpy.How copy a string without using library function strlen.&lt;b&gt; cpp program to
copy a string using pointer.&lt;/b&gt;cpp program to
copy a string without using library function strcpy*/&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include&amp;lt;string.h&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void strCpy(char
*p2,char *p1);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int main()&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
char arr1[20];&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
char arr2[20];&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;Enter a
String:\n&quot;);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
scanf(&quot;%s&quot;,&amp;amp;arr1);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
strCpy(arr2, arr1);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;You
entered and copied:%s\n&quot;,arr2);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
return 0;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void strCpy(char
*p2,char *p1)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
while(*p1!=&#39;\0&#39;)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
*p2++=*p1++;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
*p2=&#39;\0&#39;;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
/*&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
* Enter a String:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
India&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
You entered and
copied:India&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
*/&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;i&gt;/*cpp program for
copying a string without using library function strcpy*/&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include&amp;lt;string.h&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int main()&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
char arr1[20];&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;Enter a
String:\n&quot;);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
scanf(&quot;%s&quot;,&amp;amp;arr1);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
char arr2[20];&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int i,j;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
for(i=0,j=0;arr1[i]!=0;i++,j++)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
arr2[j]=arr1[i];&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
arr2[j]=&#39;\0&#39;;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;You
entered and copied:%s\n&quot;,arr2);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
return 0;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
/*&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Enter a String:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Hello&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
You entered and
copied:Hello&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
*/&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;



 
 
 
 &lt;style type=&quot;text/css&quot;&gt;
 &lt;!--
  @page { margin: 0.79in }
  P { margin-bottom: 0.08in }
  A:link { so-language: zxx }
 --&gt;
 &lt;/style&gt;


&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/05/how-to-compare-two-strings-using.html&quot;&gt;Previous&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
  &lt;a href=&quot;http://howtocpp.com/&quot;&gt;Home&lt;/a&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;a href=&quot;http://www.howtocpp.com/2013/05/how-to-find-length-of-string-without.html&quot;&gt;  Next&lt;/a&gt; 
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/2884306828658110118/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/05/how-to-copy-string-without-using-strcp.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/2884306828658110118'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/2884306828658110118'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/05/how-to-copy-string-without-using-strcp.html' title='How to copy a string without using strcp with pointer'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16009977468138578543</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-2782932974377163522.post-3744481729746301680</id><published>2013-05-04T19:32:00.000+05:30</published><updated>2013-05-19T12:50:18.435+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="string"/><category scheme="http://www.blogger.com/atom/ns#" term="string length"/><category scheme="http://www.blogger.com/atom/ns#" term="strlen"/><title type='text'>How to find the length of a string without using library function strlen</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;
 &lt;!--
  @page { margin: 0.79in }
  P { margin-bottom: 0.08in; direction: ltr; color: #000000; widows: 2; orphans: 2 }
 &lt;/style&gt;
 &lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0.14in;&quot;&gt;
/*How to find length of a string without using library function strstr.&lt;br /&gt;
How to use pointer/array to find length of string sentence. C++/CPP/C program/code to find length a string/word/sentence without using inbuilt function strlen.How to find the length of a
string without using library function strlen*/&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include&amp;lt;string.h&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int strLen(char *p);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int main()&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
char arr1[20];&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;Enter a
String:\n&quot;);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
scanf(&quot;%s&quot;,&amp;amp;arr1);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;You
entered:%s\n&quot;,arr1);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int n;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
n=strLen(arr1);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;Strlen
of entered string is:%d\n&quot;,n);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
return 0;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int length=0;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int strLen(char *p)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;Inside
strLen\n&quot;);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
char *temp;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
temp=p;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
while(*temp)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
temp++;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
return (temp-p);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
/*&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Enter a String:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
India&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
You entered:India&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Inside strLen&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Strlen of entered
string is:5&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
* */&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;



 
 
 
 &lt;style type=&quot;text/css&quot;&gt;
 &lt;!--
  @page { margin: 0.79in }
  P { margin-bottom: 0.08in }
  A:link { so-language: zxx }
 --&gt;
 &lt;/style&gt;


&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/05/how-to-reverse-string-using-pointer-or.html&quot;&gt;Previous&lt;/a&gt;&lt;a href=&quot;http://www.howtocpp.com/2013/05/how-to-reverse-string-using-pointer-or.html&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
   &lt;/a&gt;&lt;a href=&quot;http://www.howtocpp.com/2013/05/how-to-reverse-string-using-pointer-or.html&quot;&gt;Home&lt;/a&gt;&lt;a href=&quot;http://www.howtocpp.com/2013/05/how-to-reverse-string-using-pointer-or.html&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                                     Next &lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/3744481729746301680/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/05/how-to-find-length-of-string-without.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/3744481729746301680'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/3744481729746301680'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/05/how-to-find-length-of-string-without.html' title='How to find the length of a string without using library function strlen'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16009977468138578543</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-2782932974377163522.post-2829307635853021679</id><published>2013-05-03T07:30:00.001+05:30</published><updated>2013-05-19T12:52:31.117+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="string"/><category scheme="http://www.blogger.com/atom/ns#" term="string reverse"/><category scheme="http://www.blogger.com/atom/ns#" term="strrev"/><title type='text'>How to reverse a string using pointer or array in cpp without using strrev library function</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
How to reverse a string using pointer or array. CPP program for reversing a strings without using inbuilt library function strrev.
 How to reverse a sentence in cpp/C++/C without using library function strrev.Program to reverse a string using pointer.&lt;br /&gt;
#include&amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include&amp;lt;string.h&amp;gt;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
char arr1[20];&lt;br /&gt;
printf(&quot;Enter a String:\n&quot;);&lt;br /&gt;
scanf(&quot;%s&quot;,&amp;amp;arr1);&lt;br /&gt;
printf(&quot;You entered:%s\n&quot;,arr1);&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
char arr2[20];&lt;br /&gt;
&lt;br /&gt;
char *p1=arr1+strlen(arr1)-1;&lt;br /&gt;
char *p2=arr2;&lt;br /&gt;
while(p2&amp;lt;p1)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; *p2++=*p1--;&lt;br /&gt;
}&lt;br /&gt;
printf(&quot;You entered:%s\n&quot;,arr2);&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
/*OUTPUT&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;* Enter a String:&lt;br /&gt;
India&lt;br /&gt;
You entered:India&lt;br /&gt;
You entered:aidnI&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*How to reverse a string without using library function strrev and strlen*/&lt;br /&gt;
#include&amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include&amp;lt;string.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void strRev(char *arr1);&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
char arr1[20];&lt;br /&gt;
printf(&quot;Enter a String:\n&quot;);&lt;br /&gt;
scanf(&quot;%s&quot;,&amp;amp;arr1);&lt;br /&gt;
printf(&quot;You entered:%s\n&quot;,arr1);&lt;br /&gt;
&lt;br /&gt;
strRev(arr1);&lt;br /&gt;
&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
void strRev(char *arr1)&lt;br /&gt;
{&lt;br /&gt;
char *p1=arr1+strlen(arr1)-1;&lt;br /&gt;
char arr2[20];&lt;br /&gt;
char *p2=arr2;&lt;br /&gt;
&lt;br /&gt;
while(p2&amp;lt;p1)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; *p2++=*p1--;&lt;br /&gt;
}&lt;br /&gt;
*p2=&#39;\0&#39;;&lt;br /&gt;
&lt;br /&gt;
printf(&quot;Reverse String is:%s\n&quot;,arr2);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
Enter a String:&lt;br /&gt;
India&lt;br /&gt;
You entered:India&lt;br /&gt;
You entered:aidnI&lt;br /&gt;
*/&lt;br /&gt;



 
 
 
 &lt;style type=&quot;text/css&quot;&gt;
 &lt;!--
  @page { margin: 0.79in }
  P { margin-bottom: 0.08in }
  A:link { so-language: zxx }
 --&gt;
 &lt;/style&gt;


&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/05/how-to-find-length-of-string-without.html&quot;&gt;Previous&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
    &lt;a href=&quot;http://howtocpp.com/&quot;&gt;Home&lt;/a&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;
&lt;a href=&quot;http://www.howtocpp.com/2013/04/cpp-program-for-concatenating-two.html&quot;&gt;    Next&lt;/a&gt; 
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/2829307635853021679/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/05/how-to-reverse-string-using-pointer-or.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/2829307635853021679'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/2829307635853021679'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/05/how-to-reverse-string-using-pointer-or.html' title='How to reverse a string using pointer or array in cpp without using strrev library function'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16009977468138578543</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-2782932974377163522.post-150762414091721640</id><published>2013-04-28T20:30:00.002+05:30</published><updated>2013-05-19T12:57:39.437+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="concatenate"/><category scheme="http://www.blogger.com/atom/ns#" term="strcat"/><category scheme="http://www.blogger.com/atom/ns#" term="string"/><title type='text'>CPP program for concatenating two strings without using inbuilt library function strcat</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
How to concatenate two strings using pointer or array. CPP program for concatenating two strings without using inbuilt library function strcat. How to concatenate two strings in cpp/C++/C without using inbuilt in function strcat.Program to concatenate two strings using pointer.&lt;br /&gt;
&lt;br /&gt;
#include&amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include&amp;lt;string.h&amp;gt;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
char arr1[20];&lt;br /&gt;
printf(&quot;Enter a String:\n&quot;);&lt;br /&gt;
scanf(&quot;%s&quot;,&amp;amp;arr1);&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
char arr2[20];&lt;br /&gt;
scanf(&quot;%s&quot;,&amp;amp;arr2);&lt;br /&gt;
&lt;br /&gt;
printf(&quot;You entered:%s and %s\n&quot;,arr1,arr2);&lt;br /&gt;
&lt;br /&gt;
int i=0,j=0,length=0;&lt;br /&gt;
&lt;br /&gt;
for(i=0;arr1[i]!=&#39;\0&#39;;i++)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; length++;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
for(i=length,j=0;arr2[j]!=&#39;\0&#39;;i++,j++)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arr1[i]=arr2[j];&lt;br /&gt;
}&lt;br /&gt;
arr1[i]=&#39;\0&#39;;&lt;br /&gt;
&lt;br /&gt;
printf(&quot;Concated string is:%s&quot;,arr1);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;br /&gt;
}&lt;br /&gt;
/*&lt;br /&gt;
Enter a String:&lt;br /&gt;
Hello&lt;br /&gt;
India&lt;br /&gt;
You entered:Hello and India&lt;br /&gt;
Concated string is:HelloIndia&lt;br /&gt;
*/&lt;br /&gt;
&lt;style type=&quot;text/css&quot;&gt;
 &lt;!--
  @page { margin: 0.79in }
  P { margin-bottom: 0.08in }
  A:link { so-language: zxx }
 &lt;/style&gt;
 &lt;br /&gt;


&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/05/how-to-reverse-string-using-pointer-or.html&quot;&gt;Previous&lt;/a&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; &lt;a href=&quot;http://howtocpp.com/&quot;&gt;Home&lt;/a&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; &lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-search-substring-in-ccpp-without.html&quot;&gt;Next&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/150762414091721640/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/04/cpp-program-for-concatenating-two.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/150762414091721640'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/150762414091721640'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/04/cpp-program-for-concatenating-two.html' title='CPP program for concatenating two strings without using inbuilt library function strcat'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16009977468138578543</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-2782932974377163522.post-4239333667163887086</id><published>2013-04-26T23:06:00.000+05:30</published><updated>2013-05-19T13:00:23.483+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="string"/><category scheme="http://www.blogger.com/atom/ns#" term="strstr"/><category scheme="http://www.blogger.com/atom/ns#" term="substring"/><title type='text'>How to search a substring in C++/Cpp without using library function strstr</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;
 &lt;!--
  @page { margin: 0.79in }
  P { margin-bottom: 0.08in; direction: ltr; color: #000000; widows: 2; orphans: 2 }
 &lt;/style&gt;
 &lt;br /&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;b&gt;/*How to search a
sub string without using library function strstr.&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;How to use pointer/array to search substring in a string sentence.&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;b&gt;C++/CPP/C program/code to search a word in a sentence without using inbuilt function strstr*/&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include&amp;lt;string.h&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int main()&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
char arr1[50];&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;Enter a
String:\n&quot;);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
scanf(&quot;%s&quot;,&amp;amp;arr1);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
char arr2[20];&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;Enter a
String:\n&quot;);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
scanf(&quot;%s&quot;,&amp;amp;arr2);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;Searching
for:%s\n&quot;,arr2);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; 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;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int count1, count2;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
count1=0; count2=0;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
while(arr1[count1]!=&#39;\0&#39;)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
count1++;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
while(arr2[count2]!=&#39;\0&#39;)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
count2++;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int i,j,flag;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
for(i=0;i&amp;lt;count1-count2;i++)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
for(j=i;j&amp;lt;i+count2;j++)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
flag=1;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(arr1[j]!=arr2[j-i])&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
flag=0;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
break;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if (flag==1)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
break;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if (flag==1)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;yes
found\n&quot;);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
else&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;Not
found\n&quot;);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
return 0;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}/*&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Enter a String:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
zxcvbnaaaSONYdkjsdfklj&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Enter a String:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
SONY&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Searching for:SONY&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
yes found*/&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/04/cpp-program-for-concatenating-two.html&quot;&gt;Previous&lt;/a&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; &lt;a href=&quot;http://howtocpp.com/&quot;&gt;Home&lt;/a&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; &lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-use-make-file-in-cpp-c-c.html&quot;&gt;Next&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/4239333667163887086/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/04/how-to-search-substring-in-ccpp-without.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/4239333667163887086'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/4239333667163887086'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/04/how-to-search-substring-in-ccpp-without.html' title='How to search a substring in C++/Cpp without using library function strstr'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16009977468138578543</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-2782932974377163522.post-1933923259464936011</id><published>2013-04-25T08:09:00.001+05:30</published><updated>2013-05-24T14:37:07.950+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="make"/><category scheme="http://www.blogger.com/atom/ns#" term="make utility"/><category scheme="http://www.blogger.com/atom/ns#" term="makefile"/><title type='text'>How to use make file in CPP C+++ C</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
/*What is makefile&amp;nbsp;
?&lt;br /&gt;
---------------------------------------&lt;br /&gt;
makefile is a script/utility&amp;nbsp; that contains target, dependencies and actions to compile modified file/files in a project of multple files.
&amp;nbsp;*/&lt;br /&gt;
&lt;br /&gt;
/*SYNTAX
&lt;br /&gt;
-----------------------------------
&lt;br /&gt;
target:dependencies
&lt;br /&gt;
[tab]&amp;nbsp; actions
&lt;br /&gt;
.
&lt;br /&gt;
.
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&amp;nbsp;*/
&lt;br /&gt;
&lt;br /&gt;
/*HOW To USE MAKEFILE&amp;nbsp;
in Cpp&lt;br /&gt;
---------------------------------------
&lt;br /&gt;
steps to execut:
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;make -f newmakefile
&lt;/b&gt;&lt;br /&gt;
newmakefile //generating .o
&lt;br /&gt;
newmakefile //generating executable target_bin&amp;nbsp;
&lt;br /&gt;
target_bin //execute target_bin
&lt;br /&gt;
*/
&lt;br /&gt;
&lt;br /&gt;
//makefile
&lt;br /&gt;
//-----------------------------------------------
&lt;br /&gt;
&lt;b&gt;all:main.o module.o
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; gcc main.o module.o -o target_bin
&lt;br /&gt;main.o:main.c module.h
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; gcc -I . -c main.c
&lt;br /&gt;module.o:module.c module.h
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; gcc -I . -c module.c
&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
//module.c contailns definition of the function1
&lt;br /&gt;
//---------------------------------------------------
&lt;br /&gt;
#include &quot;module.h&quot;
&lt;br /&gt;
&lt;br /&gt;
void function1()
&lt;br /&gt;
{
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;\nHeloo function from Makefile\n&quot;);
&lt;br /&gt;
}
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
//module.h contains the headers and declaraion of function1
&lt;br /&gt;
//---------------------------------------------------
&lt;br /&gt;
#include&amp;lt;stdio.h&amp;gt;
&lt;br /&gt;
void function1();
&lt;br /&gt;
&lt;br /&gt;
//main.c contains the call to the function1
&lt;br /&gt;
//---------------------------------------------------
&lt;br /&gt;
//stdio.h not needed as included in module.h
&lt;br /&gt;
#include &quot;module.h&quot;
&lt;br /&gt;
int main()
&lt;br /&gt;
{
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; function1();
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;
&lt;br /&gt;
}
&lt;br /&gt;
&lt;br /&gt;
//I . specifies to look header files in current direcory
&lt;br /&gt;
//all:&amp;nbsp; is a special target that take object files as depenedencies
&lt;br /&gt;
//main.o: is filename target whose dependency is src file
&lt;br /&gt;
//clean: is a special target that takes no dependency.
&lt;br /&gt;
//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rm -rf&amp;nbsp;&amp;nbsp; *.o
&lt;br /&gt;
//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rm target_bin
&lt;br /&gt;
//makefile first compiles the files with no dependency then
&lt;br /&gt;
//file which has dependency of compiled files and so on&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-search-substring-in-ccpp-without.html&quot;&gt;Previous&lt;/a&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; &lt;a href=&quot;http://howtocpp.com/&quot;&gt;Home&lt;/a&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; &lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=2782932974377163522#overviewstats/postNum=8&quot;&gt;Next&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/1933923259464936011/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/04/how-to-use-make-file-in-cpp-c-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/1933923259464936011'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/1933923259464936011'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/04/how-to-use-make-file-in-cpp-c-c.html' title='How to use make file in CPP C+++ C'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16009977468138578543</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-2782932974377163522.post-8227531615028965063</id><published>2013-04-22T22:13:00.003+05:30</published><updated>2013-05-24T14:45:12.078+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="IPC"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><category scheme="http://www.blogger.com/atom/ns#" term="msg queue"/><category scheme="http://www.blogger.com/atom/ns#" term="system programming"/><title type='text'>How to implement msgq message queue in CPP C C++</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;
 &lt;!--
  @page { margin: 0.79in }
  P { margin-bottom: 0.08in; direction: ltr; color: #000000; widows: 2; orphans: 2 }
 &lt;/style&gt;
 &lt;br /&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;b&gt;//Program to
implement msgq&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
/*CPP Program for msg queue in Linux&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
pipes work with
related process parent-child only.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Fifo can make
unrelated process to communicate but 
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
fifo created does
not persists for use in future.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Shared memory is
similar to fifo but over comes this and can be used later also.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Program to implement
IPC Message Queues IPC mechanism.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
msgqSendkirk.c adds
the message on the message queue.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
msgqRecvSpock.c
reads and removes the message from the message 
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
queue.To use this
program first compile and run msgqSendkirk.c 
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
to add a message to
the message queue. To see the 
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Message Queue in
other terminal run msgqRecvSpock.c&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
ipcs -q shows the
msg ques.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
ipcrm -q 131073
removes the msgq created say 131071 */&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include &amp;lt;errno.h&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include &amp;lt;string.h&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include
&amp;lt;sys/types.h&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include &amp;lt;sys/ipc.h&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include &amp;lt;sys/msg.h&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
//1. declaring the
msg structure&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
struct my_msgbuf&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; 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;line-height: 100%; margin-bottom: 0in;&quot;&gt;
long mtype;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
char mtext[200];&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
};&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int main(void)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
struct my_msgbuf
buf;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int msqid;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
key_t key;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
//2. creating key
with ftok&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
key =
ftok(&quot;msgqSendkirk.c&quot;, &#39;B&#39;);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
///local/kumarsah/comp/linuxdemo/msgqSendkirk.c&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
//3. creating msgq
with msgget&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
msqid = msgget(key,
0644 | IPC_CREAT);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;Enter
lines of text, ^D to quit:\n&quot;);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
buf.mtype = 1;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
//4. type and send
the message&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
while(fgets(buf.mtext,
sizeof buf.mtext, stdin) != NULL) 
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int len =
strlen(buf.mtext);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
msgsnd(msqid, &amp;amp;buf,
len+1, 0);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
//5. removing msgq
with msgctl with IPC_RMID&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
msgctl(msqid,
IPC_RMID, NULL) ;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
return 0;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;b&gt;//
msgqRecvSpock.c&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include &amp;lt;errno.h&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include
&amp;lt;sys/types.h&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include &amp;lt;sys/ipc.h&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include &amp;lt;sys/msg.h&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
struct my_msgbuf {&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
long mtype;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
char mtext[200];&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
};&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int main(void)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
struct my_msgbuf
buf;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int msqid;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
key_t key;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if ((key =
ftok(&quot;msgqSendkirk.c&quot;, &#39;B&#39;)) == -1) {/* same key as
msgqSendkirk.c */&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
perror(&quot;ftok&quot;);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
exit(1);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if ((msqid =
msgget(key, 0644)) == -1) { /* connect to the queue */&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
perror(&quot;msgget&quot;);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
exit(1);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;spock:
ready to receive messages:\n&quot;);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
for(;;) { /* Spock
never quits! */&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if (msgrcv(msqid,
&amp;amp;buf, sizeof(buf.mtext), 0, 0) == -1) {&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
perror(&quot;msgrcv&quot;);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
exit(1);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;spock:
\&quot;%s\&quot;\n&quot;, buf.mtext);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
return 0;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
/*&lt;b&gt;terminal 1:&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
$ gcc msgqSendkirk.c&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
$ ./a.out&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Enter lines of text,
^D to quit:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
dwqdadd&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
aaaaaaaaa&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
ddddd&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
ddd&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
dd&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;b&gt;terminal2:&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
gcc msgqRecvSpock.c&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
$ ./a.out&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
spock: ready to
receive messages:.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
spock: &quot;dwqdadd&quot;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
sldjslds&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
spock: &quot;aaaaaaaaa&quot;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
spock: &quot;ddddd&quot;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
ddd&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
d&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
*/&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-use-make-file-in-cpp-c-c.html&quot;&gt;Previous&lt;/a&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; &lt;a href=&quot;http://howtocpp.com/&quot;&gt;Home&lt;/a&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; &lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-use-function-pointer-in-cppcc.html&quot;&gt;Next&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/8227531615028965063/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/04/how-to-implement-msgq-message-queue-in.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/8227531615028965063'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/8227531615028965063'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/04/how-to-implement-msgq-message-queue-in.html' title='How to implement msgq message queue in CPP C C++'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16009977468138578543</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-2782932974377163522.post-3028800730389215847</id><published>2013-04-21T11:15:00.000+05:30</published><updated>2013-05-24T14:46:41.416+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="callback"/><category scheme="http://www.blogger.com/atom/ns#" term="function pointer"/><title type='text'>How to use callback function pointer in cpp/C/C++</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Program for callback /function pointer in CPP/C/C++&lt;br /&gt;
&lt;style type=&quot;text/css&quot;&gt;
 &lt;!--
  @page { margin: 0.79in }
  P { margin-bottom: 0.08in; direction: ltr; color: #000000; line-height: 115%; widows: 2; orphans: 2 }
  P.western { font-family: &quot;Calibri&quot;, sans-serif; font-size: 11pt; so-language: en-US }
  P.cjk { font-family: &quot;Calibri&quot;, sans-serif; font-size: 11pt }
  P.ctl { font-family: &quot;Times New Roman&quot;, serif; font-size: 11pt; so-language: ar-SA }
 &lt;/style&gt;
 &lt;br /&gt;
&lt;div class=&quot;western&quot; style=&quot;margin-bottom: 0.14in;&quot;&gt;
What  is  function
pointers?As we know a pointer
is a special variable that folds the address of another variable.&lt;br /&gt;
&lt;b&gt;Function pointer is
also&amp;nbsp; a pointer  that hold the address of a function&lt;/b&gt;.&lt;/div&gt;
&lt;div class=&quot;western&quot; style=&quot;margin-bottom: 0.14in;&quot;&gt;
Int array[10]; //
here array is a constant pointer to a 10 element array. That is
constant pointer to first element of array.&lt;/div&gt;
&lt;div class=&quot;western&quot; style=&quot;margin-bottom: 0.14in;&quot;&gt;
Can we declare a
non-constant pointer to a function? Yes we can .&lt;/div&gt;
&lt;div class=&quot;western&quot; style=&quot;margin-bottom: 0.14in;&quot;&gt;
&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;Int
&lt;/span&gt;&lt;b style=&quot;background-color: #eeeeee;&quot;&gt;(&lt;/b&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;*funcPtr&lt;/span&gt;&lt;b style=&quot;background-color: #eeeeee;&quot;&gt;)&lt;/b&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;()&lt;/span&gt;;//funcPtr is a pointer to a function that takes no
arguments and returns an integers.//parenthesis is must here as we are not assigning the return type.&lt;/div&gt;
&lt;div class=&quot;western&quot; style=&quot;margin-bottom: 0.14in;&quot;&gt;
Int
(*funcPtr)(int,int);//funcPtr is a pointer to a function that takes
two arguments and returns an integers.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;western&quot; style=&quot;margin-bottom: 0.14in;&quot;&gt;
Callback
function-callback function is reference to a piece of executable code
that is past as arguments to another code.&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;div style=&quot;margin-bottom: 0.14in;&quot;&gt;
This allows a lower level
layer code to call a function defined in higher level  layer.&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.25in;&quot;&gt;
Function pointer are used in
 many situation like if you are writing a code for sorting an array
 but instead of hard coding the code of comparison of elements to
 sort we can provide a way to the user to defined how a particular
 part of the code will be performed such as array is sorted in
 ascending or descending order.&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.25in;&quot;&gt;
&lt;u&gt;&lt;b&gt;Simple
example of a function:&lt;/b&gt;&lt;/u&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.25in;&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;&lt;br /&gt;
int
func(int,int);&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
int sum;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.25in;&quot;&gt;
sum=func(1,2);&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.25in;&quot;&gt;
printf(&quot;\sum=%d\n&quot;,sum);&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.25in;&quot;&gt;
return 0;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.25in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.25in;&quot;&gt;
int func(int a,
int b)&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.25in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.25in;&quot;&gt;
return a+b;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.25in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.25in;&quot;&gt;
&lt;u&gt;&lt;b&gt;Callback
function : example of a function pointer in cpp/C/C++:&lt;/b&gt;&lt;/u&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.5in;&quot;&gt;
//Program for callback function Pointer &lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.5in;&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.5in;&quot;&gt;
int
func(int,int);&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.5in;&quot;&gt;
int main()&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.5in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.5in;&quot;&gt;
//decalring a
func ptr taking 2 args and returning a int&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.5in;&quot;&gt;
int(*funcPtr)(int,
int);&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.5in;&quot;&gt;
int sum;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.5in;&quot;&gt;
funcPtr=func;//assiging
a function addr to ptr&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.5in;&quot;&gt;
//calling
function through explicit dereference&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.5in;&quot;&gt;
sum=(*funcPtr)(1,2);&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.5in;&quot;&gt;
printf(&quot;\nSum=%d\n&quot;,sum);&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.5in;&quot;&gt;
//calling
function through implicit dereference&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.5in;&quot;&gt;
sum=funcPtr(1,2);&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.5in;&quot;&gt;
printf(&quot;\nSum=%d\n&quot;,sum);&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.5in;&quot;&gt;
return 0;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.5in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.5in;&quot;&gt;
int func(int a,
int b)&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.5in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.5in;&quot;&gt;
return a+b;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0.14in; margin-left: 0.5in;&quot;&gt;
}&lt;/div&gt;
&lt;div class=&quot;western&quot; style=&quot;margin-bottom: 0.14in;&quot;&gt;
Simples Way to learn Data Structure in C++ CPP or C&lt;br /&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-for-cirrcular.html&quot;&gt;C++ Program for Circular Queue implementation using linked list&lt;/a&gt;&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-for-circular.html&quot;&gt;C++ program for Circular Queue implementation using Array&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-to-reverse.html&quot;&gt;&lt;b&gt;C++ program for reversing single Linked list nodes&amp;nbsp; &lt;/b&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-sorted-linked-list-program.html&quot;&gt;C++ Program for sorted single linked list with class&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-for-bst-binary.html&quot;&gt;C++ Program for&amp;nbsp;BST-Binary Search Tree&amp;nbsp;&amp;nbsp;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-implement-msgq-message-queue-in.html&quot;&gt;Previous&lt;/a&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; &lt;a href=&quot;http://howtocpp.com/&quot;&gt;Home&lt;/a&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; &lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-use-malloc-for-2d-array-dynamic.html&quot;&gt;Next&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;western&quot; style=&quot;margin-bottom: 0.14in;&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/3028800730389215847/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/04/how-to-use-function-pointer-in-cppcc.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/3028800730389215847'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/3028800730389215847'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/04/how-to-use-function-pointer-in-cppcc.html' title='How to use callback function pointer in cpp/C/C++'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16009977468138578543</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-2782932974377163522.post-3656444931752300927</id><published>2013-04-13T19:30:00.002+05:30</published><updated>2013-05-24T14:49:29.416+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="2d"/><category scheme="http://www.blogger.com/atom/ns#" term="dynamic memory allocation in C"/><category scheme="http://www.blogger.com/atom/ns#" term="multi dimensional array"/><title type='text'>How to use malloc for 2d array dynamic memory allocation</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;
 &lt;!--
  @page { margin: 0.79in }
  P { margin-bottom: 0.08in; direction: ltr; color: #000000; line-height: 115%; widows: 2; orphans: 2 }
  P.western { font-family: &quot;Calibri&quot;, sans-serif; font-size: 11pt; so-language: en-US }
  P.cjk { font-family: &quot;Calibri&quot;, sans-serif; font-size: 11pt }
  P.ctl { font-family: &quot;Times New Roman&quot;, serif; font-size: 11pt; so-language: ar-SA }
 &lt;/style&gt;
 &lt;br /&gt;
&lt;b&gt;/*How to
use malloc for 2d array dynamic memory allocation. How to write 2-d array with dynamic memory allocation */&lt;/b&gt;
&lt;br /&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include&amp;lt;malloc.h&amp;gt;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int main()&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int r,c,i,j;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;Enter
No of rows and columns:&quot;);&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
scanf(&quot;%d%d&quot;,&amp;amp;r,&amp;amp;c);&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int **array;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
array=(int**)&lt;b&gt;malloc&lt;/b&gt;(r*sizeof(int));&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
for(i=0;i&amp;lt;r;i++)&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
array[i]=&lt;b&gt;malloc&lt;/b&gt;(c*sizeof(int));&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;\n
Enter the elements 1 by 1:\n&quot;);&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
for(i=0;i&amp;lt;r;i++)&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
for(j=0;j&amp;lt;c;j++)&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
scanf(&quot;%d&quot;,&amp;amp;array[i][j]);&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
//
printf(&quot;\t&quot;);&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;You
Entered:\n&quot;);&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
for(i=0;i&amp;lt;r;i++)&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
for(j=0;j&amp;lt;c;j++)&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;%d&quot;,array[i][j]);&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;\t&quot;);&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;\n&quot;); 
&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
printf(&quot;\n&quot;);&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
/*&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
* $ ./a.out&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Enter No of
rows and columns:4&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
4&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Enter the
elements 1 by 1:&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
1&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
2&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
3&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
4&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
5&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
6&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
7&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
8&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
8&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
8&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
8&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
8&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
1&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
1&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
1&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
1&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
You Entered:&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
1       2   
   3       4&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
5       6   
   7       8&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
8       8   
   8       8&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
1       1   
   1       1&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Dynamic
memory allocation for multi dimensional array here for 2-d ( two
dimensional array).There are
various ways to allocate memory dynamically for multi dimensional
array:&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;1.
Pointer to pointer&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;First
memory is allocated for &lt;b&gt;array&lt;/b&gt; which contains pointers to array
to integers.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Then,
memory is allocated for the &lt;b&gt;each array&lt;/b&gt; pointed by the
pointers. &lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Finally
memory is de-allocated in the reverse order of the allocation.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Actually
we allocate memory for number of rows and then columns.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;table cellpadding=&quot;7&quot; cellspacing=&quot;0&quot; style=&quot;width: 92px;&quot;&gt;

 &lt;colgroup&gt;&lt;col width=&quot;15&quot;&gt;&lt;/col&gt;
 &lt;col width=&quot;16&quot;&gt;&lt;/col&gt;
 &lt;col width=&quot;16&quot;&gt;&lt;/col&gt;
 &lt;/colgroup&gt;&lt;tbody&gt;
&lt;tr valign=&quot;TOP&quot;&gt;
  &lt;td height=&quot;3&quot; style=&quot;border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: none; border-top: 1px solid #000000; padding-bottom: 0in; padding-left: 0.08in; padding-right: 0in; padding-top: 0in;&quot; width=&quot;15&quot;&gt;&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
  &lt;td style=&quot;border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: none; border-top: 1px solid #000000; padding-bottom: 0in; padding-left: 0.08in; padding-right: 0in; padding-top: 0in;&quot; width=&quot;16&quot;&gt;&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
  &lt;td style=&quot;border: 1px solid #000000; padding: 0in 0.08in;&quot; width=&quot;16&quot;&gt;&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;3&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr valign=&quot;TOP&quot;&gt;
  &lt;td height=&quot;3&quot; style=&quot;border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: none; border-top: 1px solid #000000; padding-bottom: 0in; padding-left: 0.08in; padding-right: 0in; padding-top: 0in;&quot; width=&quot;15&quot;&gt;&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;4&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
  &lt;td style=&quot;border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: none; border-top: 1px solid #000000; padding-bottom: 0in; padding-left: 0.08in; padding-right: 0in; padding-top: 0in;&quot; width=&quot;16&quot;&gt;&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;5&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
  &lt;td style=&quot;border: 1px solid #000000; padding: 0in 0.08in;&quot; width=&quot;16&quot;&gt;&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;6&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr valign=&quot;TOP&quot;&gt;
  &lt;td height=&quot;3&quot; style=&quot;border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: none; border-top: 1px solid #000000; padding-bottom: 0in; padding-left: 0.08in; padding-right: 0in; padding-top: 0in;&quot; width=&quot;15&quot;&gt;&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;7&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
  &lt;td style=&quot;border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: none; border-top: 1px solid #000000; padding-bottom: 0in; padding-left: 0.08in; padding-right: 0in; padding-top: 0in;&quot; width=&quot;16&quot;&gt;&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;8&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
  &lt;td style=&quot;border: 1px solid #000000; padding: 0in 0.08in;&quot; width=&quot;16&quot;&gt;&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;9&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr valign=&quot;TOP&quot;&gt;
  &lt;td height=&quot;3&quot; style=&quot;border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: none; border-top: 1px solid #000000; padding-bottom: 0in; padding-left: 0.08in; padding-right: 0in; padding-top: 0in;&quot; width=&quot;15&quot;&gt;&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;10&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
  &lt;td style=&quot;border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: none; border-top: 1px solid #000000; padding-bottom: 0in; padding-left: 0.08in; padding-right: 0in; padding-top: 0in;&quot; width=&quot;16&quot;&gt;&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;11&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
  &lt;td style=&quot;border: 1px solid #000000; padding: 0in 0.08in;&quot; width=&quot;16&quot;&gt;&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;12&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr valign=&quot;TOP&quot;&gt;
  &lt;td height=&quot;2&quot; style=&quot;border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: none; border-top: 1px solid #000000; padding-bottom: 0in; padding-left: 0.08in; padding-right: 0in; padding-top: 0in;&quot; width=&quot;15&quot;&gt;&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;13&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
  &lt;td style=&quot;border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: none; border-top: 1px solid #000000; padding-bottom: 0in; padding-left: 0.08in; padding-right: 0in; padding-top: 0in;&quot; width=&quot;16&quot;&gt;&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;14&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
  &lt;td style=&quot;border: 1px solid #000000; padding: 0in 0.08in;&quot; width=&quot;16&quot;&gt;&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;15&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;div class=&quot;western&quot; lang=&quot;&quot; style=&quot;margin-bottom: 0.14in;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;western&quot; lang=&quot;&quot; style=&quot;margin-bottom: 0.14in;&quot;&gt;
It can be
done by pointer to pinter to int.&lt;br /&gt;
example as above.&lt;/div&gt;
&lt;div class=&quot;western&quot; lang=&quot;&quot; style=&quot;margin-bottom: 0.14in;&quot;&gt;
Int **array;
//array is a pointer to pointer to int.&lt;/div&gt;
&lt;div class=&quot;western&quot; lang=&quot;&quot; style=&quot;margin-bottom: 0.14in; text-align: left;&quot;&gt;
Array is a pointer to pointer to int. it means that array first
points to pointers then in turn pointers point to integers. We need
to allocate enough memory for the pointers to hold ponters to
integers which nothing but memory for the rows. So dynamic memorty
allocation for 2d array would be like this.&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-use-function-pointer-in-cppcc.html&quot;&gt;Previous&lt;/a&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; &lt;a href=&quot;http://howtocpp.com/&quot;&gt;Home&lt;/a&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; &lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-use-new-to-allocate-memory-for.html&quot;&gt;Next&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/3656444931752300927/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/04/how-to-use-malloc-for-2d-array-dynamic.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/3656444931752300927'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/3656444931752300927'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/04/how-to-use-malloc-for-2d-array-dynamic.html' title='How to use malloc for 2d array dynamic memory allocation'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16009977468138578543</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-2782932974377163522.post-5252557341236255198</id><published>2013-04-13T19:26:00.000+05:30</published><updated>2013-05-24T14:51:33.662+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="2d"/><category scheme="http://www.blogger.com/atom/ns#" term="3d"/><category scheme="http://www.blogger.com/atom/ns#" term="multi dimensional array"/><title type='text'>How to use new to allocate memory for 3d array in CPP C++</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;
 &lt;!--
  @page { margin: 0.79in }
  P { margin-bottom: 0.08in; direction: ltr; color: #000000; line-height: 115%; widows: 2; orphans: 2 }
  P.western { font-family: &quot;Calibri&quot;, sans-serif; font-size: 11pt; so-language: en-US }
  P.cjk { font-family: &quot;Calibri&quot;, sans-serif; font-size: 11pt }
  P.ctl { font-family: &quot;Times New Roman&quot;, serif; font-size: 11pt; so-language: ar-SA }
 &lt;/style&gt;
 &lt;br /&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
/*How to
use new to allocate memory for 3d array. How to use malloc for 3 dimensional array. CPP program for dynamically allocating memory for 3d array. How to write three dimensional array with malloc with new */&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include&amp;lt;iostream&amp;gt;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
using
namespace std; 
&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int main()&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
// 3
Dimensions Array 
&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
//  two
3x4 array&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int x =
2, y = 3, z = 4;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int i,
j, k;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
// 
memory allocation for 3D&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int
***array3D = &lt;b&gt;new&lt;/b&gt; int**[x];&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
for(i =
0; i &amp;lt; x; i++)&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
array3D[i] = &lt;b&gt;new&lt;/b&gt; int*[y];&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
for(j = 0; j &amp;lt; y; j++)&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
array3D[i][j] = &lt;b&gt;new&lt;/b&gt; int[z];&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
// 
Accessing 3d array elements&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
for(i =
0; i &amp;lt; x; i++)&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout
&amp;lt;&amp;lt; i &amp;lt;&amp;lt; endl;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
for(j = 0; j &amp;lt; y; j++)&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout &amp;lt;&amp;lt; endl;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
for(k = 0; k &amp;lt; z; k++)&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
array3D[i][j][k] = (i * y * z) + (j * z) + k;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout &amp;lt;&amp;lt; &#39;\t&#39; &amp;lt;&amp;lt; array3D[i][j][k];&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout
&amp;lt;&amp;lt; endl &amp;lt;&amp;lt; endl;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
// 
deleting 3d array&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
for(i =
0; i &amp;lt; x; i++)&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
for(j = 0; j &amp;lt; y; j++)&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
delete[] array3D[i][j];&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
delete[] array3D[i];&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
delete[]
array3D;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
return 0;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
/*OP:&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
0&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
0   
   1       2       3&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
4   
   5       6       7&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
8   
   9       10      11&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
1&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
12  
   13      14      15&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
16  
   17      18      19&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
20  
   21      22      23&lt;/div&gt;
&lt;div lang=&quot;&quot; style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
*/&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-use-malloc-for-2d-array-dynamic.html&quot;&gt;Previous&lt;/a&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; &lt;a href=&quot;http://howtocpp.com/&quot;&gt;Home&lt;/a&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; &lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-learn-stack-and-flow-of-function.html&quot;&gt;Next&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/5252557341236255198/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/04/how-to-use-new-to-allocate-memory-for.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/5252557341236255198'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/5252557341236255198'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/04/how-to-use-new-to-allocate-memory-for.html' title='How to use new to allocate memory for 3d array in CPP C++'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16009977468138578543</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-2782932974377163522.post-8115619007373444953</id><published>2013-04-11T16:01:00.003+05:30</published><updated>2013-05-24T15:03:05.347+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="recursive"/><category scheme="http://www.blogger.com/atom/ns#" term="stack"/><title type='text'>How to learn stack and flow of function call and control in cpp</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
/*How to learn stack. Stack is memory in which Last in first out is followed.&lt;br /&gt;
When function call is encountered the address of the next statement is stored or pushed in the stack. When the control returns back from the definition to calling function the address is poped out which is nothing but the statement next to the function call and executed.*/&lt;br /&gt;
#include&amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include&amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
void function1();&lt;br /&gt;
void function2();&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
printf(&quot;1\n&quot;);&lt;br /&gt;
printf(&quot;2\n&quot;);&lt;br /&gt;
function1();&lt;br /&gt;
printf(&quot;3\n&quot;);&lt;br /&gt;
printf(&quot;4\n&quot;);&lt;br /&gt;
&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
void function1()&lt;br /&gt;
{&lt;br /&gt;
printf(&quot;1.1\n&quot;);&lt;br /&gt;
printf(&quot;1.2\n&quot;);&lt;br /&gt;
function2();&lt;br /&gt;
printf(&quot;1.3\n&quot;);&lt;br /&gt;
printf(&quot;1.4\n&quot;);&lt;br /&gt;
}&lt;br /&gt;
void function2()&lt;br /&gt;
{&lt;br /&gt;
printf(&quot;2.1\n&quot;);&lt;br /&gt;
printf(&quot;2.2\n&quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
/*&lt;br /&gt;
1&lt;br /&gt;
2&lt;br /&gt;
1.1&lt;br /&gt;
1.2&lt;br /&gt;
2.1&lt;br /&gt;
2.2&lt;br /&gt;
1.3&lt;br /&gt;
1.4&lt;br /&gt;
3&lt;br /&gt;
4&lt;br /&gt;
*/&lt;br /&gt;
/*&lt;br /&gt;
First 1 and 2 gets printed then function1 gets called and address of 3 gets stored instack.Now in inside function1 1.1 and 1.2 gets printed and function2 gets called and address of 1.3 gets stored in stack. Now inside function2 2.1 and 2.2 gets printed. Then as stack is LIFO so the last address ie of 1.3 was stored in stack so 1.3 followed by 1.4 is printed. Before the address of 1.3 address of 3 was stored in stack so now 3 and the next statement 4 gets printed&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-use-new-to-allocate-memory-for.html&quot;&gt;Previous&lt;/a&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; &lt;a href=&quot;http://howtocpp.com/&quot;&gt;Home&lt;/a&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; &lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-learn-stack-and-flow-of-funhttp://www.howtocpp.com/2013/04/how-to-learn-recursive-function-call-in.htmlction.html&quot;&gt;Next&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/8115619007373444953/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/04/how-to-learn-stack-and-flow-of-function.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/8115619007373444953'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/8115619007373444953'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/04/how-to-learn-stack-and-flow-of-function.html' title='How to learn stack and flow of function call and control in cpp'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16009977468138578543</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-2782932974377163522.post-2502502154847830243</id><published>2013-04-11T15:57:00.003+05:30</published><updated>2013-05-24T15:04:33.852+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="recursive"/><category scheme="http://www.blogger.com/atom/ns#" term="stack"/><title type='text'>How to learn recursive function call in cpp/C++/C</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
/*How to learn recursive function call in cpp/C++/C&lt;br /&gt;
&amp;nbsp;Cpp Program to learn recursive function */&lt;br /&gt;
#include&amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int sum(int m, int k);&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
int i,m,k;&lt;br /&gt;
m=3;&lt;br /&gt;
k=2;&lt;br /&gt;
i=sum(m,k);&lt;br /&gt;
cout&amp;lt;&amp;lt;&quot;sum=&quot;&amp;lt;&amp;lt;i&amp;lt;&amp;lt;endl;&lt;br /&gt;
//return 0;&lt;br /&gt;
}&lt;br /&gt;
int sum(int rm, int rk)&lt;br /&gt;
{&lt;br /&gt;
cout&amp;lt;&amp;lt;rm&amp;lt;&amp;lt;&quot; &quot;&amp;lt;&amp;lt;rk&amp;lt;&amp;lt;endl;&lt;br /&gt;
if(rm==0) return(rk);//termination condition&lt;br /&gt;
else return(1+sum(rk, rm-1));//recursive condition//if not +1 then sum=0&lt;br /&gt;
}&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
/*&lt;br /&gt;
3 2&lt;br /&gt;
2 2&lt;br /&gt;
2 1&lt;br /&gt;
1 1&lt;br /&gt;
1 0&lt;br /&gt;
0 0&lt;br /&gt;
sum=5 //in stack first address of sum(3,2) was stored&lt;br /&gt;
*/&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-learn-stack-and-flow-of-function.html&quot;&gt;Previous&lt;/a&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; &lt;a href=&quot;http://howtocpp.com/&quot;&gt;Home&lt;/a&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; &lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-distinguish-between-call-by.html&quot;&gt;Next&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/2502502154847830243/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/04/how-to-learn-recursive-function-call-in.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/2502502154847830243'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/2502502154847830243'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/04/how-to-learn-recursive-function-call-in.html' title='How to learn recursive function call in cpp/C++/C'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16009977468138578543</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-2782932974377163522.post-2497547120991856326</id><published>2013-04-11T14:14:00.001+05:30</published><updated>2013-05-24T15:06:48.634+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="call by address"/><category scheme="http://www.blogger.com/atom/ns#" term="call by reference in C++"/><category scheme="http://www.blogger.com/atom/ns#" term="call by value"/><category scheme="http://www.blogger.com/atom/ns#" term="pass by address"/><category scheme="http://www.blogger.com/atom/ns#" term="pass by reference"/><category scheme="http://www.blogger.com/atom/ns#" term="pass by value"/><title type='text'>How to distinguish between call by value, call by reference, call by address</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
/*How to distinguish between call by value, call by reference, call by address.&lt;br /&gt;
Program to distinguish between pass by value,pass by reference,pass by address. Call by reference and call by address affects the calling value while call by value doe not. Most important difference is that in call by value new object is created which is some times such as when size of the variable is too large is not desirable so call by reference is preferred over call by value*/&lt;br /&gt;
&lt;br /&gt;
#include&amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include&amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
void callbyreference(int * x);//pass by address&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
int x;&lt;br /&gt;
x=10;&lt;br /&gt;
printf(&quot;Before x=%d&quot;,x);//10&lt;br /&gt;
callbyvalue(&amp;amp;x);&lt;br /&gt;
printf(&quot;\nAfter x=%d&quot;,x);//15&lt;br /&gt;
printf(&quot;\n&quot;);&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void callbyreference(int * x)&lt;br /&gt;
{&lt;br /&gt;
*x=*x+5;//mind the*&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
//CALL BY REFERNCE, PASS BY REFERNCE&lt;br /&gt;
/*&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
void callbyrefernce(int &amp;amp; x);&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
int x;&lt;br /&gt;
x=10;&lt;br /&gt;
printf(&quot;Before x=%d&quot;,x);//10&lt;br /&gt;
callbyrefernce(x);//pass by refernce&lt;br /&gt;
printf(&quot;\nAfter x=%d&quot;,x);//15&lt;br /&gt;
printf(&quot;\n&quot;);&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void callbyvalue(int &amp;amp; x)&lt;br /&gt;
{&lt;br /&gt;
x=x+5;&lt;br /&gt;
}&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
//CALL BY VALUE, PASS BY VALUE&lt;br /&gt;
/*&lt;br /&gt;
void callbyvalue(int&amp;nbsp; x);&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
int x;&lt;br /&gt;
x=10;&lt;br /&gt;
printf(&quot;Before x=%d&quot;,x);//10&lt;br /&gt;
callbyvalue(x);//pass by value&lt;br /&gt;
printf(&quot;\nAfter x=%d&quot;,x);//10&lt;br /&gt;
printf(&quot;\n&quot;);&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void callbyvalue(int&amp;nbsp; x)&lt;br /&gt;
{&lt;br /&gt;
x=x+5;&lt;br /&gt;
}&lt;br /&gt;
*/&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-learn-recursive-function-call-in.html&quot;&gt;Previous&lt;/a&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; &lt;a href=&quot;http://howtocpp.com/&quot;&gt;Home&lt;/a&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; &lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-for-circular.html&quot;&gt;Next&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/2497547120991856326/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/04/how-to-distinguish-between-call-by.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/2497547120991856326'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/2497547120991856326'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/04/how-to-distinguish-between-call-by.html' title='How to distinguish between call by value, call by reference, call by address'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16009977468138578543</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-2782932974377163522.post-1698915014217525282</id><published>2013-03-30T20:15:00.000+05:30</published><updated>2013-05-24T15:09:41.621+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Circular Queue"/><category scheme="http://www.blogger.com/atom/ns#" term="Circular Queue using Array"/><category scheme="http://www.blogger.com/atom/ns#" term="Data Structure"/><category scheme="http://www.blogger.com/atom/ns#" term="Queue"/><title type='text'>How to write cpp program for Circular Queue using Array</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;
 &lt;!--
  @page { margin: 0.79in }
  P { margin-bottom: 0.08in; direction: ltr; color: #000000; widows: 2; orphans: 2 }
 &lt;/style&gt;
 &lt;br /&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
How to write C++ program for Circular Queue using Array&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
C++ program to implement Circular Queue using Array&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Circular Queue implementation using Array&lt;br /&gt;
CPP program for implementing Circular Queue using Array&lt;/div&gt;
&lt;br /&gt;
&lt;style type=&quot;text/css&quot;&gt;
 &lt;!--
  @page { margin: 0.79in }
  P { margin-bottom: 0.08in; direction: ltr; color: #000000; widows: 2; orphans: 2 }
 &lt;/style&gt;
 &lt;br /&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include&amp;lt;iostream&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
using namespace std;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#define MAXSIZE 4&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
class queue&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
private:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int
cq[MAXSIZE];&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int front,
rear;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
public:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
queue()&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int
cq[MAXSIZE]={0};//error: array must be initialized with a
brace-enclosed initializer&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
front=
-1;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
rear =
-1;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void insert(int
item)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;\n
in insert.\t&quot;;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(  (
(front==0)&amp;amp;&amp;amp;(rear==MAXSIZE-1)%MAXSIZE )    ||   
front==(rear+1)%MAXSIZE    )&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;Q
is full.\n&quot;;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
else&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(front==-1)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
front=rear=0;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
else&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
rear=(rear+1)%MAXSIZE;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cq[rear]=item;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;\n
front = &quot;&amp;lt;&amp;lt;front&amp;lt;&amp;lt;&quot; rear = &quot;&amp;lt;&amp;lt;rear&amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void display()&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int i;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
for(i=0;i&amp;lt;MAXSIZE;i++)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;cq[i]&amp;lt;&amp;lt;&quot; &quot;;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void deletee()&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(front==-1)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;Q
is empty.\n&quot;;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
else&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int temp;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
temp=cq[front];&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cq[front]=0;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(front==rear)//only 1 elt was there&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
front=rear=-1;//delete the single so q is empty&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
else&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
front=(front+1)%MAXSIZE;//if more than 1 elt then delete frm front&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;\n
Deleted elt is:&quot;&amp;lt;&amp;lt;temp&amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;\n
front = &quot;&amp;lt;&amp;lt;front&amp;lt;&amp;lt;&quot; rear = &quot;&amp;lt;&amp;lt;rear&amp;lt;&amp;lt;endl;
   
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
};&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int main()&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
queue q;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
q.insert(10);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
q.insert(20);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
q.insert(30);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
q.insert(40);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
q.display();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
q.insert(111);//Q is full so make same place by deleting fronts&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
q.display();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
q.deletee();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
q.display();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
q.insert(100);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
q.display();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
return 0;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
/*&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
in insert.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
front = 0  rear = 0&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
in insert.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
front = 0  rear = 1&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
in insert.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
front = 0  rear = 2&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
in insert.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
front = 0  rear = 3&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
10      20      30  
   40&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
in insert.     Q is
full.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
10      20      30  
   40&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Deleted elt is 10.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
front = 1  rear = 3&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
0       20      30  
   40&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
in insert.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
front = 1  rear = 0&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
100     20      30  
   40&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
*/&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;Simples Way to learn Data Structure in C++ CPP or C&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-sorted-linked-list-program.html&quot;&gt;C++ Program for sorted single linked list with class&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-for-bst-binary.html&quot;&gt;C++ Program for&amp;nbsp;BST-Binary Search Tree&amp;nbsp;&amp;nbsp; &lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-for-cirrcular.html&quot;&gt;C++ Program for Circular Queue implementation using linked list&lt;/a&gt;&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-for-circular.html&quot;&gt;C++ program for Circular Queue implementation using Array&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-to-reverse.html&quot;&gt;&lt;b&gt;C++ program for reversing single Linked list nodes&amp;nbsp; &lt;/b&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-sorted-linked-list-program.html&quot;&gt;C++ Program for sorted single linked list with class&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-for-bst-binary.html&quot;&gt;C++ Program for&amp;nbsp;BST-Binary Search Tree&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/04/how-to-distinguish-between-call-by.html&quot;&gt;Previous&lt;/a&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; &lt;a href=&quot;http://howtocpp.com/&quot;&gt;Home&lt;/a&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; &lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-for-cirrcular.html&quot;&gt;Next&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/1698915014217525282/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/03/how-to-write-cpp-program-for-circular.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/1698915014217525282'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/1698915014217525282'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/03/how-to-write-cpp-program-for-circular.html' title='How to write cpp program for Circular Queue using Array'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16009977468138578543</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-2782932974377163522.post-7164140848821265962</id><published>2013-03-30T20:09:00.001+05:30</published><updated>2013-05-24T15:11:18.208+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Circular Que using Linked List"/><category scheme="http://www.blogger.com/atom/ns#" term="Circular Queue"/><category scheme="http://www.blogger.com/atom/ns#" term="Data Structure"/><category scheme="http://www.blogger.com/atom/ns#" term="Queue"/><title type='text'>How to write cpp program for Circular Queue using Linked List</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;
 &lt;!--
  @page { margin: 0.79in }
  P { margin-bottom: 0.08in; direction: ltr; color: #000000; widows: 2; orphans: 2 }
 &lt;/style&gt;
 &lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&amp;nbsp;/*C++ Program for Circular Queue
implementation using linked list&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Cpp program to implement Circular Queue using Linked List*/&lt;br /&gt;
C++ Program for implementing Circular Queue with Linked List&lt;/div&gt;
&lt;style type=&quot;text/css&quot;&gt;
 &lt;!--
  @page { margin: 0.79in }
  P { margin-bottom: 0.08in; direction: ltr; color: #000000; widows: 2; orphans: 2 }
 &lt;/style&gt;
 &lt;br /&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include&amp;lt;iostream&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
using namespace std;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
class queue&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
private:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
struct node&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int
data;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node*
link;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
};          
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node *front;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node *rear;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
public:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void
insert(int);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void
display();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void del();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
queue()&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; 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;line-height: 100%; margin-bottom: 0in;&quot;&gt;
front=NULL;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
front=NULL;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
};&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void
queue::insert(int d)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
//cout&amp;lt;&amp;lt;&quot;insert
called\n&quot;;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node
*newnode=new node;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
newnode-&amp;gt;data=d;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
newnode-&amp;gt;link=NULL;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(front==NULL)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
front=rear=newnode;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
else&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
rear-&amp;gt;link=newnode;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
rear=newnode;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void
queue::display()&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(front==NULL){cout&amp;lt;&amp;lt;&quot;Queue is empty.\n&quot;;}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
else&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node *ptr;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
ptr=front;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
while(ptr)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;ptr-&amp;gt;data&amp;lt;&amp;lt;&quot; &quot;;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
ptr=ptr-&amp;gt;link;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void queue::del()&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node* temp;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
temp=front;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(front==NULL){cout&amp;lt;&amp;lt;&quot;Queue is Empty.\n&quot;;}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
else&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node* temp;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
temp=front;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
front=front-&amp;gt;link;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
//rear-&amp;gt;link=front;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
delete temp;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int main()&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
queue q;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
q.insert(10);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
q.insert(20);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
q.insert(100);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
q.insert(40);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
q.insert(300);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
q.display();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
q.del();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
q.display();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
return 0;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
/*&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
10 20 100 40 300&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
20 100 40 300&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
*/&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;Simples Way to learn Data Structure in C++ CPP or C&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-sorted-linked-list-program.html&quot;&gt;C++ Program for sorted single linked list with class&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-for-bst-binary.html&quot;&gt;C++ Program for&amp;nbsp;BST-Binary Search Tree&amp;nbsp;&amp;nbsp; &lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=2782932974377163522&quot; name=&quot;more&quot;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-for-cirrcular.html&quot;&gt;C++ Program for Circular Queue implementation using linked list&lt;/a&gt;&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-for-circular.html&quot;&gt;C++ program for Circular Queue implementation using Array&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-to-reverse.html&quot;&gt;&lt;b&gt;C++ program for reversing single Linked list nodes&amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-for-circular.html&quot;&gt;Previous&lt;/a&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; &lt;a href=&quot;http://howtocpp.com/&quot;&gt;Home&lt;/a&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; &lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-for-bst-binary.html&quot;&gt;Next&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-for-bst-binary.html&quot;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/7164140848821265962/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/03/how-to-write-cpp-program-for-cirrcular.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/7164140848821265962'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/7164140848821265962'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/03/how-to-write-cpp-program-for-cirrcular.html' title='How to write cpp program for Circular Queue using Linked List'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16009977468138578543</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-2782932974377163522.post-1149481081295763274</id><published>2013-03-30T20:04:00.000+05:30</published><updated>2013-05-24T15:16:08.323+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Binary Search Tree"/><category scheme="http://www.blogger.com/atom/ns#" term="BST"/><category scheme="http://www.blogger.com/atom/ns#" term="Data Structure"/><title type='text'>How to write cpp program for BST Binary Search Tree</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;
 &lt;!--
  @page { margin: 0.79in }
  P { margin-bottom: 0.08in; direction: ltr; color: #000000; widows: 2; orphans: 2 }
 &lt;/style&gt;
 &lt;br /&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
/*BST-Binary Search Tree Program for&amp;nbsp; insertion and
traversal&lt;br /&gt;
How to write C++ Program for BST-Binary Search Tree&lt;br /&gt;
Cpp program for BST Binary Search Tree implementation with class*/&lt;br /&gt;
&lt;style type=&quot;text/css&quot;&gt;
 &lt;!--
  @page { margin: 0.79in }
  P { margin-bottom: 0.08in; direction: ltr; color: #000000; widows: 2; orphans: 2 }
 &lt;/style&gt;
 &lt;/div&gt;
--&amp;gt;


&lt;br /&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
//bst-Binary Search
tree&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include&amp;lt;iostream&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
using namespace std;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
class BST&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
private:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
struct node&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int
data;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node
*left;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node
*right;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
};&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node* start;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
public:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
BST(){start=NULL;}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void
insert(int data);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void
traverse();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void
inorder(node *);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void
preorder(node *);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void
postorder(node *);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
};&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void BST::
insert(int d)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node
*newnode;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
newnode=new
node;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
newnode-&amp;gt;data=d;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
newnode-&amp;gt;left=NULL;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
newnode-&amp;gt;right=NULL;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node *ptr;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
ptr=start;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(start==NULL)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
start=newnode;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
else&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
while(ptr!=NULL)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(d&amp;lt;ptr-&amp;gt;data)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(ptr-&amp;gt;left==NULL)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
ptr-&amp;gt;left=newnode;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
ptr=NULL;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
else&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
ptr=ptr-&amp;gt;left;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
else&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
//if(d&amp;gt;ptr-&amp;gt;data)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
//{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(ptr-&amp;gt;right==NULL)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
ptr-&amp;gt;right=newnode;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
ptr=NULL;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
else&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
ptr=ptr-&amp;gt;right;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
// }&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void BST::traverse()&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;\n
Inorder:\n&quot;;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
inorder(start);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;\n
Preorder:\n&quot;;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
preorder(start);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;\n
Postorder:\n&quot;;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
postorder(start);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void
BST::inorder(node *ptr)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(ptr!=NULL)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
inorder(ptr-&amp;gt;left);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;ptr-&amp;gt;data&amp;lt;&amp;lt;&quot;\t&quot;;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
inorder(ptr-&amp;gt;right);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void
BST::preorder(node *ptr)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(ptr!=NULL)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;ptr-&amp;gt;data&amp;lt;&amp;lt;&quot;\t&quot;;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
preorder(ptr-&amp;gt;left);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
preorder(ptr-&amp;gt;right);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void
BST::postorder(node *ptr)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(ptr!=NULL)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
postorder(ptr-&amp;gt;left);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
postorder(ptr-&amp;gt;right);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;ptr-&amp;gt;data&amp;lt;&amp;lt;&quot;\t&quot;;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int main()&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
BST b;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
b.insert(8);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
b.insert(3);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
b.insert(10);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
b.insert(1);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
b.insert(6);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
b.insert(7);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
b.insert(4);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
b.insert(10);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
b.insert(14);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
b.insert(13);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
b.traverse();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
return 0;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
/*&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
$ g++
bst_revision.cxx&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
$ ./a.out&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Inorder:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
1       3       4   
   6       7       8       10      10      13      14&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Preorder:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
8       3       1   
   6       4       7       10      10      14      13&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Postorder:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
1       4       7   
   6       3       13      14      10      10      8 
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
*&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhu3olvOetJxHvBsdXn66Xs5HXzw_LikCpi62GIz5SVEzH6N8B4QiH1BiEdn2n3sHsIEBcUBAwVfb8rAkZuHP1nWj5aWEgk5p-U-xCYRF_N_9c4pKhbiB8zOEPhNLbRlZbpzjDAyoX88dg/s1600/tree.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;159&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhu3olvOetJxHvBsdXn66Xs5HXzw_LikCpi62GIz5SVEzH6N8B4QiH1BiEdn2n3sHsIEBcUBAwVfb8rAkZuHP1nWj5aWEgk5p-U-xCYRF_N_9c4pKhbiB8zOEPhNLbRlZbpzjDAyoX88dg/s200/tree.png&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;
&lt;br /&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Depth-first&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;div style=&quot;line-height: 100%; margin-bottom: 0.02in; margin-top: 0.02in;&quot;&gt;
&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Pre-order traversal
 sequence: F, B, A, D, C, E, G, I, H (root, left, right)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;line-height: 100%; margin-bottom: 0.02in; margin-top: 0.02in;&quot;&gt;
&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;In-order traversal
 sequence: A, B, C, D, E, F, G, H ,I (left, root, right)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;line-height: 100%; margin-bottom: 0.02in; margin-top: 0.02in;&quot;&gt;
&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Post-order
 traversal sequence: A, C, E, D, B, H, I, G, F (left, right, root)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Breadth-first&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;div style=&quot;line-height: 100%; margin-bottom: 0.02in; margin-top: 0.02in;&quot;&gt;
&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Level-order
 traversal sequence: F, B, G, A, D, I, C, E, H&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Inorder:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
1 2 3 4 5 6 7 8 9&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Pre order:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
6 2 14 3 5 7 9 8&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Post order:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
1 3 5 4 2 8 9 7 6&lt;br /&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;Simples Way to learn Data Structure in C++ CPP or C&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=2782932974377163522&quot; name=&quot;more&quot;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-for-cirrcular.html&quot;&gt;C++ Program for Circular Queue implementation using linked list&lt;/a&gt;&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-for-circular.html&quot;&gt;C++ program for Circular Queue implementation using Array&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-to-reverse.html&quot;&gt;&lt;b&gt;C++ program for reversing single Linked list nodes&amp;nbsp; &lt;/b&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-sorted-linked-list-program.html&quot;&gt;C++ Program for sorted single linked list with class&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-for-bst-binary.html&quot;&gt;C++ Program for&amp;nbsp;BST-Binary Search Tree&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-for-cirrcular.html&quot;&gt;Previous&lt;/a&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; &lt;a href=&quot;http://howtocpp.com/&quot;&gt;Home&lt;/a&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; &lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-to-reverse.html&quot;&gt;Next&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/1149481081295763274/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/03/how-to-write-cpp-program-for-bst-binary.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/1149481081295763274'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/1149481081295763274'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/03/how-to-write-cpp-program-for-bst-binary.html' title='How to write cpp program for BST Binary Search Tree'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16009977468138578543</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/AVvXsEhu3olvOetJxHvBsdXn66Xs5HXzw_LikCpi62GIz5SVEzH6N8B4QiH1BiEdn2n3sHsIEBcUBAwVfb8rAkZuHP1nWj5aWEgk5p-U-xCYRF_N_9c4pKhbiB8zOEPhNLbRlZbpzjDAyoX88dg/s72-c/tree.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2782932974377163522.post-5294233822391447775</id><published>2013-03-30T19:57:00.001+05:30</published><updated>2013-05-24T15:19:58.588+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="linked list"/><category scheme="http://www.blogger.com/atom/ns#" term="single linked list"/><category scheme="http://www.blogger.com/atom/ns#" term="sorted linked list"/><title type='text'>How to write cpp program to reverse a linked list</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;
 &lt;!--
  @page { margin: 0.79in }
  P { margin-bottom: 0.08in; direction: ltr; color: #000000; line-height: 115%; widows: 2; orphans: 2 }
  P.western { font-family: &quot;Calibri&quot;, sans-serif; font-size: 11pt; so-language: en-US }
  P.cjk { font-family: &quot;Calibri&quot;, sans-serif; font-size: 11pt; so-language: zh-CN }
  P.ctl { font-family: &quot;Calibri&quot;, sans-serif; font-size: 11pt; so-language: ar-SA }
 &lt;/style&gt;
 &lt;br /&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;
&lt;b&gt;//C++ program for reversing single Linked list nodes&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
Cpp program for implement reversing Single Linked List&lt;br /&gt;
Single linked list program for reversing the nodes&lt;br /&gt;
How to reverse linked list&amp;nbsp;
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include&amp;lt;iostream&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
using namespace std;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;b&gt;struct node&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node *next;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int data;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
};&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;b&gt;class ll&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
private:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node *start;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
public:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
ll(){start=NULL;}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void insert(int a)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;Inside
Insert.&quot;&amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node *newnode=new
node;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
newnode-&amp;gt;data=a;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
newnode-&amp;gt;next=start;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
start=newnode;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
//return;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void display();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void del();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void reverse();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; 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;line-height: 100%; margin-bottom: 0in;&quot;&gt;
//void
ll::insert(int a){data=a;}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;b&gt;void
ll::display()&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;Inside
display.&quot;&amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node *curr=new node;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
curr=start;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
while(curr!=NULL)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;curr-&amp;gt;data&amp;lt;&amp;lt;&quot;
&quot;;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
curr=curr-&amp;gt;next;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;b&gt;void ll::del()&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;Inside
del.&quot;&amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node *temp=new node;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
temp=start;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
start=start-&amp;gt;next;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
delete temp;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;b&gt;void
ll::reverse()&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;Inside
reverse.&quot;&amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node *next=new node;
next=NULL;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node *result=new
node; result=NULL;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node *current=new
node;current=start;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
while(current!=NULL)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
next=current-&amp;gt;next;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
current-&amp;gt;next=result;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
result=current;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
current=next;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
start=result;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;b&gt;int main()&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
ll l;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
l.insert(10);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
l.insert(20);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
l.insert(30);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
l.insert(40);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
l.display();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
l.reverse();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
l.display();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
l.del();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
l.display();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
return 0;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
/* Inside Insert.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Inside Insert.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Inside Insert.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Inside Insert.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Inside display.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
40 30 20 10&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Inside reverse.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Inside display.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
10 20 30 40&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Inside del.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Inside display.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
20 30 40&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
*/&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-sorted-linked-list-program.html&quot;&gt;Previous&lt;/a&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; &lt;a href=&quot;http://howtocpp.com/&quot;&gt;Home&lt;/a&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; &lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-to-reverse.html&quot;&gt;Next&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/5294233822391447775/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/03/how-to-write-cpp-program-to-reverse.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/5294233822391447775'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/5294233822391447775'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/03/how-to-write-cpp-program-to-reverse.html' title='How to write cpp program to reverse a linked list'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16009977468138578543</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-2782932974377163522.post-5950875807675346653</id><published>2013-03-30T19:42:00.002+05:30</published><updated>2013-05-24T15:22:34.486+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="linked listed"/><category scheme="http://www.blogger.com/atom/ns#" term="single linked list"/><category scheme="http://www.blogger.com/atom/ns#" term="sorted linked list"/><title type='text'>How to write sorted linked list program in cpp with class</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;
 &lt;!--
  @page { margin: 0.79in }
  P { margin-bottom: 0.08in; direction: ltr; color: #000000; widows: 2; orphans: 2 }
 &lt;/style&gt;
 &lt;br /&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
How to write sorted linked list program in cpp with class&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
C++ Program for sorted single linked list with class &lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
//sorted linked list
latest&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include&amp;lt;iostream&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
using namespace std;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
struct node&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int data;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node *next;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
};&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node *start=NULL;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void insert(int d)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node
*newnode=new node;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
newnode-&amp;gt;data=d;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
newnode-&amp;gt;next=NULL;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
//insert as
first elt&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(start==NULL)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; 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;line-height: 100%; margin-bottom: 0in;&quot;&gt;
//start-&amp;gt;next=newnode;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
start=newnode;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
//insert before
first elt&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(newnode-&amp;gt;data
&amp;lt; start-&amp;gt;data)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
newnode-&amp;gt;next=start;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
start=newnode;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
return;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
//inserting at
middle&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node* prev; node
*ptr;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
for(prev=start,ptr=start-&amp;gt;next;ptr;prev=ptr,ptr=prev-&amp;gt;next)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(newnode-&amp;gt;data &amp;lt; ptr-&amp;gt;data)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
prev-&amp;gt;next=newnode;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
newnode-&amp;gt;next=ptr;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
return;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
//inserting at
last&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(ptr==NULL)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
prev-&amp;gt;next=newnode;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
newnode-&amp;gt;next=NULL;//must&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
return;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void display()&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node *ptr=start;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
while(ptr!=NULL)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;ptr-&amp;gt;data&amp;lt;&amp;lt;&quot; &quot;;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
ptr=ptr-&amp;gt;next;//must else infinite loop&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void deleteNode()&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int key;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;Enter
elt to delete:&quot;&amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cin&amp;gt;&amp;gt;key;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
//deleting the first
node&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(key==start-&amp;gt;data)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node *temp;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
temp=start;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
start=start-&amp;gt;next;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
delete temp;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
return;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
//deleting middle
node&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
node *ptr; node
*prev;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
for(prev=start,ptr=start-&amp;gt;next;ptr;prev=ptr,ptr=prev-&amp;gt;next)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(ptr-&amp;gt;data==key)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
prev-&amp;gt;next=ptr-&amp;gt;next;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
delete ptr;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
return;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
//deleteing last elt
means data not present&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(ptr==NULL)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;key
&quot;&amp;lt;&amp;lt;key&amp;lt;&amp;lt;&quot; Not present in LL.\n&quot;;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
return;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
if(start==NULL)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;No
Element to delete&quot;&amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
return;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int main()&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
insert(10);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
insert(4);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
insert(8);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
insert(9);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
insert(6);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
insert(7);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
insert(25);&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
display();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
deleteNode();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
display();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
deleteNode();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
deleteNode();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
deleteNode();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
deleteNode();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
deleteNode();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
deleteNode();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
deleteNode();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
deleteNode();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
deleteNode();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
return 0;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
/* Output:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
$ ./a.out&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
4 6 7 8 9 10 25&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Enter elt to delete:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
100&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
key 100 Not present
in LL.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
4 6 7 8 9 10 25&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Enter elt to delete:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
9&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Enter elt to delete:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
9&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
key 9 Not present in
LL.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Enter elt to delete:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
10&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Enter elt to delete:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
4&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Enter elt to delete:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
25&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Enter elt to delete:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
6&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Enter elt to delete:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
7&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Enter elt to delete:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
8&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
*/&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-cpp-program-to-reverse.html&quot;&gt;Previous&lt;/a&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; &lt;a href=&quot;http://howtocpp.com/&quot;&gt;Home&lt;/a&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; &lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-see-vtable-virtual-table-for.html&quot;&gt;Next&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/5950875807675346653/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/03/how-to-write-sorted-linked-list-program.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/5950875807675346653'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/5950875807675346653'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/03/how-to-write-sorted-linked-list-program.html' title='How to write sorted linked list program in cpp with class'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16009977468138578543</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-2782932974377163522.post-4930715238102691361</id><published>2013-03-30T19:34:00.002+05:30</published><updated>2013-05-24T15:24:16.730+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="virtual destructor"/><category scheme="http://www.blogger.com/atom/ns#" term="virtual function"/><category scheme="http://www.blogger.com/atom/ns#" term="virtual pointer"/><category scheme="http://www.blogger.com/atom/ns#" term="virtual table"/><category scheme="http://www.blogger.com/atom/ns#" term="vptr"/><category scheme="http://www.blogger.com/atom/ns#" term="vtable"/><title type='text'>How to see vtable virtual table  for virtual functions in cpp</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;
 &lt;!--
  @page { margin: 0.79in }
  P { margin-bottom: 0.08in; direction: ltr; color: #000000; widows: 2; orphans: 2 }
 &lt;/style&gt;
 &lt;br /&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Virtual table is look up table for virtual functions. It contains the function pointer to the virtual functions. Virtual table is created for each class having one or more virtual function and classes derived from that class.virtual pointer better known as vptr containing the address of vtable is created for the most base class thats why size of empty class with virtual function is equal to the size of a pointer(8 bytes for a 64 bit computer)while size of a empty class without any virtual functions is only one byte.&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Command to see
vtable/virtual table of a class. &lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Here if the name of the program is &quot;classWithVf.cxx&quot; so the command to see the vtable of the class is: &lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
g++
-fdump-class-hierarchy classWithVf.cxx&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
#include&amp;lt;iostream&amp;gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
using namespace std;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
class M  //empty
class&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
public:  
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void f() {}
 
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
};&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
class A //empty
class&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; 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;line-height: 100%; margin-bottom: 0in;&quot;&gt;
public:  
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void f() {}
 
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
};&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
class B//empty class
with 1 vf&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
public:  
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
virtual void
f() {}  
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
};&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
class B1//class with
1 vf 1 dm&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
private:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
char x1;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
public:  
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
virtual void
f1() {}  
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
};&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
class D : public B1&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
private:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
char z;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
public:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void f1()
{}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
};&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
class B2//clas
without vf 1dm&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
private:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
char a;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
public:  
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void f2() {}
 
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
};&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
class B3&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
private:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
char b31;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
public:  
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
void f3() {}
 
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
};&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
int main ()&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
M m;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;size
 of m:&quot;&amp;lt;&amp;lt;sizeof(m)&amp;lt;&amp;lt;endl;// 1 obj with def constr&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;size
 of M:&quot;&amp;lt;&amp;lt;sizeof(M)&amp;lt;&amp;lt;endl;// 1&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
A *a=new A;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;size
 of a:&quot;&amp;lt;&amp;lt;sizeof(a)&amp;lt;&amp;lt;endl;// 8 object with new so a
 is ptr here&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;size
 of A:&quot;&amp;lt;&amp;lt;sizeof(A)&amp;lt;&amp;lt;endl;// 1&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
B b;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;size
 of b:&quot;&amp;lt;&amp;lt;sizeof(b)&amp;lt;&amp;lt;endl;// 8 empty class with vf&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;b&gt;cout&amp;lt;&amp;lt;&quot;size
 of B:&quot;&amp;lt;&amp;lt;sizeof(B)&amp;lt;&amp;lt;endl;// 8&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
B1 b1;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
// B1 *b1 = new
 B1();    
 &lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;size
 of b1:&quot;&amp;lt;&amp;lt;sizeof(b1)&amp;lt;&amp;lt;endl;//16 if obj by new //else
 if by def constr 8&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;b&gt;cout&amp;lt;&amp;lt;&quot;size
 of B1:&quot;&amp;lt;&amp;lt;sizeof(B1)&amp;lt;&amp;lt;endl;//16 bytes&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
D  *d  = new
 D();&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;size
 of d1:&quot;&amp;lt;&amp;lt;sizeof(d)&amp;lt;&amp;lt;endl;//8&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;size
 of D1:&quot;&amp;lt;&amp;lt;sizeof(D)&amp;lt;&amp;lt;endl;//16&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
B2 b2; 
 &lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;size
 of b2:&quot;&amp;lt;&amp;lt;sizeof(b2)&amp;lt;&amp;lt;endl;//1//obj by def constr&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;size
 of B2:&quot;&amp;lt;&amp;lt;sizeof(B2)&amp;lt;&amp;lt;endl;//1    
 &lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
B3 *b3 = new
 B3;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;size
 of b3:&quot;&amp;lt;&amp;lt;sizeof(b3)&amp;lt;&amp;lt;endl;//8 obj by new&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
cout&amp;lt;&amp;lt;&quot;size
 of B3:&quot;&amp;lt;&amp;lt;sizeof(B3)&amp;lt;&amp;lt;endl;//1&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
return 0;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
/*&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
* g++
-fdump-class-hierarchy classWithVf.cxx&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
gvim
classWithVf.cxx.t01.class&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Class M&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
size=1 align=1&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
base size=0 base
align=1&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
M (0x2b9ff89feb60) 0
empty&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Class A&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
size=1 align=1&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
base size=0 base
align=1&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
A (0x2b9ff8a19070) 0
empty&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Vtable for B&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
B::_ZTV1B: 3u
entries&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
0     (int
(*)(...))0&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
8     (int
(*)(...))(&amp;amp; _ZTI1B)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
16    B::f&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Class B&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
size=8 align=8&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
base size=8 base
align=8&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
B (0x2b9ff8a19150) 0
nearly-empty&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
vptr=((&amp;amp;
B::_ZTV1B) + 16u)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Vtable for B1&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
B1::_ZTV2B1: 3u
entries&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
0     (int
(*)(...))0&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
8     (int
(*)(...))(&amp;amp; _ZTI2B1)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
16    B1::f1&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Class B1&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
size=16 align=8&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
base size=9 base
align=8&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
B1 (0x2b9ff8a19460)
0&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
vptr=((&amp;amp;
B1::_ZTV2B1) + 16u)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Vtable for D&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
D::_ZTV1D: 3u
entries&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
0     (int
(*)(...))0&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
8     (int
(*)(...))(&amp;amp; _ZTI1D)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
16    D::f1&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Class D&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
size=16 align=8&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
base size=10 base
align=8&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
D (0x2b9ff8a19770) 0&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
vptr=((&amp;amp;
D::_ZTV1D) + 16u)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
B1
(0x2b9ff8a197e0) 0&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
primary-for D
(0x2b9ff8a19770)&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Class B2&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
size=1 align=1&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
base size=1 base
align=1&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
B2 (0x2b9ff8a19a80)
0&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Class B3&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
size=1 align=1&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
base size=1 base
align=1&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
B3 (0x2b9ff8a19b60)
0&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
*/&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Note:&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Sizeof returns +1
for \0&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
Strlen returns exact&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-write-sorted-linked-list-program.html&quot;&gt;Previous&lt;/a&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; &lt;a href=&quot;http://howtocpp.com/&quot;&gt;Home&lt;/a&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; &lt;a href=&quot;http://www.howtocpp.com/2012/10/constructors-in-ccopy-constructor-in-cpp.html&quot;&gt;Next&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/4930715238102691361/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/03/how-to-see-vtable-virtual-table-for.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/4930715238102691361'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/4930715238102691361'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2013/03/how-to-see-vtable-virtual-table-for.html' title='How to see vtable virtual table  for virtual functions in cpp'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16009977468138578543</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-2782932974377163522.post-1474346148688466359</id><published>2012-10-22T23:41:00.002+05:30</published><updated>2013-05-24T15:40:50.894+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="constructors"/><title type='text'>Constructors in C++/Copy Constructor in CPP</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Constructors in C++/Copy Constructor in CPP:&lt;br /&gt;
&lt;b&gt;What is constructor?&lt;/b&gt;&lt;br /&gt;
Constructor is a member function whose task is to initialize the object of a class and &amp;nbsp;which is automatically gets called when object of that class gets created.&lt;br /&gt;
&lt;b&gt;Why do we need constructor?&lt;/b&gt;&lt;br /&gt;
we need constructor to initialize the objects of class at the time of their creation.&lt;br /&gt;
&lt;b&gt;What is Copy Constructor&lt;/b&gt;?&lt;br /&gt;
Copy Constructor is a constructor which gets called when an object is passed by value as argement or when an object is returnrd by value by a function or when an object is initialize by another object.&lt;br /&gt;
Why do we need Copy Constructor?&lt;br /&gt;
We need copy constructor to avoid shallow or member wise copy done by the the compy constructor provided by compiler.&lt;br /&gt;
for example:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;a href=&quot;http://www.howtocpp.com/2013/03/how-to-see-vtable-virtual-table-for.html&quot;&gt;Previous&lt;/a&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; &lt;a href=&quot;http://howtocpp.com/&quot;&gt;Home&lt;/a&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; &lt;a href=&quot;http://www.howtocpp.com/2012/10/how-to-use-template-in-cpp.html&quot;&gt;Next&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/1474346148688466359/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2012/10/constructors-in-ccopy-constructor-in-cpp.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/1474346148688466359'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/1474346148688466359'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2012/10/constructors-in-ccopy-constructor-in-cpp.html' title='Constructors in C++/Copy Constructor in CPP'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16009977468138578543</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-2782932974377163522.post-341756651900832363</id><published>2012-10-20T15:51:00.000+05:30</published><updated>2013-05-24T15:45:47.360+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="template"/><title type='text'>How to use template in cpp</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;u&gt;&lt;span style=&quot;color: purple;&quot;&gt;How to use template in C++:&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
Template is mechanism in C++ to generate fanily of&lt;br /&gt;
&amp;nbsp;generic classes and generic functions that works with &lt;br /&gt;
different types of data types hence eliminate&amp;nbsp;duplicate&lt;br /&gt;
&amp;nbsp;program for diffrent data types and make the program&lt;br /&gt;
&amp;nbsp;more manageable and easier.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;C++ Program for 1 argument template class&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;u&gt;&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
#include&amp;lt;iostream.h&amp;gt;&lt;br /&gt;
#include&amp;lt;string.h&amp;gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #d5a6bd;&quot;&gt;template &amp;lt;class T&amp;gt;&lt;/span&gt;&lt;br /&gt;
class test&lt;br /&gt;
{&lt;br /&gt;
&lt;span style=&quot;background-color: #d5a6bd;&quot;&gt;T t;&lt;/span&gt;&lt;br /&gt;
public:&lt;br /&gt;
test(&lt;span style=&quot;background-color: #d5a6bd;&quot;&gt;T x&lt;/span&gt;)//will work with int, float,char,string&lt;br /&gt;
{&lt;br /&gt;
t=x;&lt;br /&gt;
}&lt;br /&gt;
&amp;nbsp;void show(void)&lt;br /&gt;
&amp;nbsp;{&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;&quot;t= &quot;&amp;lt;&amp;lt;t&amp;lt;&amp;lt;endl;&lt;br /&gt;
&amp;nbsp;}&lt;br /&gt;
};&lt;br /&gt;
//void test&amp;lt; T&amp;gt;::show(void)&lt;br /&gt;
//{&lt;br /&gt;
//cout&amp;lt;&amp;lt;&quot;t&quot;&amp;lt;&amp;lt;t&amp;lt;&amp;lt;endl;&lt;br /&gt;
//}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
test&amp;lt;&lt;span style=&quot;background-color: #d5a6bd;&quot;&gt;int&lt;/span&gt;&amp;gt;t1(10); //calls int version of test(T t)&lt;br /&gt;
t1.show();&lt;br /&gt;
test&amp;lt;&lt;span style=&quot;background-color: #d5a6bd;&quot;&gt;float&lt;/span&gt;&amp;gt;t2(1.0);&amp;nbsp; //calls float version of test(T t)&lt;br /&gt;
t2.show();&lt;br /&gt;
test&amp;lt;&lt;span style=&quot;background-color: #d5a6bd;&quot;&gt;char&lt;/span&gt;&amp;gt;t3(&#39;m&#39;);&amp;nbsp;&amp;nbsp; //calls char version of test(T t)&lt;br /&gt;
t3.show();&lt;br /&gt;
test&amp;lt;&lt;span style=&quot;background-color: #c27ba0;&quot;&gt;char&lt;/span&gt; *&amp;gt;t4(&quot;HelloTemplate&quot;); // calls string version of test(T t)&lt;br /&gt;
t4.show();&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;C++ Program for 1 argument template function&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
#include&amp;lt;iostream.h&amp;gt;&lt;br /&gt;
//using namespace std&lt;br /&gt;
template &amp;lt;class T&amp;gt;&lt;br /&gt;
void display(T a)&lt;br /&gt;
{&lt;br /&gt;
cout&amp;lt;&amp;lt;a&amp;lt;&amp;lt;endl;&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
display(10);&lt;br /&gt;
display(20.12);&lt;br /&gt;
display(&#39;M&#39;);&lt;br /&gt;
display(&quot;MamaMeaa&quot;);&lt;br /&gt;
return 0;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;a href=&quot;http://www.howtocpp.com/2012/10/constructors-in-ccopy-constructor-in-cpp.html&quot;&gt;Previous&lt;/a&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; &lt;a href=&quot;http://howtocpp.com/&quot;&gt;Home&lt;/a&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; &lt;a href=&quot;http://www.howtocpp.com/2012/10/why-to-use-explicit-keyword-in-c.html&quot;&gt;Next&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/341756651900832363/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2012/10/how-to-use-template-in-cpp.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/341756651900832363'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/341756651900832363'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2012/10/how-to-use-template-in-cpp.html' title='How to use template in cpp'/><author><name>Unknown</name><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-2782932974377163522.post-2836100840215308563</id><published>2012-10-02T14:59:00.001+05:30</published><updated>2013-05-24T15:42:34.265+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="explicit"/><title type='text'>Why to use explicit keyword in C++</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
//explicit keyword is used only with constructor&lt;br /&gt;
// which&amp;nbsp; avoids conversion only it will allow to create objects&lt;br /&gt;
&amp;nbsp;#include&amp;lt;iostream.h&amp;gt;&lt;br /&gt;
class sample&lt;br /&gt;
{&lt;br /&gt;
private:&lt;br /&gt;
int i;&lt;br /&gt;
public:&lt;br /&gt;
sample(){}&lt;br /&gt;
// explicit sample(int ii)&lt;br /&gt;
&amp;nbsp;sample(int ii)&lt;br /&gt;
{&lt;br /&gt;
i=ii;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sample operator+(sample s)&lt;br /&gt;
{&lt;br /&gt;
sample temp;&lt;br /&gt;
temp.i=i+s.i;&lt;br /&gt;
return temp ;&lt;br /&gt;
}&lt;br /&gt;
void display()&lt;br /&gt;
{&lt;br /&gt;
cout&amp;lt;&amp;lt;i&amp;lt;&amp;lt;endl;&lt;br /&gt;
}&lt;br /&gt;
};&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
sample s1(25), s2;&lt;br /&gt;
s1.display();&lt;br /&gt;
s2=s1+25;&lt;br /&gt;
s2.display();&lt;br /&gt;
&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
//How to use explicit keyword in C++ with exaple&lt;br /&gt;
//How to use explicit keyword in C++&amp;nbsp; with exaple&lt;br /&gt;
//How to use explicit keyword in C++&amp;nbsp; with exaple&lt;br /&gt;
//Why to use explicit keyword in C++&amp;nbsp; with exaple&lt;br /&gt;
//Why to use explicit keyword in C++&amp;nbsp; with exaple&lt;br /&gt;
&lt;br /&gt;
//overloading S2=S1+25;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;a href=&quot;http://www.howtocpp.com/2012/10/how-to-use-template-in-cpp.html&quot;&gt;Previous&lt;/a&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; &lt;a href=&quot;http://howtocpp.com/&quot;&gt;Home&lt;/a&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; &lt;a href=&quot;http://www.howtocpp.com/2012/10/how-to-use-new-and-delete-in-c.html&quot;&gt;Next&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://how-to-in-cpp.blogspot.com/feeds/2836100840215308563/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://how-to-in-cpp.blogspot.com/2012/10/why-to-use-explicit-keyword-in-c.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/2836100840215308563'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2782932974377163522/posts/default/2836100840215308563'/><link rel='alternate' type='text/html' href='http://how-to-in-cpp.blogspot.com/2012/10/why-to-use-explicit-keyword-in-c.html' title='Why to use explicit keyword in C++'/><author><name>Unknown</name><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></feed>