'구조체'에 해당되는 글 1건

  1. 2009.03.25 구조체
C/C++2009. 3. 25. 20:42
구조체란?
◎ 하나 이상의 변수를 그룹 지어서 새로운 자료형을 정의 하는것
◎ 붙어 다니게 되는 데이터들은 하나로 묶어서 관리 하는것이 편리하다


/*
#include <stdio.h>

struct Man {       //구조체
int ID;
float key;
char name[10];
char address[50];
};

Input_Man(struct Man * Lee2){  //함수로 뺏을경우

(*Lee2).ID = 1002;   
//Lee2->ID = 1002;  위와 동일한 기능

(*Lee2).key = 180.2;
strcpy((*Lee2).name,"Gist Lee");
strcpy((*Lee2).address,"Japan");
}

int main(){
int x;
int y;
struct Man Lee = {1001,173.2,"Shakii","서울시 동대문구 신설동"};

struct Man Lee2;

printf("Lee의 정보\n");
printf("Lee구조체의 전체 Byte : %d \n", sizeof(Lee));
printf("ID : %d \n",Lee.ID);
printf("이름 : %s \n",Lee.name);
printf("키 : %.2f \n",Lee.key);
printf("주소 : %s \n",Lee.address);
printf("Lee : %d \n",Lee);  //첫번째 값을 사용
printf("\n\n\n");


//Lee2 = Lee;      //오른쪽것이 왼쪽으로 복사

Input_Man(&Lee2);

printf("Lee2의 정보\n"); 
printf("ID : %d \n",Lee2.ID);
printf("이름 : %s \n",Lee2.name);
printf("키 : %.2f \n",Lee2.key);
printf("주소 : %s \n",Lee2.address);

 

return 0;
}
*/

Posted by 샤키