SULIT
(EKT 150
Question 3 C3, CO1, PO1
a) Trace the output of the following program segment:
int *ptr, q;
q = 50;
ptr = &q;
printf("sd", *ptr);
2 Marks)
b) Write the function definition for function swap, to swap two numbers
#include <stdio.h>
void swap(int *nl, int *n2);
//function prototype
int main() {
int num1 = 5, num2 = 10;
swap(&num1, &num2);
//function call
printf("num1 = %d\n", num1);
printf("num2 = %d\n", num2);
return 0;
}
//function definition for function "swap"
4 Marks)
c) Write a function definition that accepts a string as an input and then prints the characters in the string in reverse order. Example, the input string "UniMAP" will be displayed as "PAMinU" (Hint: You could use the strlen() function to find the string length.)
6 Marks)