Assume a main function contains declarations for three type double arrays- c, d,
ID: 3549570 • Letter: A
Question
Assume a main function contains declarations for three type double arrays- c, d, and e, each with six elements. Explain the effect of each valid call to add_arrays (see Fig. 7.8). Explain why each invalid call is invalid.
a. Add_arrays (ar1, ar2, c, 6);
b. Add_arrays (c[6], d[6], e[6], 6);
c. Add_arrays(c, d, e, 6);
d. Add_arrays(c, d, e, 7);
e. Add_arrays(c, d, e, 5);
f. Add_arrays(c, d, 6, 3);
g. Add_arrays(e, d, c, 6);
h. Add_arrays(c, c, c, 6);
i. Add_arrays(c, d, e, c[1]); (if c[1] is 4.3?
j. Add_arrays( &c[2], &d[2], &e[2], 4);
Explanation / Answer
a. INVALID call because ar1, ar2 are not defined in main function. they are just shown as function parameters (not defined)
b. INVALID : c[6], d[6] and e[6] are not arrays, these are double values so the function cant take double as its input.
c.VALID because c,d,e all are defined in the main and the function parameters are also satisfied because allt the are double arrays. function picks up each value from c and d and adds them correspondingly and places them in e.
d. VALID call but in this case as n = 7, the function also does this:
e[6] = c[6] + d[6];
but c,d and e hav only 6 elements.
but still this is not a problem, the programme does not crash and it stores junk values in e[6] which we dont need anyway and we only concern with first 6 elements which are added correspondingly and stored in e.
e. VALID call but in this case the 6th element of both the arrays is not added and fucntion stops after adding first 5 elements only and then returns to main. thus 6th element of e is not the added value of 6th elements of c and d but some junk value. that is to be keep in mind.
f. INVALID because third input to the function is integer and it should be an double array instead.
g. VALID: only difference is that now it adds e and d and stores the result in c.
h. VALID: in this case all the element of the array c get doubled since each element is added to itself.
i. INVALID : because the last(4th) input to the function must be int but here its double(4.3)
j. INVALID : &c[2] is the memory address of the 3rd element of the array c which is not obviously an array so the function does not accept this input. memeory address looks like 0x2fed8 and these are hexadecimal numbers. you can google it if you are more curious about memory address
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.