I have a homework assignment in my C programming class that I do not understand.
We had to take a previous program that swapped the contents of two memory locations using a function. However, the professor has asked us now to modify our program so that the swapping performed by the function will appear in the main program after calling the function.
These were his exact words, and I have no idea what he is trying to get at.
The professor as usual answers NO questions, and I think I am just as confused as the rest of my classmates.
We are currently covering pointers if that helps any.
Here is my original program.
#include <stdio.h>
void main()
{
void swap(int x, int y);
int first_num = 10;
int second_num = 50;
printf("\nThe value of first_num is %d \n The value of second num is %d \n",
first_num, second_num );
swap(first_num, second_num);
printf("\nThe value of first_num is %d \n The value of second num is %d \n",
first_num, second_num );
system("pause");
}
void swap(int x, int y)
{
int local_int;
local_int = x;
x = y;
y = local_int;
printf("\nIn the function first_num is %d\nIn the function second_num is ", x,
y );
}
Thanks in advance for all of your help!
Cheers
~AB


Sign In
Create Account

Back to top









