C언어/구조체와 사용자 정의 자료형 썸네일형 리스트형 // 구조체 멤버의 연산. #include /* struct simple { int data1; int data2; }; swap(struct simple *i,struct simple *j)//구조체 포인터로 받는다. { struct simple temp=*i; // 맴버 값 바꿀시 임시 구조체도 같은구조체롤 선언하여 형 일치 시킴 *i=*j; *j=temp; } int main() { struct simple p1={1,2};// 객체의 선언및 초기화 struct simple p2={3,4}; swap(&p1,&p2); // 객체의 주소값을 인자로 전달하여야 콜바이 레퍼런스 의미!! printf("p1.data1=%d p1.data2=%d\n",p1.data1,p1.data2); // 결과값 출력 printf("p2.data1.. 더보기 // 구조체 call by value & call by reference #include struct library { int a; int b; }; expresion(struct library call_value)// 함수의 인수를 구조체 변수로 전달 :콜바이 밸유 { printf("a=%d b=%d\n",call_value.a,call_value.b); } exchange(struct library *pointer)// 함수의 인수를 구조체 포인터를 전달 : { int temp; temp=pointer->a; pointer->a=pointer->b; pointer->b=temp; } int main() { struct library lib={1,2}; expresion(lib);//구조체 변수(객체) 전달 (값에 의한 복사) exchange(&lib);// 구조체변수의 주.. 더보기 구조체 변수와 주소값의 관계 더보기 구조체 포인터의 활용 더보기 구조체 배열과 포인터의 선언 더보기 구조체의 정의 양식 더보기 이전 1 다음