<?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>iterators c++ example - Wikitechy</title>
	<atom:link href="https://www.wikitechy.com/interview-questions/tag/iterators-c-example/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.wikitechy.com/interview-questions/tag/iterators-c-example/</link>
	<description>Interview Questions</description>
	<lastBuildDate>Thu, 18 Aug 2022 11:19:55 +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>iterators c++ example - Wikitechy</title>
	<link>https://www.wikitechy.com/interview-questions/tag/iterators-c-example/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>What is Iterator in C++ ?</title>
		<link>https://www.wikitechy.com/interview-questions/cpp/what-is-iterator-in-c/</link>
					<comments>https://www.wikitechy.com/interview-questions/cpp/what-is-iterator-in-c/#respond</comments>
		
		<dc:creator><![CDATA[webmaster]]></dc:creator>
		<pubDate>Thu, 18 Aug 2022 11:19:55 +0000</pubDate>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[auto iterator c++]]></category>
		<category><![CDATA[c++ iterator implementation]]></category>
		<category><![CDATA[c++ iterators]]></category>
		<category><![CDATA[introduction to iterators in c++]]></category>
		<category><![CDATA[iterator arithmetic c++]]></category>
		<category><![CDATA[iterators]]></category>
		<category><![CDATA[iterators c++ example]]></category>
		<category><![CDATA[iterators in c++]]></category>
		<category><![CDATA[list iterator c++]]></category>
		<category><![CDATA[types of iterators in c++]]></category>
		<guid isPermaLink="false">https://www.wikitechy.com/interview-questions/?p=4777</guid>

					<description><![CDATA[An iterator is an object like a pointer that points to an element inside the container. Iterator can use to move through the contents of the container. We can access the content at that particular location using them and it can be visualized as something similar to a pointer pointing to some location. It plays [&#8230;]]]></description>
										<content:encoded><![CDATA[<ul>
<li style="text-align: justify;">An iterator is an object like a pointer that points to an element inside the container.</li>
<li style="text-align: justify;">Iterator can use to move through the contents of the container.</li>
<li style="text-align: justify;">We can access the content at that particular location using them and it can be visualized as something similar to a pointer pointing to some location.</li>
<li style="text-align: justify;">It plays a critical role while connecting algorithm with containers along with the manipulation of data stored inside the containers.</li>
<li style="text-align: justify;">Pointer is a most obvious form of an iterator.</li>
<li style="text-align: justify;">In an array pointer can point to elements and using increment operator (++) it can iterate through them.</li>
<li style="text-align: justify;">All iterator doesn’t have similar functionality as that of pointers.</li>
<li style="text-align: justify;">Depending upon the functionality of iterators they can be classified into five categories, they are:
<ul>
<li>Input iterator</li>
<li>Output iterator</li>
<li>Forward iterator</li>
<li>Bidirectional iterator</li>
<li>Random access iterator</li>
</ul>
</li>
</ul>
<p><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-4779 aligncenter" src="https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/what-is-iterator.png" alt="" width="1338" height="806" srcset="https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/what-is-iterator.png 1338w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/what-is-iterator-300x181.png 300w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/what-is-iterator-1024x617.png 1024w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/what-is-iterator-768x463.png 768w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/what-is-iterator-390x235.png 390w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/what-is-iterator-820x494.png 820w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/what-is-iterator-1180x711.png 1180w" sizes="(max-width: 1338px) 100vw, 1338px" /></p>
<h2 id="input-iterator" style="text-align: justify;">Input iterator</h2>
<ul style="text-align: justify;">
<li>They have limited functionality and weakest of all iterators.</li>
<li>In single-pass algorithms it can be used.</li>
<li>Those algorithms which process the container sequentially, such that no element is accessed more than once.</li>
</ul>
<h2 id="output-iterator" style="text-align: justify;">Output iterator</h2>
<ul style="text-align: justify;">
<li>It is also like input operators, they are also very limited in their functionality and can only be used in single-pass algorithm, but not for accessing elements, but for being assigned elements.</li>
</ul>
<h2 id="forward-iterator" style="text-align: justify;">Forward iterator</h2>
<ul style="text-align: justify;">
<li>It is higher in hierarchy than input iterator and output iterator and contain all the features present in these two iterators</li>
<li>As name suggests, they can also only move in a forward direction and that too one step at a time.</li>
</ul>
<h2 id="bidirectional-iterator" style="text-align: justify;">Bidirectional iterator</h2>
<ul style="text-align: justify;">
<li>It has all the features of forward iterators along with the fact that they overcome the drawback of forward iterators, in both the directions they can move, hence their name is Bidirectional iterators.</li>
</ul>
<h2 id="random-access-iterator" style="text-align: justify;">Random Access iterator</h2>
<ul style="text-align: justify;">
<li>It is the most powerful iterators and they are not limited to moving sequentially, as their name suggests, they can randomly access any element inside the container.</li>
</ul>
<h3 id="sample-code" style="text-align: justify;"><strong>Sample Code</strong></h3>
<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/><br/>    #include &lt;vector&gt;<br/><br/>    using namespace std;<br/><br/>    int main()<br/><br/>    {<br/><br/>            // Declaring a vector<br/><br/>            vector&lt;int&gt; v = { 1, 2, 3 };<br/><br/><br/><br/><br/>           // Declaring an iterator<br/><br/>           vector&lt;int&gt;::iterator i;<br/><br/><br/><br/><br/>           int j;<br/><br/><br/><br/><br/>           cout &lt;&lt; &quot;Without iterators = &quot;;<br/><br/>     <br/><br/>           // Accessing the elements without using iterators<br/><br/>           for (j = 0; j &lt; 3; ++j)<br/><br/>        {<br/><br/>          cout &lt;&lt; v[j] &lt;&lt; &quot; &quot;;<br/><br/>        }<br/><br/><br/><br/><br/>          cout &lt;&lt; &quot;\nWith iterators = &quot;;<br/><br/>     <br/><br/>          // Accessing the elements using iterators<br/><br/>         for (i = v.begin(); i != v.end(); ++i)<br/><br/>      {<br/><br/>          cout &lt;&lt; *i &lt;&lt; &quot; &quot;;<br/><br/>      }<br/><br/><br/><br/><br/>         // Adding one more element to vector<br/><br/>         v.push_back(4);<br/><br/><br/><br/><br/>         cout &lt;&lt; &quot;\nWithout iterators = &quot;;<br/><br/>     <br/><br/>         // Accessing the elements without using iterators<br/><br/>        for (j = 0; j &lt; 4; ++j)<br/><br/>     {<br/><br/>         cout &lt;&lt; v[j] &lt;&lt; &quot; &quot;;<br/><br/>     }<br/><br/><br/><br/><br/>         cout &lt;&lt; &quot;\nWith iterators = &quot;;<br/><br/>     <br/><br/>        // Accessing the elements using iterators<br/><br/>       for (i = v.begin(); i != v.end(); ++i)<br/><br/>    {<br/><br/>        cout &lt;&lt; *i &lt;&lt; &quot; &quot;;<br/><br/>    }<br/><br/><br/><br/><br/>    return 0;<br/><br/>  }</code></pre> </div>
<h3 id="output" style="text-align: justify;"><strong>Output</strong></h3>
<p><img decoding="async" class="alignnone size-full wp-image-4778 aligncenter" src="https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/iterators.png" alt="" width="673" height="320" srcset="https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/iterators.png 673w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/iterators-300x143.png 300w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/iterators-390x185.png 390w" sizes="(max-width: 673px) 100vw, 673px" /></p>
<p style="text-align: justify;"><strong> </strong></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.wikitechy.com/interview-questions/cpp/what-is-iterator-in-c/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
