1. 10 points) Assume you are given 3 arrays: An aray of integers intarr beginnin
ID: 3700203 • Letter: 1
Question
1. 10 points) Assume you are given 3 arrays: An aray of integers intarr beginning at memory location 0x7B, an array of characters str at 0x5F, and an array of strings strarr at 0xB3. Calculate the memory locations of the following (a) The 93rd element of intarr Hint: The type of a string is char* (b) The 22nd element of str (c) The 44th element of etrarr 2. (10 points) Explain what it means to be pass by value, and how this differs fron languages like Java or python which are pass by reference. 3. (20 points) Consider the following snippets of code: void cet next (1liat node) ( nain) 1list head; set val(head, 5) set next (head) typedef struct 1list int val; llist next; 1list; node neunode; nemode.al 10; node.next newnode; 5printt ldin*, hoad.nun) void set val (llist *node, intu6printf dn, head. next->nam) (a) (5 points) The definition of the struct has an error. Explain what is wrong, and write out code with the same intent that will compile. (b) (8 points) Assuing that everything is appropriately in scope, what is the output after running main? (c) 7 points) Modify the set next function (and possibly the function call in main) to change the output of line 6 to be 7 4. (20 points) Consider the following snippets of code typodaf struct coord t int index double val; coord ? coord» constructi( int ix, double val) { 8 coord+ construct2(int ix, double ral) coord *ptr (coarda) ptr-index-ix; ptr->val = val ; roturn ptr malloc(Explanation / Answer
1. If it is assumed that an int occupies 4 bytes of memory, then the 93rd element starts at 0x30F . With char as 1 byte memory, 22nd element is at 0x74. The string will depend on the length of each string.
2. Pass by value means that you are only sending the value to the function. If that function changes the value of the variable, the change is temporary. In pass by reference, the change is permanent. This is because, the change is directly made in the memory location itself.
3. a The struct label and variable has the same name.
typedef struct llist {
int val;
llist *next;
} somename;
3b. There is an error as head.num isnt a valid one.
3c. Set newnode.val=7
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.