SE350:lab-2:mgha023

From Marks Wiki
Jump to navigation Jump to search

Part 1

I entered the following code on the Windows machine and Run the program 4 times by changing int to float, char and double. I was not able to log on to the Linux server. I tried what the lecturer had indicated the previous day but i was unsucessful.I took the tutors help and I was eventually able to log on.


	int *ip;
	printf("%d\n", sizeof(ip));
Windows Linux
char=4 char=4
int=4 int=4
float=4 float=4
double=4 double=4


Part 2

  • This was my code to print out the address of x and y:


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


Windows Linux
&x=0029FB48 &x=oxffb8a73c
&y=0029FB3C &y=oxffb8a738
diff=3 diff=1


  • To find the difference between (long)&x and (long)&y:


 	int x, y;

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


Windows Linux
&x=0027FAF0 &x=oxffeba73c
&y=0027FAE4 &y=oxffeba738
diff=12 diff=12


Part 3

  • Code for size of an array:


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

	printf("Size of array=%d\n", sizeof(arr));


Windows Linux
Array size=4 Array size=4


  • To find out the address of the array:
 	int x;
	char arr[4];
	int y;

	printf("&arr=%p\n", &arr);


Windows Linux
&arr = 0023F820 &arr = 0xffb73734


  • For value of &arr[4]:


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

	printf("&arr[4]=%p\n", &(arr[4]));

Windows Linux
&arr[4] = 001DFB4C &arr[4] = 0xffb8d738


  • Difference between &x and &y, value of arr and arr+4 :
       int x;
	char arr[10];
	int y;

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


Windows Linux
diff = 8 diff = 1
arr = 0013F8E0 arr = 0xff82a732
arr+4 = 0013F8E4 arr+4 = 0xff82a736


  • Code for the last part of question three:


 	int x;
	char arr[4];
	int y;
 	 
        x = 0;
        y = 0;
        arr[4] = 10;
 	
       printf("x=%d, y=%d\n", x, y );
Windows Linux
x=0 y=0

This result is surprising as according to the tutors, i was not meant to get 'x=0 and y=0' as my answer as there is an array in between. I tried Debugging and running again but i got (0,0) everytime.


Part 4

  • Repeating above but declaring x and y as global variables:


#include <stdio.h>

int x;
int y;

int main(void)
{

	char arr[4]={10};
	
	printf("x=%d,y=%d\n",&x,&y );
	 
	return 0;
}


Windows Linux
&x = 1536360 &x = 268503616
&y = 1536356 &y = 268503620

Part 5

  • Entered the following code to find values of p1 and p2:


int *p1,*p2;
{int q; p1=&q;}
{int r; p2=&r;}
printf("p1=%d, p2=%d\n", p1, p2);


Windows Linux
p1 = 1703120 p1 = - 6465740
p2 = 1703108 p2 = -6465740


At this point, Microsoft Visual Studio stopped responding. I restarted the application several times but yet it failed to respond. I tried opening TextPad but that failed too. So as of now, although I have a lot of work in front of me, I'm not able to progress as neither of the applications are working...

Right, so I'm still waiting...Neither of them are opening. It's almost 12.00pm...Hope this starts soon. I have 5 more questions to complete.

I called the tutor but he said he could npt diagnose the problem. So I restarted the computer and yet nothign worked. Thus, i was sittign idle for around 20 minutes trying to make things work. Time was up so I decided to abandon it and continue at home.

  • At home now and gettign on with Part 6...

Part 6

These were the errors I got after running the code! I'm yet to get around this:


  • Error 1 error C2143: syntax error : missing ';' before '{'
  • Warning 2 warning C4172: returning address of local variable or temporary
  • Error 3 error C2143: syntax error : missing ';' before 'type'
  • Error 4 error C2065: 's' : undeclared identifier
  • Warning 5 warning C4013: 'malloc' undefined; assuming extern returning int
  • Warning 6 warning C4047: 'initializing' : 'char *' differs in levels of indirection from 'int'
  • Warning 7 warning C4013: 'strcpy' undefined; assuming extern returning int
  • Error 8 error C2099: initializer is not a constant
  • Error 9 error C2143: syntax error : missing ')' before 'string'
  • Error 10 error C2143: syntax error : missing '{' before 'string'
  • Error 11 error C2059: syntax error : '<Unknown>'
  • Error 12 error C2059: syntax error : ')'
  • Error 13 error C2374: 'sp' : redefinition; multiple initialization
  • Error 14 error C2099: initializer is not a constant
  • Error 15 error C2143: syntax error : missing ')' before 'string'
  • Error 16 error C2143: syntax error : missing '{' before 'string'
  • Error 17 error C2059: syntax error : '<Unknown>'
  • Error 18 error C2059: syntax error : ')'
  • Error 19 error C2374: 'sp' : redefinition; multiple initialization
  • Warning 20 warning C4013: 'static_str' undefined; assuming extern returning int
  • Error 21 error C2099: initializer is not a constant
  • Error 22 error C2143: syntax error : missing ')' before 'string'
  • Error 23 error C2143: syntax error : missing '{' before 'string'
  • Error 24 error C2059: syntax error : '<Unknown>'
  • Error 25 error C2059: syntax error : ')'
  • Error 26 error C2374: 'sp' : redefinition; multiple initialization
  • Error 27 error C2099: initializer is not a constant
  • Error 28 error C2143: syntax error : missing ')' before 'string'
  • Error 29 error C2143: syntax error : missing '{' before 'string'
  • Error 30 error C2059: syntax error : '<Unknown>'
  • Error 31 error C2059: syntax error : ')'
  • Error 32 error C2059: syntax error : 'return'
  • Error 33 error C2059: syntax error : '}'