交换结构体内部的两组数据
程序员文章站
2022-06-03 17:49:56
...
#include<stdio.h>
#define N 30
typedef struct Mystruct
{
int a;
int b;
}MYSTRUCT;
void Swap(struct Mystruct *p,struct Mystruct *p1)
{
// struct Mystruct *pstr=p1;
struct Mystruct a;
a=*p1;
*p1=*p;
*p=a;
printf("%d\n",*p);
printf("%d\n",*p1);
}
int main()
{
struct Mystruct *pstr;
struct Mystruct *pstr1;
MYSTRUCT str[N];
str[0].a=1;
str[0].b=3;
str[1].a=2;
str[1].b=4;
pstr=&str[0];
pstr1=&str[1];
printf("%d\n",*pstr);
printf("%d\n",*pstr1);
Swap(pstr,pstr1);
printf("%d\n",str[0]);
printf("%d\n",str[1]);
printf("%d\n",str[0].b);
printf("%d\n",str[1].b);
}
上一篇: 设置地址栏前的图标
下一篇: js验证ip地址和子网掩码等