<?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 struct elements | Student Projects</title>
	<atom:link href="https://studentprojects.in/tag/accessing-struct-elements/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:46:53 +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>Creating a struct element</title>
		<link>https://studentprojects.in/software-development/cpp/creating-a-struct-element/</link>
					<comments>https://studentprojects.in/software-development/cpp/creating-a-struct-element/#respond</comments>
		
		<dc:creator><![CDATA[Shubhajna Rai]]></dc:creator>
		<pubDate>Wed, 04 Jan 2023 14:24:20 +0000</pubDate>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[creating struct element]]></category>
		<category><![CDATA[Accessing struct elements]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=10070</guid>

					<description><![CDATA[<p>To define the struct, we utilise the struct keyword. The fundamental syntax for declaring a struct is, Here’s one example of how a struct is defined and used in main as a user-defined data type. Accessing struct elements The dot operator is used to access any of the values of a structure&#8217;s members (.). This</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/creating-a-struct-element/">Creating a struct element</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>To define the struct, we utilise the struct keyword.</p>



<p>The fundamental syntax for declaring a struct is,</p>



<pre class="wp-block-code"><code lang="cpp" class="language-cpp">struct structure_name
{
    //structure_elements
} structure_variable;
</code></pre>



<p>Here’s one example of how a struct is defined and used in main as a user-defined data type.</p>



<pre class="wp-block-code"><code lang="cpp" class="language-cpp">#include &lt;iostream&gt;
using namespace std;
 
struct employee
{
    /* data */
    int eId;
    char favChar;
    int salary;
};
 
int main()
{
    struct employee Roy;
    return 0;
}
</code></pre>



<h3>Accessing struct elements</h3>



<p>The dot operator is used to access any of the values of a structure&#8217;s members (.). This dot operator is placed between the name of the structure variable and the name of the structure member that we want to access.</p>



<p>There must always be an already defined structure variable before the dot operator and a valid structure element after the dot operator.</p>



<p>Here&#8217;s an example of how we can access struct elements.</p>



<pre class="wp-block-code"><code lang="cpp" class="language-cpp">#include &lt;iostream&gt;
using namespace std;
 
struct employee
{
    /* data */
    int eId;
    char favChar;
    int salary;
};
 
int main()
{
    struct employee Roy;
    Roy.eId = 1;
    Roy.favChar = 'c';
    Roy.salary = 120000000;
    cout &lt;&lt; "eID of Roy is " &lt;&lt; Roy.eId &lt;&lt; endl;
    cout &lt;&lt; "favChar of Roy is " &lt;&lt; Roy.favChar &lt;&lt; endl;
    cout &lt;&lt; "salary of Roy is " &lt;&lt; Roy.salary &lt;&lt; endl;
    return 0;
}
</code></pre>



<p>Output:</p>



<pre class="wp-block-code"><code lang="cpp" class="language-cpp">Output:
eID of Roy is 1
favChar of Roy is c
salary of Roy is 120000000
</code></pre><p>The post <a href="https://studentprojects.in/software-development/cpp/creating-a-struct-element/">Creating a struct element</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/creating-a-struct-element/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
