<?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>Accessing an array element | Student Projects</title>
	<atom:link href="https://studentprojects.in/tag/accessing-an-array-element/feed/" rel="self" type="application/rss+xml" />
	<link>https://studentprojects.in</link>
	<description>Microcontroller projects, Circuit Diagrams, Project Ideas</description>
	<lastBuildDate>Thu, 29 Dec 2022 13:59:58 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>
	<item>
		<title>Array Operations</title>
		<link>https://studentprojects.in/software-development/cpp/array-operations-2/</link>
					<comments>https://studentprojects.in/software-development/cpp/array-operations-2/#respond</comments>
		
		<dc:creator><![CDATA[Shubhajna Rai]]></dc:creator>
		<pubDate>Sat, 31 Dec 2022 01:55:00 +0000</pubDate>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Accessing an array element]]></category>
		<category><![CDATA[array operations]]></category>
		<category><![CDATA[changing an array element]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=10053</guid>

					<description><![CDATA[<p>Defining an array 1. Without specifying the size of the array: Although the array cannot be left empty in this scenario, we can leave the square brackets empty. It must contain elements. 2. With specifying the size of the array: Accessing an array element An array element can be easily retrieved by its index number.</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/array-operations-2/">Array Operations</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Defining an array</p>



<h4>1. Without specifying the size of the array:</h4>



<pre class="wp-block-code"><code lang="cpp" class="language-cpp">int arr[] = {1, 2, 3};</code></pre>



<p>Although the array cannot be left empty in this scenario, we can leave the square brackets empty. It must contain elements.</p>



<h4>2. With specifying the size of the array:</h4>



<pre class="wp-block-code"><code lang="cpp" class="language-cpp">int arr[3];
arr[0] = 1, arr[1] = 2, arr[2] = 3;</code></pre>



<h3>Accessing an array element</h3>



<p>An array element can be easily retrieved by its index number.</p>



<p>An index number is a sort of number that allows us to access array variables. In a programme, index numbers provide a way to retrieve each element of an array. It should be noted that the index number begins with 0 and not one.</p>



<pre class="wp-block-code"><code lang="cpp" class="language-cpp">#include &lt;iostream&gt;
using namespace std;
 
int main()
{
    int arr[] = {1, 2, 3};
    cout &lt;&lt; arr[1] &lt;&lt; endl;
}
</code></pre>



<p>Output:</p>



<p>2</p>



<h3>Changing an array element</h3>



<p>An element in an array can be overwritten using its index number.</p>



<p>Example:</p>



<pre class="wp-block-code"><code lang="cpp" class="language-cpp">#include &lt;iostream&gt;
using namespace std;
 
int main()
{
    int arr[] = {1, 2, 3};
    arr[2] = 8; //changing the element on index 2
    cout &lt;&lt; arr[2] &lt;&lt; endl;
}
</code></pre>



<p>Output:</p>



<p>8</p><p>The post <a href="https://studentprojects.in/software-development/cpp/array-operations-2/">Array Operations</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/array-operations-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Array Operations</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/array-operations/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/array-operations/#respond</comments>
		
		<dc:creator><![CDATA[Shubhajna Rai]]></dc:creator>
		<pubDate>Tue, 25 Oct 2022 08:10:32 +0000</pubDate>
				<category><![CDATA[C Tutorials]]></category>
		<category><![CDATA[array operation]]></category>
		<category><![CDATA[changing array elements]]></category>
		<category><![CDATA[Accessing an array element]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=9676</guid>

					<description><![CDATA[<p>Defining an array Without mentioning the array&#8217;s size int arr[] = {1, 2, 3}; Although the array in this situation cannot be empty, we can leave the square brackets empty. There must be components in it. By defining the array&#8217;s size int arr[3]; arr[0] = 1, arr[1] = 2, arr[2] = 3; In this case,</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/array-operations/">Array Operations</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p><strong>Defining an array</strong></p>



<ol type="1"><li>Without mentioning the array&#8217;s size</li></ol>



<p>int arr[] = {1, 2, 3};</p>



<p>Although the array in this situation cannot be empty, we can leave the square brackets empty. There must be components in it.</p>



<ul><li>By defining the array&#8217;s size</li></ul>



<p>int arr[3];</p>



<p>arr[0] = 1, arr[1] = 2, arr[2] = 3;</p>



<p>In this case, the array&#8217;s definition itself allows us to specify its size. The items of an array can then be added afterwards.</p>



<p><strong>Accessing an array element</strong></p>



<ul><li>The index number of an array element makes it simple to access that element. It is important to keep in mind that the index number actually begins at zero, not one.</li></ul>



<pre class="wp-block-code"><code lang="c" class="language-c">#include &lt;stdio.h&gt;
int main()
{

    int arr[] = {1, 5, 7, 2};

    printf("%d ", arr[2]); //printing element on index 2

}</code></pre>



<p>Output:7</p>



<p>Changing an array element</p>



<ul><li>Using an array&#8217;s index number, an element can be replaced.</li></ul>



<p>Example:</p>



<pre class="wp-block-code"><code lang="c" class="language-c">#include &lt;stdio.h&gt;
int main()
{

    int arr[] = {1, 5, 7, 2};

    arr[2] = 8; //changing the element on index 2

    printf("%d ", arr[2]); //printing element on index 2

}</code></pre>



<p>Output:8</p><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/array-operations/">Array Operations</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/c-tutorials/c-tutorials-c-tutorials/array-operations/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
