<?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>Zero Intellect &#187; variable name</title>
	<atom:link href="http://www.zerointellect.com/tag/variable-name/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zerointellect.com</link>
	<description>Technology Blog requiring Zero Intellect to follow !!!</description>
	<lastBuildDate>Mon, 28 Jun 2010 14:09:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Overview of a structure in C and C++</title>
		<link>http://www.zerointellect.com/programming/overview-of-a-structure-in-c-and-c/</link>
		<comments>http://www.zerointellect.com/programming/overview-of-a-structure-in-c-and-c/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 05:03:37 +0000</pubDate>
		<dc:creator>zrydento</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[data type]]></category>
		<category><![CDATA[record data fields]]></category>
		<category><![CDATA[record selector]]></category>
		<category><![CDATA[struct]]></category>
		<category><![CDATA[struct type name]]></category>
		<category><![CDATA[structure]]></category>
		<category><![CDATA[structure variable]]></category>
		<category><![CDATA[variable name]]></category>

		<guid isPermaLink="false">http://www.zerointellect.com/?p=254</guid>
		<description><![CDATA[<p> </p>
<p>The following article gives a brief overview of the structure in C/C++. The structure was first introduced in C where the need to group variables into a single record arose. Variables normally were assigned a single value or were assigned multiple values of the same type (array). The introduction of the structure allowed for variables to <p>Continue reading <a href="http://www.zerointellect.com/programming/overview-of-a-structure-in-c-and-c/">Overview of a structure in C and C++</a></p>]]></description>
			<content:encoded><![CDATA[<p> </p>
<p>The following article gives a brief overview of the structure in C/C++. The structure was first introduced in C where the need to group variables into a single record arose. Variables normally were assigned a single value or were assigned multiple values of the same type (array). The introduction of the structure allowed for variables to contain records of multiple values of different types. A simple comparison is displayed in the figure below</p>
<p><img class="aligncenter" src="http://www.zerointellect.com/uploads/05122009-diagram-1-1.png" alt="" width="350" height="375" /></p>
<p>A structure is of the format below and consists of 3 major components</p>
<p>1. struct-type-name<br />
2. structure-variable<br />
3. record data fields (data type, variable-name)</p>
<p> </p>
<blockquote><p>struct [<strong>&lt;struct-type-name&gt;</strong>]<br />
{<br />
 [<strong>&lt;type&gt;</strong> <strong>&lt;variable-names&gt;</strong>];<br />
 [<strong>&lt;type&gt;</strong> <strong>&lt;variable-names&gt;</strong>];<br />
 [<strong>&lt;type&gt;</strong> <strong>&lt;variable-names&gt;</strong>];<br />
 &#8230;<br />
}[<strong>&lt;structure-variables&gt;</strong>];</p></blockquote>
<p>The &lt;struct-type-name&gt; is an optional tag name that refers to the structure type. It should be defined to give a reflection of the contents of the structure. Such as &#8216;student&#8217; to indicate a record of student details. The &lt;structure-variables&gt; are the data definitions, and are also optional.</p>
<p>Though both are optional, one of the two must appear (makes logical sense, otherwise we would not be able to retrieve or store any values in the records). Elements in the record are defined by naming a &lt;type&gt;, followed by &lt;variable-names&gt; separated by commas. Different variable types can be separated by a semicolon.</p>
<p>A sample program follows that has a single record structure-variable as well as a structure-variable that holds 2 records</p>
<p> </p>
<p><strong># include &lt;iostream.h&gt;<br />
# include &lt;conio.h&gt;</strong></p>
<p><strong>void main()<br />
{<br />
 clrscr();</strong></p>
<p><strong> struct contact<br />
 {<br />
  char name[20];<br />
  int age;<br />
 }mrx;</strong></p>
<p><strong> cout&lt;&lt;&#8221;Name: &#8220;;<br />
 cin&gt;&gt;mrx.name;<br />
 cout&lt;&lt;&#8221;Age: &#8220;;<br />
 cin&gt;&gt;mrx.age;<br />
 cout&lt;&lt;&#8221;\nmrx.name : &#8220;&lt;&lt;mrx.name&lt;&lt;&#8221;\nmrx.age : &#8220;&lt;&lt;mrx.age;</strong></p>
<p><strong> struct contact family[2];</strong></p>
<p><strong> cout&lt;&lt;&#8221;\n\nEnter details of Family Members&#8230;\n&#8221;;</strong></p>
<p><strong> for(int i=0;i&lt;2;i++)<br />
 {<br />
  cout&lt;&lt;&#8221;\nName: &#8220;;<br />
  cin&gt;&gt;family[i].name;<br />
  cout&lt;&lt;&#8221;Age: &#8220;;<br />
  cin&gt;&gt;family[i].age;<br />
 }</strong></p>
<p><strong> cout&lt;&lt;&#8221;\nDetails of Family Members&#8230;&#8221;;</strong></p>
<p><strong> for(i=0;i&lt;2;i++)<br />
 {<br />
  cout&lt;&lt;&#8221;\n\nName :\t&#8221;&lt;&lt;family[i].name&lt;&lt;&#8221;\nAge :\t&#8221;&lt;&lt;family[i].age;<br />
 } <br />
      <br />
 getch();<br />
}</strong></p>
<p> </p>
<p>To access elements in a structure, you use a record selector (.)</p>
<p>For example, as it is mentioned in the program above mrx.age</p>
<p>To declare additional variables of the same type, you use the keyword struct followed by the &lt;struct-type-name&gt;, followed by the variable names</p>
<p>For example, the following declaration will create a record of 5 rows containing colleague details (age, name) as per our example program above</p>
<p><strong>struct colleagues[5];</strong></p>
<p>To summarize, structures were created to hold records of different data type values. But in C++ which is an object oriented language, classes were introduced that have many more benefits than structures. However, for simple implementations structures are very useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zerointellect.com/programming/overview-of-a-structure-in-c-and-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

