SE250:lab-2:gfun006

From Marks Wiki
Jump to navigation Jump to search

Lab 2

Question 1

The size of a int pointer was 4, this was the same for all other data types in C. Originally I was confused at why there was no difference between the data types, but then I realized it's just because the size of the pointer will never change. It was exactly the same on the Linux server.

Question 2

Address of x (&x) = 0012FF50
Address of y (&y) = 0012FF54
Difference of (long)(&x - &y)) = -1
Difference of (long)&x - (long)&y = -4

My results showed that the difference for (long)&x - (long)&y was -1 and the difference for (long)(&x - &y) was -4. These results changed on the Linux server to -2 and -8 respectively. The addresses were also noticeably different on the two servers. For example, the lab machine showed the address of x to be 0012FF50, while the address on Linux was 0x10010d0c.

DIFFICULTIES --> Linux is not my friend. It took me forever until I figured out how to get onto the server and make use of it.

Question 3

The size of the array is 4
Address of pointer of array = 0012FF44
Address of arr+4 = 0012FF48
Address of &arr[4] = 0012FF48
Address of x = 0 is 0012FF50
Address of y = 0 is 0012FF54

My results show that these addresses are similar to the addresses for the above, so they are basically stored at the same place. The weird thing I found on Linux was that the address of y (which was 0x10010d14), and the address of &arr[4] was EXACTLY the same. Which doesn't make a bit of sense...Oh well.

DIFFICULTIES --> I did not realize that when the question asked "What is the value of &arr?", it meant what was the address.

CONFUSIONS --> When the size of the array was varied, there was absolutely no difference between &x and &y. I do not know whether this was suppose to happen or not. Also, I have no idea whether it was correct that when I set x = 0 and y = 0, it still made no difference where the memory was initially stored.

Question 4

Address of x (&x) = 0040DB04, Address of y (&y) = 0040DB00
Difference of (long)(&x - &y)) = 1
Difference of (long)&x - (long)&y = 4

The size of the array is 4
Address of pointer of array = 0040DB08
Address of arr+4 = 0040DB0C
Address of &arr[4] = 0040DB0C

Address of x = 0 is 0040DB04
Address of y = 0 is 0040DB00

By changing everything to global variables, this changed where everything was stored in memory, which makes sense.

CONFUSIONS --> Although the difference between &x and &y are still the same, they are now positive. I don't quite see why...yet.

Question 5

Address of p1 is 0012FF30
Address of p2 is 0012FF2C

Question 6

The results were strange.

sp XÆd = 0012FF40(X ↕)
sp = 0012FF40(X ↕)
sp XÆd = 0012FF40(X ↕)
sp = 0012FF40(X ↕)
sp XÆd = 0040C010(XXXXXXX)
sp = 0040C010(XXXXXXX)
sp XÆd = 009411F0(XXXXXXX)
sp = 009411F0(XXXXXXX)

I do not comprehend.

From this point onwards, I had to switch computers because I ran out of time in the lab. Therefore any addresses from this point onwards will probably not make sense to the addresses above.

Question 7

My results showed the following

&my struct = CFC6FAAE
offsets:
my char: 0
my short: -2
my int: -4
my long: -8
my float: -12
my double: -16

I also noticed that the address of my structure was changing everytime I ran the code.

Question 8

&my_union = 00000000
offsets:
my char: 0
my short: 0
my int: 0
my long: 0
my float: 0
my double: 0

Question 9

These are the results I got:

&sp1 = 0012FF54
sp1= 00921A80
&sp2 = 0012FF50
sp2 = 00921A98

&sp3 = 0012FF4C
sp3 = 00921A80

The fact that sp1 and sp3 have the same address shows that when sp1 was freed, sp3 took up the free space.