[C] About phrash on function

2019-4-29 写技术

#include <stdio.h>
#include <stdlib.h>

typedef struct _ss{
	int a;
	int b;
}ss;

void fun( ss &s){
	s.a = 2;
	s.b = 3;
	printf("fun:%d %d\n", 	 s.a, s.b);
}

void fun2(ss *s){
	s->a=55;
	printf("fun2:%d %d\n", s->a, s->b);
}

void fun3(ss *s){
	fun(*s);
}

void fun4(ss &s){
	fun2(&s);
}

int main(){
	ss s;
	
	printf("test\n");
	s.a=1;
	s.b=1;
	

	printf(" def:%d %d\n", s.a, s.b);
	fun(s);

	printf(" def1:%d %d\n", s.a, s.b);
	
	fun2(&s);
	printf(" def2:%d %d\n", s.a, s.b);

	fun3(&s);

	printf(" def3:%d %d\n", s.a, s.b);


	fun4(s);

	printf(" def4:%d %d\n", s.a, s.b);

	return 0;
}

标签: C

发表评论:

Powered by anycle 湘ICP备15001973号-1