<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="et">
	<id>http://courses.cs.taltech.ee/w/index.php?action=history&amp;feed=atom&amp;title=Stack_Exploration_%28ITS8020%29</id>
	<title>Stack Exploration (ITS8020) - Redigeerimiste ajalugu</title>
	<link rel="self" type="application/atom+xml" href="http://courses.cs.taltech.ee/w/index.php?action=history&amp;feed=atom&amp;title=Stack_Exploration_%28ITS8020%29"/>
	<link rel="alternate" type="text/html" href="http://courses.cs.taltech.ee/w/index.php?title=Stack_Exploration_(ITS8020)&amp;action=history"/>
	<updated>2026-05-21T19:02:19Z</updated>
	<subtitle>Selle lehekülje redigeerimiste ajalugu</subtitle>
	<generator>MediaWiki 1.35.9</generator>
	<entry>
		<id>http://courses.cs.taltech.ee/w/index.php?title=Stack_Exploration_(ITS8020)&amp;diff=7046&amp;oldid=prev</id>
		<title>Irve: Uus lehekülg: &#039;{{its8020}} In preparation for memory management, we shall investigate [http://en.wikipedia.org/wiki/Call_stack call stack] contents.  == Task ==  Write some small program for fu...&#039;</title>
		<link rel="alternate" type="text/html" href="http://courses.cs.taltech.ee/w/index.php?title=Stack_Exploration_(ITS8020)&amp;diff=7046&amp;oldid=prev"/>
		<updated>2018-09-14T05:38:53Z</updated>

		<summary type="html">&lt;p&gt;Uus lehekülg: &amp;#039;{{its8020}} In preparation for memory management, we shall investigate [http://en.wikipedia.org/wiki/Call_stack call stack] contents.  == Task ==  Write some small program for fu...&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Uus lehekülg&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{its8020}}&lt;br /&gt;
In preparation for memory management, we shall investigate [http://en.wikipedia.org/wiki/Call_stack call stack] contents.&lt;br /&gt;
&lt;br /&gt;
== Task ==&lt;br /&gt;
&lt;br /&gt;
Write some small program for further exploration. The program should contain:&lt;br /&gt;
* function main() containing:&lt;br /&gt;
** at least 3 integers, with some (different) default values&lt;br /&gt;
** a string&lt;br /&gt;
* function void foo(int argument) containing:&lt;br /&gt;
** at least 2 integers, with some default values&lt;br /&gt;
This base program can do practically anything (including nothing), as long as the function foo() runs.&lt;br /&gt;
&lt;br /&gt;
# Modify the program to print the &amp;#039;&amp;#039;memory addresses&amp;#039;&amp;#039; of all the variables. Use &amp;quot;%p&amp;quot; for [http://linux.die.net/man/3/printf printf()] function. Use &amp;amp; operator on the variable to get the memory address as a value.&lt;br /&gt;
# Within function foo(), use the memory address of the first declared variable to print out the value of address which precedes it and the memory address which follows it. (Use * operator to read memory from given location)&lt;br /&gt;
# Can you go further? Can you read the variables of main() just by modifying the address of a variable in foo()? (&amp;#039;&amp;#039;Yes, but try it out&amp;#039;&amp;#039;)&lt;br /&gt;
# Can you print the string from main()? Is it located in the stack?&lt;br /&gt;
  // note that there is a difference between the lines:&lt;br /&gt;
  char s[] = &amp;quot;foo:asdasdasd&amp;quot;; // is allocated on the stack&lt;br /&gt;
  char *s = &amp;quot;bar:dsadsadas&amp;quot;;  // is not allocated on the stack&lt;br /&gt;
# Comment some of the lines which print the addresses of variables in main() (from task 1), check that your program does not use them -- can you still print them by using an address from foo()?&lt;br /&gt;
# Put the variables back to the stack. Write a function which tries to print out all the stack (4 bytes per line using printf() with &amp;quot;%08x\n&amp;quot;. The program should crash at some point with a segmentation fault; this is the expected and desired result of the task and should be valued!&lt;br /&gt;
: Note: For your convenience print the memory location address, then its contents as decimal, hexadecimal, and char.&lt;/div&gt;</summary>
		<author><name>Irve</name></author>
	</entry>
</feed>