๊ตฌ์กฐ์ฒด: ์๋ก ๋ค๋ฅธ ํ์ ์ ๋ฐ์ดํฐ๋ฅผ ํ๋์ ๋จ์๋ก ๋ฌถ์ ์ ์๋ ๋๊ตฌ
strcpy ๋ฌธ์์ด ๋ null(= '\0') ๊น์ง ๋ณต์ฌ
#include <stdio.h>
#include <string.h>
#include <stdlib.>
struct strudent{
int 10;
char name[20];
int age;
};
int main() {
struct strict s1;
s1.id = 101;
s1.age = 20;
strcpy = string copy
https://blockdmask.tistory.com/348
// ๊ตฌ์กฐ์ฒด : ์ฌ๋ฌ๊ฐ์ ๋ค๋ฅธ ๋ฐ์ดํฐ๋ฅผ ํ๋๋ก ๋ฌถ์ด์ ๊ด๋ฆฌํ ์ ์๋ ๋ฐ์ดํฐ ๊พธ๋ฌ๋ฏธ
struct People{
char name;
int age;
};
struct Address{
char city; // ๋์
int num; // ์ฐํธ๋ฒํธ
};
struct Student{
char name;
int age;
struct Address addr;
};
int main() {
struct People p1;
// . ์ฐ์ฐ์๋ฅผ ์ด์ฉํด ๋ฉค๋ฒ๋ณ์์ ์ ๊ทผ
char a = 10;
char p = &a;
// ๊ตฌ์กฐ์ฒด + ํฌ์ธํฐ
struct Student s;
s.name = "ํ๊ธธ๋";
s.age = 20;
s.addr.city = "์์ธ";
s.addr.num = 1234;
printf("%s\n",s.addr.city);
struct Student ps = &s;
printf("%d\n", (ps).age);
printf("%d\n", ps->age);
// -> ์ฐ์ฐ์ ์ผ์ชฝ์ ๋ฌด์กฐ๊ฑด ๊ตฌ์กฐ์ฒด ์ฃผ์
int arr[3]= {1,2,3};
arr[0] = 1;
arr[1] = 2;
arr[2] = 3;
printf("%d\n", *p);
return 0;
}