<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.kram.nz/index.php?action=history&amp;feed=atom&amp;title=SE250%3Alab-2%3Assre005</id>
	<title>SE250:lab-2:ssre005 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.kram.nz/index.php?action=history&amp;feed=atom&amp;title=SE250%3Alab-2%3Assre005"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-2:ssre005&amp;action=history"/>
	<updated>2026-06-08T20:35:00Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.kram.nz/index.php?title=SE250:lab-2:ssre005&amp;diff=5312&amp;oldid=prev</id>
		<title>Mark: 10 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-2:ssre005&amp;diff=5312&amp;oldid=prev"/>
		<updated>2008-11-03T05:19:13Z</updated>

		<summary type="html">&lt;p&gt;10 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Started off having trouble finding Emacs, compiling a code and finding MS Word.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main (void)&lt;br /&gt;
{&lt;br /&gt;
    int *ip;&lt;br /&gt;
    printf(&amp;quot;%d\n&amp;quot;, sizeof(ip));&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code failed to compile as the pointer ‘ip’ was not set to any variable.  As explained by the tutor, if the pointer is not set to point at the address of an existing value, it will point at a random address in memory and thus the compiler refuses to compile to code.&lt;br /&gt;
&lt;br /&gt;
Thus, the following code was devised:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
int main (void)&lt;br /&gt;
{&lt;br /&gt;
    int x = 10;&lt;br /&gt;
    int *ip = &amp;amp;x;&lt;br /&gt;
    printf(&amp;quot;%d\n&amp;quot;, sizeof(ip));&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Problems with compiling still persisted but after changing the setup of emacs, the problem was solved and the value for the size of a pointer of type int returned was 4.&lt;br /&gt;
&lt;br /&gt;
To answer the question: “Are all pointers the same size?  What other data types in C are the same size?” the pointer’s type was changed to various others to see if the size output given was still 4(windows and linux).&lt;br /&gt;
&lt;br /&gt;
Double –  4; lab2.c:6: warning: initialization from incompatible pointer type&lt;br /&gt;
&lt;br /&gt;
Long – 4; lab2.c:6: warning: initialization from incompatible pointer type&lt;br /&gt;
&lt;br /&gt;
Short – 4; lab2.c:6: warning: initialization from incompatible pointer type&lt;br /&gt;
&lt;br /&gt;
Char – 4; lab2.c:6: warning: initialization from incompatible pointer type&lt;br /&gt;
&lt;br /&gt;
Float – 4; lab2.c:6: warning: initialization from incompatible pointer type&lt;br /&gt;
&lt;br /&gt;
Another student pointed out that you do not need to have a pointer pointing to a specific address for a size value to be returned.  My earlier problems with compiling were actually caused by not using the correct commands in the command line of emacs. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main (void)&lt;br /&gt;
{&lt;br /&gt;
    // int x = 10;&lt;br /&gt;
    double *ip;//= &amp;amp;x;&lt;br /&gt;
    printf(&amp;quot;%d\n&amp;quot;, sizeof(ip));&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
With the unnecessary lines commented out, the code was run again to produce exactly the same results without the warnings. (Same results with linux).&lt;br /&gt;
&lt;br /&gt;
2.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main (void)&lt;br /&gt;
{&lt;br /&gt;
    int x;&lt;br /&gt;
    int y;&lt;br /&gt;
  &lt;br /&gt;
   printf(&amp;quot;&amp;amp;x = %p, &amp;amp;y = %p, diff = %ld\n&amp;quot;, &amp;amp;x, &amp;amp;y, (long)(&amp;amp;x − &amp;amp;y));&lt;br /&gt;
   return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Returned:  &lt;br /&gt;
&amp;amp;x = 0x22ccc4, &amp;amp;y = 0x22ccc0, diff = 1 (Windows)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0xfff3275c, &amp;amp;y = 0xfff32758, diff = 1 (Iinux)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replacing the line “(long)(&amp;amp;x - &amp;amp;y)” with (long)&amp;amp;x - (long)&amp;amp;y returns the output:&lt;br /&gt;
&amp;amp;x = 0x22ccc4, &amp;amp;y = 0x22ccc0, diff = 4 (Windows)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0xfff3275c, &amp;amp;y = 0xfff32758, diff = 4 (Iinux)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main (void)&lt;br /&gt;
{&lt;br /&gt;
    int x;&lt;br /&gt;
    char arr[ 4 ];&lt;br /&gt;
    int y;&lt;br /&gt;
    printf(&amp;quot;&amp;amp;x = %p, &amp;amp;y = %p, diff = %ld\n&amp;quot;, &amp;amp;x, &amp;amp;y, (long)&amp;amp;x - (long)&amp;amp;y);&lt;br /&gt;
    printf(&amp;quot;Address of arr is %p.  Value of &amp;amp;arr is %p.  The value of arr+4 is %c. The value of &amp;amp;arr[4] is %p&amp;quot;, &amp;amp;arr, &amp;amp;arr, arr + 4, &amp;amp;arr[4]);&lt;br /&gt;
&lt;br /&gt;
   return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Returned:  &lt;br /&gt;
Windows:&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0x22ccc4, &amp;amp;y = 0x22ccbc, diff = 8&lt;br /&gt;
&lt;br /&gt;
Address of arr is 0x22ccc0.  Value of &amp;amp;arr is 0x22ccc0.  The value of arr+4 is Ä. The value of &amp;amp;arr[4] is 0x22ccc4&lt;br /&gt;
&lt;br /&gt;
Linux:&lt;br /&gt;
&amp;amp;x = 0xffd6075c, &amp;amp;y = 0xffd60754, diff = 8&lt;br /&gt;
&lt;br /&gt;
Address of arr is 0xffd60758.  Value of &amp;amp;arr is 0xffd60758.  The value of arr+4&lt;br /&gt;
&lt;br /&gt;
is \. The value of &amp;amp;arr[4] is 0xffd6075c&lt;br /&gt;
&lt;br /&gt;
Varying the size of the array from 0 to 10 produced the following results:&lt;br /&gt;
&lt;br /&gt;
For arr[0]:&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0x22ccbc, &amp;amp;y = 0x22cc9c, diff = 32&lt;br /&gt;
&lt;br /&gt;
Diff = 4 (linux)&lt;br /&gt;
&lt;br /&gt;
For arr[1]:&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0x22ccc4, &amp;amp;y = 0x22ccbc, diff = 8&lt;br /&gt;
&lt;br /&gt;
Diff = 4 (linux)&lt;br /&gt;
&lt;br /&gt;
For arr[2]:&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0x22ccc4, &amp;amp;y = 0x22ccbc, diff = 8&lt;br /&gt;
&lt;br /&gt;
Diff = 4 (linux)&lt;br /&gt;
&lt;br /&gt;
For arr[3]:&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0x22ccbc, &amp;amp;y = 0x22cc9c, diff = 32&lt;br /&gt;
&lt;br /&gt;
Diff = 4 (linux)&lt;br /&gt;
&lt;br /&gt;
For arr[4]:&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0x22ccc4, &amp;amp;y = 0x22ccbc, diff = 8&lt;br /&gt;
&lt;br /&gt;
Diff = 8 (linux)&lt;br /&gt;
&lt;br /&gt;
For arr[5]:&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0x22ccbc, &amp;amp;y = 0x22cc9c, diff = 32&lt;br /&gt;
&lt;br /&gt;
Diff = 4 (linux)&lt;br /&gt;
&lt;br /&gt;
For arr[6]:&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0x22ccbc, &amp;amp;y = 0x22cc9c, diff = 32&lt;br /&gt;
&lt;br /&gt;
Diff = 4 (linux)&lt;br /&gt;
&lt;br /&gt;
For arr[7]:&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0x22ccbc, &amp;amp;y = 0x22cc9c, diff = 32&lt;br /&gt;
&lt;br /&gt;
Diff = 4 (linux)&lt;br /&gt;
&lt;br /&gt;
For arr[8]:&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0x22ccc4, &amp;amp;y = 0x22ccb4, diff = 16&lt;br /&gt;
&lt;br /&gt;
Diff = 4 (linux)&lt;br /&gt;
&lt;br /&gt;
For arr[9]:&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0x22ccbc, &amp;amp;y = 0x22cc9c, diff = 32&lt;br /&gt;
&lt;br /&gt;
Diff = 4 (linux)&lt;br /&gt;
&lt;br /&gt;
For arr[10]:&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0x22ccbc, &amp;amp;y = 0x22cc9c, diff = 32&lt;br /&gt;
&lt;br /&gt;
Diff = 4 (linux)&lt;br /&gt;
&lt;br /&gt;
Reverting the array to size 4, setting x and y to 0 and arr[4] to 10 and printing out the values of x and y with the following code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main (void)&lt;br /&gt;
{&lt;br /&gt;
    int x;&lt;br /&gt;
    char arr[ 4 ] = “10”;&lt;br /&gt;
    int y;&lt;br /&gt;
    printf(&amp;quot;&amp;amp;x = %p, &amp;amp;y = %p, diff = %ld\n&amp;quot;, &amp;amp;x, &amp;amp;y, (long)&amp;amp;x - (long)&amp;amp;y);&lt;br /&gt;
    printf(&amp;quot;Address of arr is %p.  Value of &amp;amp;arr is %p.  The value of arr+4 is %c. The value of &amp;amp;arr[4] is %p&amp;quot;, &amp;amp;arr, &amp;amp;arr, arr + 4, &amp;amp;arr[4]);&lt;br /&gt;
&lt;br /&gt;
   return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Produced the output:&lt;br /&gt;
&lt;br /&gt;
Windows:&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0x22ccc4, &amp;amp;y = 0x22ccbc, diff = 8&lt;br /&gt;
&lt;br /&gt;
Address of arr is 0x22ccc0.  Value of &amp;amp;arr is 0x22ccc0.  The value of arr+4 is Ä. The value of &amp;amp;arr[4] is 0x22ccc4&lt;br /&gt;
&lt;br /&gt;
x = 0, y = 0&lt;br /&gt;
&lt;br /&gt;
Linux:&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0xff88e75c, &amp;amp;y = 0xff88e754, diff = 8&lt;br /&gt;
&lt;br /&gt;
Address of arr is 0xff88e758.  Value of &amp;amp;arr is 0xff88e758.  The value of arr+4&lt;br /&gt;
&lt;br /&gt;
is \. The value of &amp;amp;arr[4] is 0xff88e75c&lt;br /&gt;
&lt;br /&gt;
4.  x and y declared as global variables and the last 2 exercises repeated.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    int x = 0;&lt;br /&gt;
    int y = 0;&lt;br /&gt;
int main (void)&lt;br /&gt;
{&lt;br /&gt;
    char arr[4] = &amp;quot;10&amp;quot;;&lt;br /&gt;
    printf(&amp;quot;&amp;amp;x = %p, &amp;amp;y = %p, diff = %ld\n&amp;quot;, &amp;amp;x, &amp;amp;y, (long)&amp;amp;x - (long)&amp;amp;y);&lt;br /&gt;
   return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
arr[0]:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Windows :  &amp;amp;x = 0x403030, &amp;amp;y = 0x403020, diff = 16&lt;br /&gt;
&lt;br /&gt;
Linux: &amp;amp;x = 0x10010a64, &amp;amp;y = 0x10010a68, diff = -4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
arr[1]:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Windows:  &amp;amp;x = 0x403030, &amp;amp;y = 0x403020, diff = 16&lt;br /&gt;
&lt;br /&gt;
Linux: &amp;amp;x = 0x10010a64, &amp;amp;y = 0x10010a68, diff = -4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
arr[2]:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0x403030, &amp;amp;y = 0x403020, diff = 16&lt;br /&gt;
&lt;br /&gt;
Linux: &amp;amp;x = 0x10010a64, &amp;amp;y = 0x10010a68, diff = -4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
arr[3]:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0x403030, &amp;amp;y = 0x403020, diff = 16&lt;br /&gt;
&lt;br /&gt;
Linux: &amp;amp;x = 0x10010a64, &amp;amp;y = 0x10010a68, diff = -4&lt;br /&gt;
&lt;br /&gt;
arr[4]:&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0x403030, &amp;amp;y = 0x403020, diff = 16&lt;br /&gt;
&lt;br /&gt;
Linux: &amp;amp;x = 0x10010a64, &amp;amp;y = 0x10010a68, diff = -4&lt;br /&gt;
&lt;br /&gt;
arr[5]:&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0x403030, &amp;amp;y = 0x403020, diff = 16&lt;br /&gt;
&lt;br /&gt;
Linux: &amp;amp;x = 0x10010a64, &amp;amp;y = 0x10010a68, diff = -4&lt;br /&gt;
&lt;br /&gt;
arr[6]:&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0x403030, &amp;amp;y = 0x403020, diff = 16&lt;br /&gt;
&lt;br /&gt;
Linux: &amp;amp;x = 0x10010a64, &amp;amp;y = 0x10010a68, diff = -4&lt;br /&gt;
&lt;br /&gt;
arr[7]:&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0x403030, &amp;amp;y = 0x403020, diff = 16&lt;br /&gt;
&lt;br /&gt;
Linux: &amp;amp;x = 0x10010a64, &amp;amp;y = 0x10010a68, diff = -4&lt;br /&gt;
&lt;br /&gt;
arr[8]:&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0x403030, &amp;amp;y = 0x403020, diff = 16&lt;br /&gt;
&lt;br /&gt;
Linux: &amp;amp;x = 0x10010a64, &amp;amp;y = 0x10010adc, diff = -4&lt;br /&gt;
&lt;br /&gt;
arr[9]:&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0x403030, &amp;amp;y = 0x403020, diff = 16&lt;br /&gt;
&lt;br /&gt;
Linux: &amp;amp;x = 0x10010a64, &amp;amp;y = 0x10010adc, diff = -4&lt;br /&gt;
&lt;br /&gt;
arr[10]:&lt;br /&gt;
&lt;br /&gt;
&amp;amp;x = 0x403030, &amp;amp;y = 0x403020, diff = 16&lt;br /&gt;
&lt;br /&gt;
Linux: &amp;amp;x = 0x10010a64, &amp;amp;y = 0x10010adc, diff = -4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main (void)&lt;br /&gt;
{&lt;br /&gt;
    int *p1, *p2;&lt;br /&gt;
    int q;&lt;br /&gt;
    p1 = &amp;amp;q;&lt;br /&gt;
    int r;&lt;br /&gt;
    p2 = &amp;amp;r;&lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;p1 = %p, p2 = %p&amp;quot;, p1, p2);&lt;br /&gt;
   return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Result:&lt;br /&gt;
p1 = 0x22ccbc, p2 = 0x22ccb8(windows)&lt;br /&gt;
p1 = 0xffc80754, p2 = 0xffc80750 (linux)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6.&lt;br /&gt;
Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
char *local_str() {&lt;br /&gt;
    char s[8] = &amp;quot;0123456&amp;quot;;&lt;br /&gt;
    return s;&lt;br /&gt;
}&lt;br /&gt;
char *local_str2() {&lt;br /&gt;
    char s[8] = &amp;quot;abcdefg&amp;quot;;&lt;br /&gt;
    return s;&lt;br /&gt;
}&lt;br /&gt;
char *static_str() {&lt;br /&gt;
    static char s[8] = &amp;quot;tuvwxyz&amp;quot;;&lt;br /&gt;
    return s;&lt;br /&gt;
}&lt;br /&gt;
char *malloc_str() {&lt;br /&gt;
    char *s = malloc(8);&lt;br /&gt;
    strcpy( s, &amp;quot;hijklmn&amp;quot; );&lt;br /&gt;
    return s;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main (void)&lt;br /&gt;
    &lt;br /&gt;
{&lt;br /&gt;
    char *sp;&lt;br /&gt;
    sp = local_str( );&lt;br /&gt;
    printf( &amp;quot;sp = %p(%s)\n&amp;quot;, sp, sp );&lt;br /&gt;
    strcpy(sp, &amp;quot;XXXXXXX&amp;quot;);&lt;br /&gt;
    printf(&amp;quot;sp X&amp;#039;d = %p(%s)\n&amp;quot;, sp, sp);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    sp = local_str();&lt;br /&gt;
    local_str2();&lt;br /&gt;
    printf( &amp;quot;sp = %p(%s)\n&amp;quot;, sp, sp );&lt;br /&gt;
    strcpy(sp, &amp;quot;XXXXXXX&amp;quot;);&lt;br /&gt;
    printf(&amp;quot;sp X&amp;#039;d = %p(%s)\n&amp;quot;, sp, sp);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    sp = static_str();&lt;br /&gt;
    local_str2();&lt;br /&gt;
    printf( &amp;quot;sp = %p(%s)\n&amp;quot;, sp, sp );&lt;br /&gt;
    strcpy(sp, &amp;quot;XXXXXXX&amp;quot;);&lt;br /&gt;
    printf(&amp;quot;sp X&amp;#039;d = %p(%s)\n&amp;quot;, sp, sp);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    sp = malloc_str();&lt;br /&gt;
    local_str2();&lt;br /&gt;
    printf( &amp;quot;sp = %p(%s)\n&amp;quot;, sp, sp );&lt;br /&gt;
    strcpy(sp, &amp;quot;XXXXXXX&amp;quot;);&lt;br /&gt;
    printf(&amp;quot;sp X&amp;#039;d = %p(%s)\n&amp;quot;, sp, sp);&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Results:&lt;br /&gt;
Windows:&lt;br /&gt;
sp = 0x22cc90(456)&lt;br /&gt;
sp X&amp;#039;d = 0x22cc90(-0@)&lt;br /&gt;
sp = 0x22cc90(efg)&lt;br /&gt;
sp X&amp;#039;d = 0x22cc90(-0@)&lt;br /&gt;
sp = 0x402000(tuvwxyz)&lt;br /&gt;
sp X&amp;#039;d = 0x402000(XXXXXXX)&lt;br /&gt;
sp = 0xfb01a0(hijklmn)&lt;br /&gt;
sp X&amp;#039;d = 0xfb01a0(XXXXXXX)&lt;br /&gt;
&lt;br /&gt;
Linux:&lt;br /&gt;
sp = 0xffaa1724( þîÐ►)&lt;br /&gt;
sp X&amp;#039;d = 0xffaa1724(XXXXXXX)&lt;br /&gt;
sp = 0xffaa1724(abcdefg)&lt;br /&gt;
sp X&amp;#039;d = 0xffaa1724(XXXXXXX)&lt;br /&gt;
sp = 0x10010dc0(tuvwxyz)&lt;br /&gt;
sp X&amp;#039;d = 0x10010dc0(XXXXXXX)&lt;br /&gt;
sp = 0x10011008(hijklmn)&lt;br /&gt;
sp X&amp;#039;d = 0x10011008(XXXXXXX)&lt;br /&gt;
&lt;br /&gt;
I am unsure of what obersvation I need to make. In Windows, the original string which stores numbers returns the last 3 values only and in Linux the first string returns jibberish. In Windows, the strcopy method returns jibberish twice where in linux it works all 4 times.&lt;br /&gt;
&lt;br /&gt;
7.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
struct {&lt;br /&gt;
    char my_char;&lt;br /&gt;
    short my_short;&lt;br /&gt;
    int my_int;&lt;br /&gt;
    long my_long;&lt;br /&gt;
    float my_float;&lt;br /&gt;
    double my_double;&lt;br /&gt;
} my_struct;&lt;br /&gt;
&lt;br /&gt;
int main (void)&lt;br /&gt;
{&lt;br /&gt;
    &lt;br /&gt;
    printf( &amp;quot;&amp;amp;my struct = %p\n&amp;quot;, my_struct );&lt;br /&gt;
printf( &amp;quot;offsets:\n&amp;quot;&lt;br /&gt;
	&amp;quot;my_char: %ld\n&amp;quot;&lt;br /&gt;
	&amp;quot;my_short: %ld\n&amp;quot;&lt;br /&gt;
	&amp;quot;my_int: %ld\n&amp;quot;&lt;br /&gt;
	&amp;quot;my_long: %ld\n&amp;quot;&lt;br /&gt;
	&amp;quot;my_float: %ld\n&amp;quot;&lt;br /&gt;
	&amp;quot;my_double: %ld\n&amp;quot;,&lt;br /&gt;
	(long)&amp;amp;my_struct - (long)&amp;amp;my_struct.my_char,&lt;br /&gt;
	(long)&amp;amp;my_struct - (long)&amp;amp;my_struct.my_short,&lt;br /&gt;
	(long)&amp;amp;my_struct - (long)&amp;amp;my_struct.my_int,&lt;br /&gt;
	(long)&amp;amp;my_struct - (long)&amp;amp;my_struct.my_long,&lt;br /&gt;
	(long)&amp;amp;my_struct - (long)&amp;amp;my_struct.my_float,&lt;br /&gt;
	(long)&amp;amp;my_struct - (long)&amp;amp;my_struct.my_double );&lt;br /&gt;
&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Results:&lt;br /&gt;
&lt;br /&gt;
Windows:&lt;br /&gt;
&lt;br /&gt;
offsets:&lt;br /&gt;
&lt;br /&gt;
my_char: 0&lt;br /&gt;
&lt;br /&gt;
my_short: -2&lt;br /&gt;
&lt;br /&gt;
my_int: -4&lt;br /&gt;
&lt;br /&gt;
my_long: -8&lt;br /&gt;
&lt;br /&gt;
my_float: -12&lt;br /&gt;
&lt;br /&gt;
my_double: -16&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Linux:&lt;br /&gt;
&lt;br /&gt;
offsets:&lt;br /&gt;
&lt;br /&gt;
my_char: 0&lt;br /&gt;
&lt;br /&gt;
my_short: -2&lt;br /&gt;
&lt;br /&gt;
my_int: -4&lt;br /&gt;
&lt;br /&gt;
my_long: -8&lt;br /&gt;
&lt;br /&gt;
my_float: -12&lt;br /&gt;
&lt;br /&gt;
my_double: -16&lt;br /&gt;
&lt;br /&gt;
Results are exactly the same.&lt;br /&gt;
&lt;br /&gt;
8.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
union{&lt;br /&gt;
    char my_char;&lt;br /&gt;
    short my_short;&lt;br /&gt;
    int my_int;&lt;br /&gt;
    long my_long;&lt;br /&gt;
    float my_float;&lt;br /&gt;
    double my_double;&lt;br /&gt;
} my_struct;&lt;br /&gt;
&lt;br /&gt;
int main (void)&lt;br /&gt;
{&lt;br /&gt;
    &lt;br /&gt;
    printf( &amp;quot;&amp;amp;my struct = %p\n&amp;quot;, my_struct );&lt;br /&gt;
printf( &amp;quot;offsets:\n&amp;quot;&lt;br /&gt;
	&amp;quot;my_char: %ld\n&amp;quot;&lt;br /&gt;
	&amp;quot;my_short: %ld\n&amp;quot;&lt;br /&gt;
	&amp;quot;my_int: %ld\n&amp;quot;&lt;br /&gt;
	&amp;quot;my_long: %ld\n&amp;quot;&lt;br /&gt;
	&amp;quot;my_float: %ld\n&amp;quot;&lt;br /&gt;
	&amp;quot;my_double: %ld\n&amp;quot;,&lt;br /&gt;
	(long)&amp;amp;my_struct - (long)&amp;amp;my_struct.my_char,&lt;br /&gt;
	(long)&amp;amp;my_struct - (long)&amp;amp;my_struct.my_short,&lt;br /&gt;
	(long)&amp;amp;my_struct - (long)&amp;amp;my_struct.my_int,&lt;br /&gt;
	(long)&amp;amp;my_struct - (long)&amp;amp;my_struct.my_long,&lt;br /&gt;
	(long)&amp;amp;my_struct - (long)&amp;amp;my_struct.my_float,&lt;br /&gt;
	(long)&amp;amp;my_struct - (long)&amp;amp;my_struct.my_double );&lt;br /&gt;
&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Results:&lt;br /&gt;
&lt;br /&gt;
Windows:&lt;br /&gt;
&lt;br /&gt;
offsets:&lt;br /&gt;
&lt;br /&gt;
my_char: 0&lt;br /&gt;
&lt;br /&gt;
my_short: 0&lt;br /&gt;
&lt;br /&gt;
my_int: 0&lt;br /&gt;
&lt;br /&gt;
my_long: 0&lt;br /&gt;
&lt;br /&gt;
my_float: 0&lt;br /&gt;
&lt;br /&gt;
my_double: 0&lt;br /&gt;
&lt;br /&gt;
Linux:&lt;br /&gt;
&lt;br /&gt;
offsets:&lt;br /&gt;
&lt;br /&gt;
my_char: 0&lt;br /&gt;
&lt;br /&gt;
my_short: 0&lt;br /&gt;
&lt;br /&gt;
my_int: 0&lt;br /&gt;
&lt;br /&gt;
my_long: 0&lt;br /&gt;
&lt;br /&gt;
my_float: 0&lt;br /&gt;
&lt;br /&gt;
my_double: 0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
9.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main (void)&lt;br /&gt;
{&lt;br /&gt;
    &lt;br /&gt;
    char *sp1, *sp2, *sp3;&lt;br /&gt;
    sp1 = malloc( 10 );&lt;br /&gt;
    sp2 = malloc( 10 );&lt;br /&gt;
    printf(&amp;quot;Address of sp1 = %p.  Address of sp2 - %p.\n&amp;quot;, sp1, sp2);&lt;br /&gt;
    printf(&amp;quot;sp1 = %s\n&amp;quot;, sp1);&lt;br /&gt;
    free( sp1 );&lt;br /&gt;
    sp1[6] = &amp;#039;d&amp;#039;;&lt;br /&gt;
    printf(&amp;quot;sp1 = %s\n&amp;quot;, sp1);&lt;br /&gt;
    sp3 = malloc( 10 );&lt;br /&gt;
    printf(&amp;quot;Address of sp1 = %p.  Address of sp2 - %p. Address of sp3 - %p\n&amp;quot;, sp1, sp2, sp3);&lt;br /&gt;
&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Results:&lt;br /&gt;
&lt;br /&gt;
Windows:&lt;br /&gt;
&lt;br /&gt;
Address of sp1 = 0xfa0198.  Address of sp2 - 0xfa01a8.&lt;br /&gt;
&lt;br /&gt;
sp1 = &lt;br /&gt;
&lt;br /&gt;
sp1 = ԝ aԝda &lt;br /&gt;
&lt;br /&gt;
Address of sp1 = 0xfa0198.&lt;br /&gt;
&lt;br /&gt;
Address of sp2 - 0xfa01a8. &lt;br /&gt;
&lt;br /&gt;
Address of sp3 - 0xfa0198&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Linux:&lt;br /&gt;
&lt;br /&gt;
Address of sp1 = 0x10011008.  &lt;br /&gt;
&lt;br /&gt;
Address of sp2 - 0x10011018.&lt;br /&gt;
&lt;br /&gt;
sp1 =&lt;br /&gt;
&lt;br /&gt;
sp1 =&lt;br /&gt;
&lt;br /&gt;
Address of sp1 = 0x10011008.  &lt;br /&gt;
&lt;br /&gt;
Address of sp2 - 0x10011018. &lt;br /&gt;
&lt;br /&gt;
Address of sp3 - 0x10&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
10.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
char *local_str() {&lt;br /&gt;
    char s[8] = &amp;quot;0123456&amp;quot;;&lt;br /&gt;
    return s;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
char *local_str2() {&lt;br /&gt;
    char s[8] = &amp;quot;abcdefg&amp;quot;;&lt;br /&gt;
    return s;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
char *local_str3() {&lt;br /&gt;
    char s[8] = &amp;quot;abcdefg&amp;quot;;&lt;br /&gt;
    return s;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
char *local_str4() {&lt;br /&gt;
    char s[8] = &amp;quot;abcdefg&amp;quot;;&lt;br /&gt;
    return s;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main (void)&lt;br /&gt;
    &lt;br /&gt;
{&lt;br /&gt;
    printf( &amp;quot;local_str = %p\n&amp;quot;, local_str );&lt;br /&gt;
    printf( &amp;quot;local_str2 = %p\n&amp;quot;, local_str2 );&lt;br /&gt;
    printf( &amp;quot;local_str3 = %p\n&amp;quot;, local_str3 );&lt;br /&gt;
    printf( &amp;quot;local_str4 = %p\n&amp;quot;, local_str4 );&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Results:&lt;br /&gt;
&lt;br /&gt;
Windows:&lt;br /&gt;
&lt;br /&gt;
local_str = 0x401050&lt;br /&gt;
&lt;br /&gt;
local_str2 = 0x40106c&lt;br /&gt;
&lt;br /&gt;
local_str3 = 0x401088&lt;br /&gt;
&lt;br /&gt;
local_str4 = 0x4010a4&lt;br /&gt;
&lt;br /&gt;
last 2 hexadecimal places in decimal:&lt;br /&gt;
&lt;br /&gt;
local str = 5*16^1 = 80&lt;br /&gt;
&lt;br /&gt;
local str2 = 6*16^1 + 12*16^0 = 108&lt;br /&gt;
&lt;br /&gt;
local str3 = 8*16^1 + 8*16^0 = 136&lt;br /&gt;
&lt;br /&gt;
local str4 = 10*16 + 4*1 = 164&lt;br /&gt;
&lt;br /&gt;
All differences in string sizes in Windows are 28 which indicates that each memory allocation is 28 in size.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Linux:&lt;br /&gt;
&lt;br /&gt;
local_str = 0x100004ac&lt;br /&gt;
&lt;br /&gt;
local_str2 = 0x1000051c&lt;br /&gt;
&lt;br /&gt;
local_str3 = 0x1000058c&lt;br /&gt;
&lt;br /&gt;
local_str4 = 0x100005fc&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
last 3 hexadecimal places in decimal:&lt;br /&gt;
&lt;br /&gt;
local str = 1196&lt;br /&gt;
&lt;br /&gt;
local str2 = 1308&lt;br /&gt;
&lt;br /&gt;
local str3 = 1372&lt;br /&gt;
&lt;br /&gt;
local str4 = 1532&lt;br /&gt;
&lt;br /&gt;
Difference str2 and str = 112&lt;br /&gt;
&lt;br /&gt;
Difference str3 and str2 = 64&lt;br /&gt;
&lt;br /&gt;
Difference str4 and str3 = 160&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Which are all multiples of 16.  In Linux, as opposed to Window&amp;#039;s constant memory allocation of 28, Linux&amp;#039;s memory allocations appear random.  However, all of the sizes of allocations are multiples of 16 which could be significant.&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>