<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://hades.mech.northwestern.edu//index.php?action=history&amp;feed=atom&amp;title=ME333_W2011_Quiz_2_Solutions</id>
	<title>ME333 W2011 Quiz 2 Solutions - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://hades.mech.northwestern.edu//index.php?action=history&amp;feed=atom&amp;title=ME333_W2011_Quiz_2_Solutions"/>
	<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=ME333_W2011_Quiz_2_Solutions&amp;action=history"/>
	<updated>2026-05-20T19:51:53Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=ME333_W2011_Quiz_2_Solutions&amp;diff=19575&amp;oldid=prev</id>
		<title>Lynch at 10:02, 18 January 2011</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=ME333_W2011_Quiz_2_Solutions&amp;diff=19575&amp;oldid=prev"/>
		<updated>2011-01-18T10:02:32Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 05:02, 18 January 2011&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The main() function begins by statically allocating an array of doubles of length 6, given by arr[0] through arr[5].  arr is a pointer to (address of) the first element of the array, equivalent to &amp;amp;arr[0].  &amp;amp;arr[k] is a pointer to (address of) the kth element of the array, and k should be between 0 and 5.  arr[k] contains the (type double) contents of the kth element of the array, and *arr contains the (type double) contents of the first element of the array.  The contents of the kth element of the array can be (awkwardly) referenced as *(&amp;amp;arr[k]).&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The main() function begins by statically allocating an array of doubles of length 6, given by arr[0] through arr[5].  arr is a pointer to (address of) the first element of the array, equivalent to &amp;amp;arr[0].  &amp;amp;arr[k] is a pointer to (address of) the kth element of the array, and k should be between 0 and 5.  arr[k] contains the (type double) contents of the kth element of the array, and *arr contains the (type double) contents of the first element of the array.  The contents of the kth element of the array can be (awkwardly) referenced as *(&amp;amp;arr[k]).&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Q1:  initialize(arr) calls the function &quot;initialize&quot; with a pointer to first element of arr.  This function just goes through a while loop and puts the value of i into each arr[i] for i = 0..5.  So arr[1] = 1.0, arr[2] = 2.0, arr[3] = 3.0, arr[4] = 4.0.&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Q1:  initialize(arr) calls the function &quot;initialize&quot; with a pointer to first element of arr.  This function just goes through a while loop and puts the value of i into each arr[i] for i = 0..5.  So &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;arr[0] = 0.0, &#039;&#039;&#039;&lt;/ins&gt;arr[1] = 1.0, arr[2] = 2.0, arr[3] = 3.0, arr[4] = 4&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;.0&#039;&#039;&#039;, arr[5] = 5&lt;/ins&gt;.0.&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Q2.  The function &quot;add&quot; is called with a pointer to (address of) the first element of arr (let&#039;s call this local variable containing the address &quot;foo&quot;, to emphasize that this function has its own local copy of the address); the value 2.0 (the value of arr[2]), so the local variable addval (of type double) is set to 2.0; and 6 (from ARRAY_SIZE), so the local variable num (of type int) is set to 6.  In &quot;add&quot;, we execute a for loop using the counter i, which takes values from 0 to 5 (starts at 0 and runs the contents of the loop while i&amp;lt;num).  So the contents of the addresses foo[0..5] are set to the previous contents plus addval, which is 2.0.  Since the addresses of foo[0..5] are the same as the addresses of arr[0..5], we now have arr[1] = 3.0, arr[2] = 4.0, arr[3] = 5.0, arr[4] = 6.0.&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Q2.  The function &quot;add&quot; is called with a pointer to (address of) the first element of arr (let&#039;s call this local variable containing the address &quot;foo&quot;, to emphasize that this function has its own local copy of the address); the value 2.0 (the value of arr[2]), so the local variable addval (of type double) is set to 2.0; and 6 (from ARRAY_SIZE), so the local variable num (of type int) is set to 6.  In &quot;add&quot;, we execute a for loop using the counter i, which takes values from 0 to 5 (starts at 0 and runs the contents of the loop while i&amp;lt;num).  So the contents of the addresses foo[0..5] are set to the previous contents plus addval, which is 2.0.  Since the addresses of foo[0..5] are the same as the addresses of arr[0..5], we now have &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;arr[0] = 2.0, &#039;&#039;&#039;&lt;/ins&gt;arr[1] = 3.0, arr[2] = 4.0, arr[3] = 5.0, arr[4] = 6&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;.0&#039;&#039;&#039;, arr[5] = 7&lt;/ins&gt;.0.&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Q3. The function &quot;add&quot; is called with a pointer to (address of) arr[2] (let&#039;s call this local variable containing the address foo); the value 5.0, so the local variable addval is set to 5.0; and 2, so the local variable num is set to 2.  Note that in our function call &lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Q3. The function &quot;add&quot; is called with a pointer to (address of) arr[2] (let&#039;s call this local variable containing the address foo); the value 5.0, so the local variable addval is set to 5.0; and 2, so the local variable num is set to 2.  Note that in our function call &lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 10:&lt;/td&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 10:&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;the third argument takes the contents of the address arr (this is equivalent to arr[0]), which is 2.0 (a double), and &quot;casts&quot; it as a type int, to match what is required by the function &quot;add&quot;.  So &quot;add&quot; changes the contents of foo[0] to foo[0] + 5.0, and the contents of foo[1] to foo[1] + 5.0.  Since the address of foo[0] is the address of arr[2], this means that arr[2] back in the main function has had its contents changed to arr[2] + 5.0.  The address of foo[1] is the same as the address of arr[3], so arr[3] is now arr[3] + 5.0.  arr[0], arr[1], arr[4], and arr[5] remain unchanged.  &lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;the third argument takes the contents of the address arr (this is equivalent to arr[0]), which is 2.0 (a double), and &quot;casts&quot; it as a type int, to match what is required by the function &quot;add&quot;.  So &quot;add&quot; changes the contents of foo[0] to foo[0] + 5.0, and the contents of foo[1] to foo[1] + 5.0.  Since the address of foo[0] is the address of arr[2], this means that arr[2] back in the main function has had its contents changed to arr[2] + 5.0.  The address of foo[1] is the same as the address of arr[3], so arr[3] is now arr[3] + 5.0.  arr[0], arr[1], arr[4], and arr[5] remain unchanged.  &lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;So now arr[1] = 3.0, arr[2] = 9.0, arr[3] = 10.0, arr[4] = 6.0.&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;So now &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;arr[0] = 2.0, &#039;&#039;&#039;&lt;/ins&gt;arr[1] = 3.0, arr[2] = 9.0, arr[3] = 10.0, arr[4] = 6&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;.0&#039;&#039;&#039;, arr[5] = 7&lt;/ins&gt;.0.&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Lynch</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=ME333_W2011_Quiz_2_Solutions&amp;diff=19574&amp;oldid=prev</id>
		<title>Lynch at 10:00, 18 January 2011</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=ME333_W2011_Quiz_2_Solutions&amp;diff=19574&amp;oldid=prev"/>
		<updated>2011-01-18T10:00:09Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 05:00, 18 January 2011&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The main() function begins by statically allocating an array of doubles of length 6, &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;indexed&lt;/del&gt; by arr[0] through arr[5].  arr is a pointer to (address of) the first element of the array, equivalent to &amp;amp;arr[0].  &amp;amp;arr[k] is a pointer to (address of) the kth element of the array, and k should be between 0 and 5.  arr[k] contains the (type double) contents of the kth element of the array, and *arr contains the (type double) contents of the first element of the array.  The contents of the kth element of the array can be (awkwardly) referenced as *(&amp;amp;arr[k]).&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The main() function begins by statically allocating an array of doubles of length 6, &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;given&lt;/ins&gt; by arr[0] through arr[5].  arr is a pointer to (address of) the first element of the array, equivalent to &amp;amp;arr[0].  &amp;amp;arr[k] is a pointer to (address of) the kth element of the array, and k should be between 0 and 5.  arr[k] contains the (type double) contents of the kth element of the array, and *arr contains the (type double) contents of the first element of the array.  The contents of the kth element of the array can be (awkwardly) referenced as *(&amp;amp;arr[k]).&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Q1:  initialize(arr) calls the function &quot;initialize&quot; with a pointer to first element of arr.  This function just goes through a while loop and puts the value of i into each arr[i] for i = 0..5.  So arr[1] = 1.0, arr[2] = 2.0, arr[3] = 3.0, arr[4] = 4.0.&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Q1:  initialize(arr) calls the function &quot;initialize&quot; with a pointer to first element of arr.  This function just goes through a while loop and puts the value of i into each arr[i] for i = 0..5.  So arr[1] = 1.0, arr[2] = 2.0, arr[3] = 3.0, arr[4] = 4.0.&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Lynch</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=ME333_W2011_Quiz_2_Solutions&amp;diff=19573&amp;oldid=prev</id>
		<title>Lynch at 09:59, 18 January 2011</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=ME333_W2011_Quiz_2_Solutions&amp;diff=19573&amp;oldid=prev"/>
		<updated>2011-01-18T09:59:49Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 04:59, 18 January 2011&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The main function begins by statically allocating an array of doubles of length 6, indexed by arr[0] through arr[5].  arr is a pointer to (address of) the first element of the array, equivalent to &amp;amp;arr[0].  &amp;amp;arr[k] is a pointer to (address of) the kth element of the array, and k should be between 0 and 5.  arr[k] contains the (type double) contents of the kth element of the array, and *arr contains the (type double) contents of the first element of the array.  The contents of the kth element of the array can be (awkwardly) referenced as *(&amp;amp;arr[k]).&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The main&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;()&lt;/ins&gt; function begins by statically allocating an array of doubles of length 6, indexed by arr[0] through arr[5].  arr is a pointer to (address of) the first element of the array, equivalent to &amp;amp;arr[0].  &amp;amp;arr[k] is a pointer to (address of) the kth element of the array, and k should be between 0 and 5.  arr[k] contains the (type double) contents of the kth element of the array, and *arr contains the (type double) contents of the first element of the array.  The contents of the kth element of the array can be (awkwardly) referenced as *(&amp;amp;arr[k]).&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Q1:  initialize(arr) calls the function &quot;initialize&quot; with a pointer to first element of arr.  This function just goes through a while loop and puts the value of i into each arr[i] for i = 0..5.  So arr[1] = 1.0, arr[2] = 2.0, arr[3] = 3.0, arr[4] = 4.0.&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Q1:  initialize(arr) calls the function &quot;initialize&quot; with a pointer to first element of arr.  This function just goes through a while loop and puts the value of i into each arr[i] for i = 0..5.  So arr[1] = 1.0, arr[2] = 2.0, arr[3] = 3.0, arr[4] = 4.0.&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Lynch</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=ME333_W2011_Quiz_2_Solutions&amp;diff=19572&amp;oldid=prev</id>
		<title>Lynch at 09:59, 18 January 2011</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=ME333_W2011_Quiz_2_Solutions&amp;diff=19572&amp;oldid=prev"/>
		<updated>2011-01-18T09:59:38Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 04:59, 18 January 2011&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The main function begins by statically allocating an array of doubles of length 6, indexed by arr[0] through arr[5].  arr is a pointer to (address of) the first element of the array&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;;&lt;/del&gt; arr[k] &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;contains&lt;/del&gt; &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;the&lt;/del&gt; &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;contents&lt;/del&gt; of the kth element of the array &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;(&lt;/del&gt;k &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;from&lt;/del&gt; 0 &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;to&lt;/del&gt; 5&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;),&lt;/del&gt; &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;which&lt;/del&gt; &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;is&lt;/del&gt; &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;of&lt;/del&gt; type double&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;;&lt;/del&gt; and &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;amp;&lt;/del&gt;arr&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[k]&lt;/del&gt; &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;is&lt;/del&gt; &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;a&lt;/del&gt; &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;pointer&lt;/del&gt; &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;to&lt;/del&gt; &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;(address&lt;/del&gt; of&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;)&lt;/del&gt; the kth element of the array.&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The main function begins by statically allocating an array of doubles of length 6, indexed by arr[0] through arr[5].  arr is a pointer to (address of) the first element of the array&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;,&lt;/ins&gt; &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;equivalent to &amp;amp;arr[0].  &amp;amp;&lt;/ins&gt;arr[k] &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;is&lt;/ins&gt; &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;a&lt;/ins&gt; &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;pointer to (address&lt;/ins&gt; of&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;)&lt;/ins&gt; the kth element of the array&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;, and&lt;/ins&gt; k &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;should be between&lt;/ins&gt; 0 &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;and&lt;/ins&gt; 5&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;.&lt;/ins&gt;  &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;arr[k]&lt;/ins&gt; &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;contains&lt;/ins&gt; &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;the (&lt;/ins&gt;type double&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;) contents of the kth element of the array,&lt;/ins&gt; and &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;*&lt;/ins&gt;arr &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;contains&lt;/ins&gt; &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;the&lt;/ins&gt; &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;(type&lt;/ins&gt; &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;double)&lt;/ins&gt; &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;contents of the first element of the array.  The contents&lt;/ins&gt; of the kth element of the array&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt; can be (awkwardly) referenced as *(&amp;amp;arr[k])&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Q1:  initialize(arr) calls the function &quot;initialize&quot; with a pointer to first element of arr.  This function just goes through a while loop and puts the value of i into each arr[i] for i = 0..5.  So arr[1] = 1.0, arr[2] = 2.0, arr[3] = 3.0, arr[4] = 4.0.&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Q1:  initialize(arr) calls the function &quot;initialize&quot; with a pointer to first element of arr.  This function just goes through a while loop and puts the value of i into each arr[i] for i = 0..5.  So arr[1] = 1.0, arr[2] = 2.0, arr[3] = 3.0, arr[4] = 4.0.&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Lynch</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=ME333_W2011_Quiz_2_Solutions&amp;diff=19571&amp;oldid=prev</id>
		<title>Lynch: New page: The main function begins by statically allocating an array of doubles of length 6, indexed by arr[0] through arr[5].  arr is a pointer to (address of) the first element of the array; arr[k...</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=ME333_W2011_Quiz_2_Solutions&amp;diff=19571&amp;oldid=prev"/>
		<updated>2011-01-18T09:54:54Z</updated>

		<summary type="html">&lt;p&gt;New page: The main function begins by statically allocating an array of doubles of length 6, indexed by arr[0] through arr[5].  arr is a pointer to (address of) the first element of the array; arr[k...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The main function begins by statically allocating an array of doubles of length 6, indexed by arr[0] through arr[5].  arr is a pointer to (address of) the first element of the array; arr[k] contains the contents of the kth element of the array (k from 0 to 5), which is of type double; and &amp;amp;arr[k] is a pointer to (address of) the kth element of the array.&lt;br /&gt;
&lt;br /&gt;
Q1:  initialize(arr) calls the function &amp;quot;initialize&amp;quot; with a pointer to first element of arr.  This function just goes through a while loop and puts the value of i into each arr[i] for i = 0..5.  So arr[1] = 1.0, arr[2] = 2.0, arr[3] = 3.0, arr[4] = 4.0.&lt;br /&gt;
&lt;br /&gt;
Q2.  The function &amp;quot;add&amp;quot; is called with a pointer to (address of) the first element of arr (let&amp;#039;s call this local variable containing the address &amp;quot;foo&amp;quot;, to emphasize that this function has its own local copy of the address); the value 2.0 (the value of arr[2]), so the local variable addval (of type double) is set to 2.0; and 6 (from ARRAY_SIZE), so the local variable num (of type int) is set to 6.  In &amp;quot;add&amp;quot;, we execute a for loop using the counter i, which takes values from 0 to 5 (starts at 0 and runs the contents of the loop while i&amp;lt;num).  So the contents of the addresses foo[0..5] are set to the previous contents plus addval, which is 2.0.  Since the addresses of foo[0..5] are the same as the addresses of arr[0..5], we now have arr[1] = 3.0, arr[2] = 4.0, arr[3] = 5.0, arr[4] = 6.0.&lt;br /&gt;
&lt;br /&gt;
Q3. The function &amp;quot;add&amp;quot; is called with a pointer to (address of) arr[2] (let&amp;#039;s call this local variable containing the address foo); the value 5.0, so the local variable addval is set to 5.0; and 2, so the local variable num is set to 2.  Note that in our function call &lt;br /&gt;
&lt;br /&gt;
 add(&amp;amp;arr[2], 5.0, ((int) *arr));&lt;br /&gt;
&lt;br /&gt;
the third argument takes the contents of the address arr (this is equivalent to arr[0]), which is 2.0 (a double), and &amp;quot;casts&amp;quot; it as a type int, to match what is required by the function &amp;quot;add&amp;quot;.  So &amp;quot;add&amp;quot; changes the contents of foo[0] to foo[0] + 5.0, and the contents of foo[1] to foo[1] + 5.0.  Since the address of foo[0] is the address of arr[2], this means that arr[2] back in the main function has had its contents changed to arr[2] + 5.0.  The address of foo[1] is the same as the address of arr[3], so arr[3] is now arr[3] + 5.0.  arr[0], arr[1], arr[4], and arr[5] remain unchanged.  &lt;br /&gt;
So now arr[1] = 3.0, arr[2] = 9.0, arr[3] = 10.0, arr[4] = 6.0.&lt;/div&gt;</summary>
		<author><name>Lynch</name></author>
	</entry>
</feed>