SE250:lab-2:tsen009

From Marks Wiki
Jump to navigation Jump to search

Web page currently unavailable and under construction...

please try again later...

KTHXBI

Task

the point of the lab was to follow through the tasks given in the lab sheet and record the details and results that we aquired from it.

Results

Task #1

int *ip;
printf("%d \n", sizeof(ip));

Task #2

    int x;
    int y;
    printf("&x = %p, &y = %p, diff = %ld \n", &x, &y, (long)(&x - &y));
&x = 0x22ccc4, &y = 0x22ccc0, diff = 1

Task #3

    int x;
    char arr [4];
    int y;
    printf("sizeof arr = %d, &arr = %p, &arr[4] = %p \n", sizeof(arr), &arr, &arr[4]);

    printf("&x = %p, &y = %p, diff = %ld \n", &x, &y, (long)(&x - &y));


sizeof arr = 4, &arr = 0x22cca0, &arr[4] = 0x22cca4 
&x = 0x22cca4, &y = 0x22cc9c, diff = 2

To make my life easier, i decided to do an automated loop to make arrays of different sizes, and ended up with the following code/results.

    int counter = 0;

    for (counter = 0; counter < 11; counter++){

	int x;
	char arr [counter];
	int y;

	printf("Char Arr size = %d\n", counter);
	printf("sizeof arr = %d, &arr = %p, &arr[4] = %p \n", sizeof(arr), &arr, &arr[4]); 

	printf("&x = %p, &y = %p, diff = %ld \n", &x, &y, (long)(&x - &y)); 
     }


Char Arr size = 0
sizeof arr = 0, &arr = 0x22cc60, &arr[4] = 0x22cc64 
&x = 0x22cc94, &y = 0x22cc90, diff = 1 
Char Arr size = 1
sizeof arr = 1, &arr = 0x22cc60, &arr[4] = 0x22cc64 
&x = 0x22cc94, &y = 0x22cc90, diff = 1 
Char Arr size = 2
sizeof arr = 2, &arr = 0x22cc50, &arr[4] = 0x22cc54 
&x = 0x22cc94, &y = 0x22cc90, diff = 1 
Char Arr size = 3
sizeof arr = 3, &arr = 0x22cc50, &arr[4] = 0x22cc54 
&x = 0x22cc94, &y = 0x22cc90, diff = 1 
Char Arr size = 4
sizeof arr = 4, &arr = 0x22cc50, &arr[4] = 0x22cc54 
&x = 0x22cc94, &y = 0x22cc90, diff = 1 
Char Arr size = 5
sizeof arr = 5, &arr = 0x22cc50, &arr[4] = 0x22cc54 
&x = 0x22cc94, &y = 0x22cc90, diff = 1 
Char Arr size = 6
sizeof arr = 6, &arr = 0x22cc50, &arr[4] = 0x22cc54 
&x = 0x22cc94, &y = 0x22cc90, diff = 1 
Char Arr size = 7
sizeof arr = 7, &arr = 0x22cc50, &arr[4] = 0x22cc54 
&x = 0x22cc94, &y = 0x22cc90, diff = 1 
Char Arr size = 8
sizeof arr = 8, &arr = 0x22cc50, &arr[4] = 0x22cc54 
&x = 0x22cc94, &y = 0x22cc90, diff = 1 
Char Arr size = 9
sizeof arr = 9, &arr = 0x22cc50, &arr[4] = 0x22cc54 
&x = 0x22cc94, &y = 0x22cc90, diff = 1 
Char Arr size = 10
sizeof arr = 10, &arr = 0x22cc50, &arr[4] = 0x22cc54 
&x = 0x22cc94, &y = 0x22cc90, diff = 1

but surprisingly the result was unexpected. may be there was a glitch/error or it was something completely wrong. but as the size of the array increases, it seems that the memory dont seem to increase. it may be due to this being done by a loop. the values of the x/y memory addresses seem to stay the same the whole way through although the array size keep changing.