Working with Pointers

In your class directory, create a new directory called Pointers. In the Pointers directory, write a program for each of the exercises below.
  1. The goal of this exercise is to write a function swap that swaps two integer values. Our first attempt, outlined below, did not work.
        void swap(int x, int y)
        {
            int tmp = x; 
            x = y; 
            y = t;
        }
    
        int main()
        {
            int num1 = 111, num2 = 222;
    
            swap(num1, num2);
            printf("\n num1=[%d], num2=[%d]\n", num1, num2);
        }
    
    Use pointers to fix the code (try for a minimal number of changes).

  2. Assume now that the two integer values are stored into an array. Fill in the missing code below to swap the two array elements.
     
        void swap2(____________)
        {
            int tmp    = _________; 
            __________ = _________; 
            __________ = _________; 
        }
    
        int main()
        {
            int num[2] = {111, 222};
    
            swap2(___________);
            printf("num[0]=[%d], num[1]=[%d]\n", num[0], num[1]);
        }
    
    The output should be
        num[0] = 222, num[1] = 111