0
点赞
收藏
分享

微信扫一扫

20241010_063117 c语言 使用无类型指针定义交换数值的函数

狐沐说 2024-10-10 阅读 15
#include <stdio.h>  
#include <stdlib.h>
#include <time.h>

void fn(void* p1, void* p2,int len){
	char* pc1 = (char*)p1;
	char* pc2 = (char*)p2;
	char temp;
	int i;
	for(i=0;i<len;i++){
		temp = *pc1;
		*pc1 = *pc2;
		*pc2 = temp;
		pc1++;
		pc2++;
	}
}
 
 
int main() {
	int a = 100;
	int b = 200;
	fn(&a,&b,sizeof(int));
	printf("%d,%d",a,b);

    return 0;  
}



举报

相关推荐

0 条评论