<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>how to call destructor C++ - Wikitechy</title>
	<atom:link href="https://www.wikitechy.com/interview-questions/tag/how-to-call-destructor-c/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.wikitechy.com/interview-questions/tag/how-to-call-destructor-c/</link>
	<description>Interview Questions</description>
	<lastBuildDate>Thu, 18 Aug 2022 10:51:24 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.wikitechy.com/interview-questions/wp-content/uploads/2025/10/cropped-wikitechy-icon-32x32.png</url>
	<title>how to call destructor C++ - Wikitechy</title>
	<link>https://www.wikitechy.com/interview-questions/tag/how-to-call-destructor-c/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>What is destructor in C++ ?</title>
		<link>https://www.wikitechy.com/interview-questions/cpp/what-is-destructor-in-cpp/</link>
					<comments>https://www.wikitechy.com/interview-questions/cpp/what-is-destructor-in-cpp/#respond</comments>
		
		<dc:creator><![CDATA[webmaster]]></dc:creator>
		<pubDate>Thu, 18 Aug 2022 10:51:24 +0000</pubDate>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[c++ destructor]]></category>
		<category><![CDATA[c++ destructors]]></category>
		<category><![CDATA[characteristics of destructors in c++]]></category>
		<category><![CDATA[constructor and destructor in c++]]></category>
		<category><![CDATA[destructor in c++]]></category>
		<category><![CDATA[destructor in c++ example program with output]]></category>
		<category><![CDATA[destructors in c++]]></category>
		<category><![CDATA[how to call destructor C++]]></category>
		<category><![CDATA[types of destructor in c++]]></category>
		<category><![CDATA[use of destructor in c++]]></category>
		<category><![CDATA[what is destructor in c++]]></category>
		<guid isPermaLink="false">https://www.wikitechy.com/interview-questions/?p=4774</guid>

					<description><![CDATA[In C++ destructor is an instance member function which is invoked automatically whenever an object is going to be destroyed. A destructor meaning is the last function that is going to be called before an object is destroyed. If the object is created by using new or the constructor uses new to allocate memory which [&#8230;]]]></description>
										<content:encoded><![CDATA[<ul>
<li style="text-align: justify;">In C++ destructor is an instance member function which is invoked automatically whenever an object is going to be destroyed.</li>
<li style="text-align: justify;">A destructor meaning is the last function that is going to be called before an object is destroyed.</li>
<li style="text-align: justify;">If the object is created by using new or the constructor uses new to allocate memory which resides in the heap memory or the free store, the destructor should use delete to free the memory, the thing is to be noted here.</li>
<li style="text-align: justify;">When the objects are destroyed, destructor function is automatically invoked.</li>
<li style="text-align: justify;">Destructor does not have arguments and it cannot be declared as constant or static.</li>
<li style="text-align: justify;">Destructor cannot become a member of the union while with an object of a class.</li>
<li style="text-align: justify;">The programmer cannot access the address of destructor and in public section of class destructor should be declared.</li>
<li style="text-align: justify;">If the object goes out of scope, destructor function is called automatically were the function ends, the program ends, a block containing local variables ends, a delete operator is called.</li>
<li style="text-align: justify;">Destructors have same name as the class preceded by a tilde (~) it doesn’t take any argument and return anything.</li>
</ul>
<h2 id="sample-code" style="text-align: justify;">Sample Code</h2>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-cpp code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-cpp code-embed-code">#include&lt;iostream&gt;<br/>               using namespace std;<br/>              class Demo {<br/>                   private:<br/>                   int num1, num2;<br/>                   public:<br/>                   	Demo(int n1, int n2) {<br/>                                   cout&lt;&lt;&quot;Inside Constructor&quot;&lt;&lt;endl;<br/>                                   num1 = n1;<br/>                                   num2 = n2;<br/>                              }<br/>                             void display() {<br/>                                   cout&lt;&lt;&quot;num1 = &quot;&lt;&lt; num1 &lt;&lt;endl;<br/>                                   cout&lt;&lt;&quot;num2 = &quot;&lt;&lt; num2 &lt;&lt;endl;<br/>                             }<br/>                         ~Demo() {<br/>                                  cout&lt;&lt;&quot;Inside Destructor&quot;;<br/>                            }<br/>                       };<br/>                      int main() {<br/>                      Demo obj1(30, 50);<br/>                      obj1.display();<br/>                      return 0;<br/>                      }</code></pre> </div>
<h2 id="output" style="text-align: justify;">Output</h2>
<p style="text-align: justify;"><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-4775" src="https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/destructor.png" alt="" width="1137" height="311" srcset="https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/destructor.png 1137w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/destructor-300x82.png 300w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/destructor-1024x280.png 1024w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/destructor-768x210.png 768w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/destructor-390x107.png 390w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/destructor-820x224.png 820w" sizes="(max-width: 1137px) 100vw, 1137px" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.wikitechy.com/interview-questions/cpp/what-is-destructor-in-cpp/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
