<?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>EmbLogic &#187; Gaurav Kumar</title>
	<atom:link href="https://www.emblogic.com/blog/author/gaurav-in/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.emblogic.com/blog</link>
	<description>Embedded System and ARM Training</description>
	<lastBuildDate>Tue, 03 Mar 2020 13:00:06 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.9.1</generator>
	<item>
		<title>structures</title>
		<link>https://www.emblogic.com/blog/04/structures-3/</link>
		<comments>https://www.emblogic.com/blog/04/structures-3/#comments</comments>
		<pubDate>Sat, 11 Apr 2015 06:24:32 +0000</pubDate>
		<dc:creator><![CDATA[Gaurav Kumar]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=12555</guid>
		<description><![CDATA[structure is a user defined data type available in c programming,it allows us to combine data items of different kinds and helps us to construct a complex data type in a meaningful way. Structure is used to represent a record. &#8230; <a href="https://www.emblogic.com/blog/04/structures-3/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p style="margin-bottom: 0in;font-weight: normal;text-decoration: none" align="JUSTIFY"><span style="font-size: large">structure is a user defined data type available in c programming,it allows us to combine data items of different kinds and helps us to construct a complex data type in a meaningful way.</span></p>
<p style="margin-bottom: 0in;font-weight: normal;text-decoration: none" align="JUSTIFY"><span style="font-size: large">Structure is used to represent a record. Suppose we want to keep track of books in a library. For this we have to track some attributed(title,author,subject,book id) of each book. To define a structure we must use the struct statement. This statement defines a new data type with more then one member for our program . the format for struct statement is :</span></p>
<p style="margin-bottom: 0in;font-weight: normal;text-decoration: none" align="JUSTIFY">
<p style="margin-bottom: 0in;font-weight: normal;text-decoration: none" align="JUSTIFY"><span style="font-size: large">struct [structure tag]</span></p>
<p style="margin-bottom: 0in;font-weight: normal;text-decoration: none" align="JUSTIFY"><span style="font-size: large">{</span></p>
<p style="margin-bottom: 0in;font-weight: normal;text-decoration: none" align="JUSTIFY"><span style="font-size: large"> member definition;</span></p>
<p style="margin-bottom: 0in;font-weight: normal;text-decoration: none" align="JUSTIFY"><span style="font-size: large"> member definition;</span></p>
<p style="margin-bottom: 0in;font-weight: normal;text-decoration: none" align="JUSTIFY"><span style="font-size: large"> &#8230;.</span></p>
<p style="margin-bottom: 0in;font-weight: normal;text-decoration: none" align="JUSTIFY"><span style="font-size: large">}[one or more structure variables];</span></p>
<p style="margin-bottom: 0in;font-weight: normal;text-decoration: none" align="JUSTIFY">
<p style="margin-bottom: 0in;font-weight: normal;text-decoration: none" align="JUSTIFY"><span style="font-size: large">the structure tag and structure variable is optional and each member definition is a normal variable definition such as int i; or float j or any other variable definition we can also declare structure variable separately like:</span></p>
<p style="margin-bottom: 0in;font-weight: normal;text-decoration: none" align="JUSTIFY">
<p style="margin-bottom: 0in;font-weight: normal;text-decoration: none" align="JUSTIFY"><span style="font-size: large">struct structure tag structure variable1,structure variable2&#8230; ;</span></p>
<p style="margin-bottom: 0in;font-weight: normal;text-decoration: none" align="JUSTIFY">
<p style="margin-bottom: 0in;font-weight: normal;text-decoration: none" align="JUSTIFY"><span style="font-size: large">a structure member has no meaning on its own so we cannot access it directly. In order to access a structure member,the member name must be linked with the structure variable using dot (.)operator also called period or member access operator .we can also use structure pointer operator if we are declaring a pointer variable for that structure .</span></p>
<p style="margin-bottom: 0in;font-weight: normal;text-decoration: none" align="JUSTIFY"><span style="font-size: large">Structures can also be nested within other structure in C programming and they can also be passed as a function argument like any other variable.</span></p>
<p style="margin-bottom: 0in;text-decoration: none" align="JUSTIFY">
<p style="margin-bottom: 0in;text-decoration: none" align="JUSTIFY"><span style="font-size: large"><b>Bit fields:-</b></span></p>
<p style="margin-bottom: 0in;font-weight: normal;text-decoration: none" align="JUSTIFY"><span style="font-size: large">bit fields allow the packing of data in a structure. This is specially useful when memory is limited . Suppose our structure contains some true/false variables then we are going to store either 0 or 1 in these variables. so C programming offers us a better way to utilize the memory space in these situations . We can define the width of variable which tells the C compiler that we are going to use only those number of bits for example :</span></p>
<p style="margin-bottom: 0in;font-weight: normal;text-decoration: none" align="JUSTIFY"><span style="font-size: large">struct </span></p>
<p style="margin-bottom: 0in;font-weight: normal;text-decoration: none" align="JUSTIFY"><span style="font-size: large">{</span></p>
<p style="margin-bottom: 0in;font-weight: normal;text-decoration: none" align="JUSTIFY"><span style="font-size: large">unsigned int cgpa : 3;</span></p>
<p style="margin-bottom: 0in;font-weight: normal;text-decoration: none" align="JUSTIFY"><span style="font-size: large">}student;</span></p>
<p style="margin-bottom: 0in;font-weight: normal;text-decoration: none" align="JUSTIFY"><span style="font-size: large">the above structure definition instructs C compiler that cgpa variable is going to use only </span></p>
<p style="margin-bottom: 0in;font-weight: normal;text-decoration: none" align="JUSTIFY"><span style="font-size: large">3 bits to store the value,if we try to use more then 3 bits then it will not allow us to do so.</span></p>
<p style="margin-bottom: 0in;font-weight: normal;text-decoration: none" align="JUSTIFY">
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/04/structures-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
