<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: 4.7 &#8212; Structs</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/47-structs/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/47-structs/</link>
	<description></description>
	<pubDate>Wed, 19 Nov 2008 17:00:52 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Chris Walker</title>
		<link>http://www.learncpp.com/cpp-tutorial/47-structs/#comment-31343</link>
		<dc:creator>Chris Walker</dc:creator>
		<pubDate>Thu, 30 Oct 2008 12:54:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/47-structs/#comment-31343</guid>
		<description>Exactly! This is a pass-parameter-by-value-or-reference issue. As a general rule: if you need to modify the struct/obj and keep changes in the previous scope, pass by reference, not by value. Your description of what was happening in your code is spot on.</description>
		<content:encoded><![CDATA[<p>Exactly! This is a pass-parameter-by-value-or-reference issue. As a general rule: if you need to modify the struct/obj and keep changes in the previous scope, pass by reference, not by value. Your description of what was happening in your code is spot on.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: som shekhar</title>
		<link>http://www.learncpp.com/cpp-tutorial/47-structs/#comment-31341</link>
		<dc:creator>som shekhar</dc:creator>
		<pubDate>Thu, 30 Oct 2008 12:33:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/47-structs/#comment-31341</guid>
		<description>Okay i understood what can go wrong in the above problem???correct me if i am wrong!!
when i declare Score s1; memory has been allocated lets say its address is 123.
Now when i am passing this s1 to the function ReadScore, this function will create a copy of s1 
which will have different memory,(let say its address is 125) so it does everything right,
but doesnt touch at all the address 123..which is still junk. SO i m getting junk correct?

the above problem i overcame ,when i send the reference of the s1!!!
Or else i can call the PrintScore inside the ReadScore function..this will also eliminates the problem.</description>
		<content:encoded><![CDATA[<p>Okay i understood what can go wrong in the above problem???correct me if i am wrong!!<br />
when i declare Score s1; memory has been allocated lets say its address is 123.<br />
Now when i am passing this s1 to the function ReadScore, this function will create a copy of s1<br />
which will have different memory,(let say its address is 125) so it does everything right,<br />
but doesnt touch at all the address 123..which is still junk. SO i m getting junk correct?</p>
<p>the above problem i overcame ,when i send the reference of the s1!!!<br />
Or else i can call the PrintScore inside the ReadScore function..this will also eliminates the problem.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: som shekhar</title>
		<link>http://www.learncpp.com/cpp-tutorial/47-structs/#comment-31339</link>
		<dc:creator>som shekhar</dc:creator>
		<pubDate>Thu, 30 Oct 2008 12:22:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/47-structs/#comment-31339</guid>
		<description>&lt;pre&gt;
#include&#60;iostream.h&#62;

struct Score
{
	int nScore;
};
void ReadScore(Score s1)
{
	cout&#60;&#60;&#34;\nEnter Score:&#34;;
	cin&#62;&#62;s1.nScore;
}
void PrintScore(Score s1)
{
	cout&#60;&#60;&#34;\nScore=&#34;&#60;&#60; s1.nScore;
}

int main()
{
	Score s1;
	ReadScore(s1);
	PrintScore(s1);
	return 0;
}
&lt;/pre&gt;
When i print the score i got junk , i understood since initially s1 was not initialised, and
when it is passed to function ReadScore s1 now become a local scope for that function and
value got destroyed after the function ends and dats y i got junk value.
But When i am doing like this
&lt;pre&gt;
#include&#60;iostream.h&#62;

struct Score
{
	int nScore;
};
void ReadScore(Score s1)
{
	Score s2;
	cout&#60;&#60;&#34;\nEnter Score:&#34;;
	cin&#62;&#62;s2.nScore;
	s1 =s2;
}
void PrintScore(Score s1)
{
	cout&#60;&#60;&#34;\nScore=&#34;&#60;&#60; s1.nScore;
}

int main()
{
	Score s1;
	ReadScore(s1);
	PrintScore(s1);
	return 0;
}
&lt;/pre&gt;

i m still getting junk.Well i have created another structure variable s2, and then i assigned
s2 to s1, so it will be copying the score, Correct??? then y the value is getting destroyed after the f
the function ends</description>
		<content:encoded><![CDATA[<pre>
#include&lt;iostream.h&gt;

struct Score
{
	int nScore;
};
void ReadScore(Score s1)
{
	cout&lt;&lt;&quot;\nEnter Score:&quot;;
	cin&gt;&gt;s1.nScore;
}
void PrintScore(Score s1)
{
	cout&lt;&lt;&quot;\nScore=&quot;&lt;&lt; s1.nScore;
}

int main()
{
	Score s1;
	ReadScore(s1);
	PrintScore(s1);
	return 0;
}
</pre>
<p>When i print the score i got junk , i understood since initially s1 was not initialised, and<br />
when it is passed to function ReadScore s1 now become a local scope for that function and<br />
value got destroyed after the function ends and dats y i got junk value.<br />
But When i am doing like this</p>
<pre>
#include&lt;iostream.h&gt;

struct Score
{
	int nScore;
};
void ReadScore(Score s1)
{
	Score s2;
	cout&lt;&lt;&quot;\nEnter Score:&quot;;
	cin&gt;&gt;s2.nScore;
	s1 =s2;
}
void PrintScore(Score s1)
{
	cout&lt;&lt;&quot;\nScore=&quot;&lt;&lt; s1.nScore;
}

int main()
{
	Score s1;
	ReadScore(s1);
	PrintScore(s1);
	return 0;
}
</pre>
<p>i m still getting junk.Well i have created another structure variable s2, and then i assigned<br />
s2 to s1, so it will be copying the score, Correct??? then y the value is getting destroyed after the f<br />
the function ends</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/47-structs/#comment-23165</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Fri, 08 Aug 2008 17:51:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/47-structs/#comment-23165</guid>
		<description>Yes, you can do this -- PCOORD is a typedef's poniter to a Coordinate struct.  You can't initialize your pPos because pPos is a pointer, and you haven't set it to point at anything.</description>
		<content:encoded><![CDATA[<p>Yes, you can do this &#8212; PCOORD is a typedef&#8217;s poniter to a Coordinate struct.  You can&#8217;t initialize your pPos because pPos is a pointer, and you haven&#8217;t set it to point at anything.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/47-structs/#comment-23164</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Fri, 08 Aug 2008 17:49:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/47-structs/#comment-23164</guid>
		<description>Yes, a function can return a structure of data.  This is one of the few ways to return multiple values from a function.</description>
		<content:encoded><![CDATA[<p>Yes, a function can return a structure of data.  This is one of the few ways to return multiple values from a function.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: siku</title>
		<link>http://www.learncpp.com/cpp-tutorial/47-structs/#comment-22501</link>
		<dc:creator>siku</dc:creator>
		<pubDate>Fri, 01 Aug 2008 19:28:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/47-structs/#comment-22501</guid>
		<description>Is there such a thing like typedef pointers? I got into trouble to initialize PCOORD. Finally I figured it out but I am not sure that am I doing the right thing? I thought it would be good to put this code example here since the mechanism is used in many places.

For example (code):


typedef struct Coordinate
{
   short X;
   short Y;
} COORD, *PCOORD;

int main()
{
   COORD pos;
   pos.X = 0;
   pos.Y = 0;
   PCOORD pPos = &#38;pos;
}

At the beginning my main function looked like the main() below:

int main()
{
   //this is the wrong way to do things
   PCOORD pPos;
   pPos-&#62;X = 0;
   pPos-&#62;Y = 0;
   //if you use pPos now in somewhere compiler gives you warning that pPos is not initialized and my program crashed if I run that.
   // Why is it so? Why I cant initialize?
}</description>
		<content:encoded><![CDATA[<p>Is there such a thing like typedef pointers? I got into trouble to initialize PCOORD. Finally I figured it out but I am not sure that am I doing the right thing? I thought it would be good to put this code example here since the mechanism is used in many places.</p>
<p>For example (code):</p>
<p>typedef struct Coordinate<br />
{<br />
   short X;<br />
   short Y;<br />
} COORD, *PCOORD;</p>
<p>int main()<br />
{<br />
   COORD pos;<br />
   pos.X = 0;<br />
   pos.Y = 0;<br />
   PCOORD pPos = &amp;pos;<br />
}</p>
<p>At the beginning my main function looked like the main() below:</p>
<p>int main()<br />
{<br />
   //this is the wrong way to do things<br />
   PCOORD pPos;<br />
   pPos-&gt;X = 0;<br />
   pPos-&gt;Y = 0;<br />
   //if you use pPos now in somewhere compiler gives you warning that pPos is not initialized and my program crashed if I run that.<br />
   // Why is it so? Why I cant initialize?<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Astro</title>
		<link>http://www.learncpp.com/cpp-tutorial/47-structs/#comment-20482</link>
		<dc:creator>Astro</dc:creator>
		<pubDate>Mon, 07 Jul 2008 10:38:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/47-structs/#comment-20482</guid>
		<description>
We can pass a structure to a function.

But can a function return a structure of data? 

Cheers.

</description>
		<content:encoded><![CDATA[<p>We can pass a structure to a function.</p>
<p>But can a function return a structure of data? </p>
<p>Cheers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mitul Golakiya</title>
		<link>http://www.learncpp.com/cpp-tutorial/47-structs/#comment-19342</link>
		<dc:creator>Mitul Golakiya</dc:creator>
		<pubDate>Thu, 19 Jun 2008 11:45:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/47-structs/#comment-19342</guid>
		<description>/* Program of Structure Exerice 1 */

#include &#60;iostream.h&#62;
#include &#60;conio.h&#62;

struct web
{
	int adv;
	float rate;
	float click;
};

float money(int adv,float rate,float click)
{
	float totalearning;
	totalearning = (adv * rate * click);
	return totalearning;
}

web mny;

void main()
{
	float res;

	clrscr();

	cout &#60;&#60; &#34;n How many advertise was shown: &#34;;
	cin &#62;&#62; mny.adv;

	cout &#60;&#60; &#34;n What was rate of click : &#34;;
	cin &#62;&#62; mny.rate;

	cout &#60;&#60; &#34;n Average of earning per click : &#34;;
	cin &#62;&#62; mny.click;

	res = money(mny.adv , mny.rate , mny.click);

	cout &#60;&#60; &#34;n The Total earning is &#34; &#60;&#60; res;

	getch();
}

/* End of Program */</description>
		<content:encoded><![CDATA[<p>/* Program of Structure Exerice 1 */</p>
<p>#include &lt;iostream.h&gt;<br />
#include &lt;conio.h&gt;</p>
<p>struct web<br />
{<br />
	int adv;<br />
	float rate;<br />
	float click;<br />
};</p>
<p>float money(int adv,float rate,float click)<br />
{<br />
	float totalearning;<br />
	totalearning = (adv * rate * click);<br />
	return totalearning;<br />
}</p>
<p>web mny;</p>
<p>void main()<br />
{<br />
	float res;</p>
<p>	clrscr();</p>
<p>	cout &lt;&lt; &quot;n How many advertise was shown: &quot;;<br />
	cin &gt;&gt; mny.adv;</p>
<p>	cout &lt;&lt; &quot;n What was rate of click : &quot;;<br />
	cin &gt;&gt; mny.rate;</p>
<p>	cout &lt;&lt; &quot;n Average of earning per click : &quot;;<br />
	cin &gt;&gt; mny.click;</p>
<p>	res = money(mny.adv , mny.rate , mny.click);</p>
<p>	cout &lt;&lt; &quot;n The Total earning is &quot; &lt;&lt; res;</p>
<p>	getch();<br />
}</p>
<p>/* End of Program */</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Learn C++ - &#187; 4.6 &#8212; Typedefs</title>
		<link>http://www.learncpp.com/cpp-tutorial/47-structs/#comment-13462</link>
		<dc:creator>Learn C++ - &#187; 4.6 &#8212; Typedefs</dc:creator>
		<pubDate>Tue, 29 Apr 2008 04:44:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/47-structs/#comment-13462</guid>
		<description>[...]  4.7 â€” Structs [...]</description>
		<content:encoded><![CDATA[<p>[...]  4.7 â€” Structs [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/47-structs/#comment-9481</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Wed, 12 Mar 2008 15:13:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/47-structs/#comment-9481</guid>
		<description>Wow, nice catch!  I fixed the closing tag.  Let me know if you are still having problems.</description>
		<content:encoded><![CDATA[<p>Wow, nice catch!  I fixed the closing tag.  Let me know if you are still having problems.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
