#include <stdio.h>
void swap(int *i, int *j)
{
int t;
t = *i;
*i = *j;
*j = t;
}
void main()
{
int i,j;
i=5;
j=10;
printf("%d %d\n",i,j);
swap(&i,&j);
printf("%d %d\n",i,j);
}
Will there be any problem with this small programme which swaps two variables because i,j inside the function work as pointers and inside main contain numbers? should i have used another letters, e.g. a,b instead of i,j inside main?
Variables are local to the scope they are defined, so no this should not be a problem at all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With