The void is a sub-process, it must be enclosed in braces and must not end in a semicolon.
on the other hand as the community says int * temp = * p1;
is a constaint violation, it must be int temp = * p1;
Nor was exchanging values, it showed only as when they were entered.
Finally, the main returns an int
, you must specify that you return a 0, that is done with return 0;
The whole program would be like that
#include <stdio.h>
void swap (int *p1, int *p2){
int temp = *p1;
*p1 = *p2;
*p2 = temp;
}
int main ()
{
int x = 10;
int y = 20;
swap (p1, p2);
printf ("x: %d, y: %d\n", x, y);
return 0;
}
1
solved Why isn’t this swap program working in C?