SE250:lab-2:aomr001
The lab task for todays lab was to find more and explore pointers and different data structures. I have done a number of different tasks and compiled and ran these on 2 different machines, on a windows operating system (x32) and on a LINUX machine (x64) to see what effect that would have on my results.
task1
for task 1 .. my code was :
char *ip; double *ip1; short *ip2; float *ip3; long *ip4; printf("ip = %d\nip1 = %d\nip2 = %d\nip3 = %d\nip4 = %d\n", sizeof(ip),sizeof(ip1),sizeof(ip2),sizeof(ip3),sizeof(ip4));
and the output on the vista os was:
ip = 4 ip1 = 4 ip2 = 4 ip3 = 4 ip4 = 4
while the output on the linux machine was:
ip = 4 ip1 = 4 ip2 = 4 ip3 = 4 ip4 = 4
task2
a)
printf("address of x= %p, address of y= %p, difference= %ld\n",&x, &y ,(long)(&x - &y));
output on windows:
address of x= 0x22ccc4, address of y= 0x22ccc0, difference= 1
ouput on linux:
&x = 0xfff0b9dc, &y = 0xfff0b9d8, diff = 1
i was asked to do a little editing to the code:
printf("address of x= %p, address of y= %p, difference= %ld\n",&x, &y ,((long)&x -(long)&y));
output on windows:
address of x= 0x22ccc4, address of y= 0x22ccc0, difference= 4
output on LINUX:
&x = 0xfff0b9dc, &y = 0xfff0b9d8, diff = 4
task3
printf("sizeof arr = %d\n", sizeof(arr));
output on windows:
sizeof arr = 4
output on LINUX:
size of arr = 4
c)
printf("address of arr = %p",&arr);
output on WINDOWS:
address of arr = 2280640
output on LINUX:
address of arr = 0xffc1d9d4
d)
printf("arr+4 = %d, &arr[4]= %d", arr+4,&arr[4]);
output on LINUX:
arr+4 = -2225704, &arr[4]= -2225704
e)
for (i =0; i < 10; i++){ arr[i]; printf("diff &x - &y = %d\n",(long)(&x - &y));
output on WINDOWS:
diff btwn &x and &y whn arr[0] = 8 diff btwn &x and &y whn arr[1] = 2 diff btwn &x and &y whn arr[2] = 2 diff btwn &x and &y whn arr[3] = 8 diff btwn &x and &y whn arr[4] = 2 diff btwn &x and &y whn arr[5] = 8 diff btwn &x and &y whn arr[6] = 8 diff btwn &x and &y whn arr[7] = 8 diff btwn &x and &y whn arr[8] = 4 diff btwn &x and &y whn arr[9] = 8 diff btwn &x and &y whn arr[10] = 8
output on LINUX:
diff &x - &y = 1 diff &x - &y = 1 diff &x - &y = 1 diff &x - &y = 1 diff &x - &y = 1 diff &x - &y = 1 diff &x - &y = 1 diff &x - &y = 1 diff &x - &y = 1 diff &x - &y = 1
f)
printf("x = %d, y = %d",x,y);
output on WINDOWS:
x = 10, y = 0
output on LINUX:
x = 167772160, y = 0
task4
X and y as global variables printf("&x = %p, &y = %p, diff = %ld\n",&x,&y, (long)(&x - &y)); printf("&x = %p, &y = %p, diff = %ld\n",&x,&y, (long)&x - (long)&y); printf(“sizeof(arr) = &d”, sizeof(arr)); printf("address of arr = %d",&arr); printf("address of arr+4 = %d",&arr+4); printf("address of arr [4]= %d",&arr[4]);
output on WINDOWS:
&x = 0x403030, &y = 0x403020, diff = 4 &x = 0x403030, &y = 0x403020, diff = 16 sizeof(arr) = 4 address of arr = 4206640 address of arr+4 = 4206656 address of arr[4] = 4206644
diff btwn &x and &y whn arr[0] = 8 btwn &x and &y whn arr[1] = 8 diff btwn &x and &y whn arr[2] = 8 diff btwn &x and &y whn arr[3] = 8 diff btwn &x and &y whn arr[4] = 8 diff btwn &x and &y whn arr[5] = 8 diff btwn &x and &y whn arr[6] = 8 diff btwn &x and &y whn arr[7] = 8 diff btwn &x and &y whn arr[8] = 8 diff btwn &x and &y whn arr[9] = 8 diff btwn &x and &y whn arr[10] = 8
task5
int *p1, *p2; { int q; p1 = &q; } { int r; p2 = &r; }
output on WINDOWS:
p1 = 2280636 , p2 = 2280632
output on LINUX:
p1 = -7644716, p2 = -7644716
task6
sp = local str( ); printf( ”sp = %p(%s)\n”, sp, sp ); sp = local str( ); local str2( ); printf( ”sp = %p(%s)\n”, sp, sp ); sp = static str( ); local str2( ); printf( ”sp = %p(%s)\n”, sp, sp ); sp = malloc str( ); local str2( ); printf( ”sp = %p(%s)\n”, sp, sp );
output on WINDOWS:
sp = 0x22cc90(456) sp = 0x22cc90(efg) sp = 0x402000(tuvwxyz) sp = 0x10401a0(hijklmn)
output on LINUX:
sp = 0xffbc29a4(þîÐ) sp = 0xffbc29a4(abcdefg) sp = 0x10010cd4(tuvwxyz) sp = 0x10011008(hijklmn)
strcpy( sp, ”XXXXXXX” ); printf( ”sp X’d = %p(%s)\n”, sp, sp );
output on WINDOWS:
sp = 0x22cc90(456) sp X'd = 0x22cc90(-0@) sp = 0x22cc90(efg) sp X'd = 0x22cc90(-0@) sp = 0x402000(tuvwxyz) sp X'd = 0x402000(XXXXXXX) sp = 0xda01a0(hijklmn) sp X'd = 0xda01a0(XXXXXXX)
output on LINUX:
sp = 0xffb0f9a4(þîÐ) sp X'd = 0xffb0f9a4(XXXXXXX) sp = 0xffb0f9a4(abcdefg) sp X'd = 0xffb0f9a4(XXXXXXX) sp = 0x10010dc0(tuvwxyz) sp X'd = 0x10010dc0(XXXXXXX) sp = 0x10011008(hijklmn) sp X'd = 0x10011008(XXXXXXX)
task7
output on WINDOWS:
&my_struct = 0x0 offsets: my_char: 0 my_short: -2 my_int: -4 my_long: -8 my_float: -12 my_double: -16
output on LINUX:
&my_struct = 0xffe879c0 offsets: my_char: 0 my_short: -2 my_int: -4 my_long: -8 my_float: -12 my_double: -16
task8
output on WINDOWS:
&my_struct = 0x0 offsets: my_char: 0 my_short: 0 my_int: 0 my_long: 0 my_float: 0 my_double: 0
ouput on LINUX:
&my_struct = 0xffafe9d8 offsets: my_char: 0 my_short: 0 my_int: 0 my_long: 0 my_float: 0 my_double: 0
task9
output on WINDOWS:
sp1 address: 0x22ccc4 sp2 address: 0x22ccc0 sp3 address: 0x22ccbc
output on LINUX:
sp1 address: 0xffb5b9dc sp2 address: 0xffb5b9d8 sp3 address: 0xffb5b9d4
task10
output on windows:
local_str = 0x401050
ouput on LINUX:
local_str = 0x100004dc