Write a function with a pointer and exchange two numbers

CSDN Q & A 2021-12-30 14:04:17 阅读数:666

write function pointer exchange numbers

#include<stdio.h>

int main()

void swop(int *p1,int *p2)
{ int num;
num=*p1;
*p1=*p2;
*p2=num;
}
{ void swop(int *p1,int *p2);
int a,b;
int *pointer_1,*pointer_2;
pointer_1=&a;pointer_2=&b;
scanf("%d,%d",&a,&b);
swop(pointer_1,pointer_2);
printf("%d,%d\n"a,b);
return 0;
}
Seek correction




Refer to the answer 1:
#include <stdio.h> void swop(int *p1, int *p2){ int num; num = *p1; *p1 = *p2; *p2 = num;}int main(){ int a, b; int *pointer_1, *pointer_2; pointer_1 = &a; pointer_2 = &b; scanf("%d,%d", &a, &b); swop(pointer_1, pointer_2); printf("%d,%d\n", a, b); return 0;}



Refer to the answer 2:
版权声明:本文为[CSDN Q & A]所创,转载请带上原文链接,感谢。 https://primo.wiki/2021/12/202112301404159576.html