#include <stdio.h>
#include <stdlib.h>
char* ReadUserName(void)
{
char* name
= (char*)malloc(sizeof(char) * 30); //문자형 동적메모리 할당 gets(name
); //포인터가 가리키는 문자형 메모리공간에 문자열 입력받음
return name; //포인터가 가리키는 메모리공간에 담긴 문자열값 반환
}
int main(void)
{
char* name1;
char* name2;
name1 = ReadUserName(); //유저 이름 불러오는 함수를 참조
printf("name1: %s\n", name1
); //포인터 name1이 가리키는 함수의 반환값(문자열) 출력
name2 = ReadUserName(); //유저 이름 불러오는 함수를 참조
printf("name2: %s\n", name2
); //포인터 name2이 가리키는 함수의 반환값(문자열) 출력
printf("Again name1: %p\n", name1
); //다시 name1 출력 printf("Again name2: %p\n", name2
); //다시 name2 출력
printf("Again name1: %p\n", name1
); //다시 name1 출력 printf("Again name2: %p\n", name2
); //다시 name2 출력
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmNoYXIqIFJlYWRVc2VyTmFtZSh2b2lkKQp7CgljaGFyKiBuYW1lID0gKGNoYXIqKW1hbGxvYyhzaXplb2YoY2hhcikgKiAzMCk7IC8v66y47J6Q7ZiVIOuPmeyggeuplOuqqOumrCDtlaDri7kKCWdldHMobmFtZSk7IC8v7Y+s7J247YSw6rCAIOqwgOumrO2CpOuKlCDrrLjsnpDtmJUg66mU66qo66as6rO16rCE7JeQIOusuOyekOyXtCDsnoXroKXrsJvsnYwKCglyZXR1cm4gbmFtZTsgLy/tj6zsnbjthLDqsIAg6rCA66as7YKk64qUIOuplOuqqOumrOqzteqwhOyXkCDri7TquLQg66y47J6Q7Je06rCSIOuwmO2ZmAp9CgppbnQgbWFpbih2b2lkKQp7CgljaGFyKiBuYW1lMTsKCWNoYXIqIG5hbWUyOwoKCW5hbWUxID0gUmVhZFVzZXJOYW1lKCk7IC8v7Jyg7KCAIOydtOumhCDrtojrn6zsmKTripQg7ZWo7IiY66W8IOywuOyhsAoJcHJpbnRmKCJuYW1lMTogJXNcbiIs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