Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please answer the queston (in terms of C programming) and explain answer Semeste

ID: 3905564 • Letter: P

Question

Please answer the queston (in terms of C programming) and explain answer

Semester 2 & Trimester 3B, 2015 COMP1004 Engineering Programming Question 5 - Functions and File 1/0 (20 marks) Q5(a) What will be printed when the following code is executed? 9 marks) include void functionl (int i, int 3): void function2(int *i, int *j); void funetion3 (int arrayil, int length) a int main(void) int int a#2,b-3; c[31-14,5, 6): functionl (a,b): printf ("%d %d ",a,b) ; function2 (&a;, &b;): printf("d din", a, b) i function3 (c, 3) printf("%d %d %d ". c [0],c[1],c[2]); return 0 void functionl (inti, int 3) int temp: temp ; i-ja j-temp void function2 (int *i, int ) t? int temp: tempe * j-tempi void function3 (int array], int length) int i, temp [3]; for (i-0;i

Explanation / Answer

Output:

for function1(a,b) output is 2 3

here we are passing a and b as variables ad there we are receiving these values in another variables i and j and all the variables a,b,i,j are differenet and we are swaping the values of i and j in function1 so values of a and b will not changes that is the reason why after performing the swappoing on i and j also values of a and b doesnot change. Th is calles pass by value.

for function2(&a,&b) output is 3 2

Here we are passing address of a and b and there in function also we are receiving them in pointer variables. In function2 we are swapping the values based on the memory locations thats why changes made in that function will reflect in that a and b also.

for function2(c,3) will print the 6 5 4.

function3 contains the code which reverses the array. First for loop copies the array we passed in function call in reverse order to temp array and second for loop will copy the contents from temp array to original array.

So for three function calls total output will be: