Question: Question 4 (20 marks) (a) Write C-language statements to declare and initialise the following A variable of type integer with a value of 10 )
Question 4 (20 marks) (a) Write C-language statements to declare and initialise the following A variable of type integer with a value of 10 ) A one dimensional array with the following integer values: 1, 10, 6, 21, 10 (iii)A pointer to the variable defined in (1) (6 marks) (b) Explain, using appropriate examples, what the following operators are used for when using pointers in a C-program: () addressing operator () dereferencing operator (6 marks) (c) Consider the following C-Program function void swap (int , int B) int temp: temp = A; A = B; B = temp; The function is called from main() using the statement swap(x,y) where x and y are integers defined in main(). The intention is that the values of x and y in main() are swapped. () Explain why the function above fails to do what is required. (3 marks) (II) Re-write the function implementation of swap for it to achieve its purpose and show how it is called in main(). (Hint: use pointers)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
