For the next program fragment, write in the form of a table the value of the variables after each step of the program (the columns correspond to the variables, the rows to the rows of the program). Type int and pointers occupy 4 bytes each. The compiler arranged the variables at the following addresses: a - 100, p1 - 120, p2 - 124, sx - 128, sy - 132. The number N is the number of the variant.
struct str {int x; int y;}; int a[5] = {1, 2, 3, 4, 5}; int *p1, *p2; str s; p1 = &a[N%5+1]; //первая строка таблицы p2 = a+N/5+1; //2-я строка sx = *p1; //3-я строка sy = *p2++; //4-я строка *(p1-2)=sy; //5-я строка p2=&s; //6-я строка p2->x=p1[1]; //7-я строка p2–>y=sy; //8-я строка a[5]=sx; //9-я строка The table, as I understand it, should be 5 columns and 9 rows with values.
something like this? Only here in the 8th line I did not understand - is the assignment of the value to itself? Because p2 refers to s.
Added! Oh yes, N = 2.
Found and corrected the shortcomings, that’s about everything in the table. Line 7 is not quite clear - is the pointer to the element of the array? or it points to an element with an index of 1 array (as I am in the table and designed). The teacher said that there are errors in the code that need to be fixed, besides the incorrect declaration of the structure s mb here is also a mistake? still not like line 8 - so you can declare? Well, in general, not sure that everything is filled correctly. Interested in line 2.