나의 작은 valley
[C언어] 문자열의 배열 본문
728x90
포인터의 배열로 받기 vs 다차원 배열로 받기)
#include <stdio.h>
int main()
{
const char* recommend[5] = {
"playing the orchestra",
"No vaseline",
"Giant steps",
"The Freewheelin' Bob Dylan",
"Round About Midnight",
};
char myhobbies[4][40] = {
"Bleach",
"upload blog",
"Game",
"Walking around till dark",
};
const char* temp1 = "playing the orchestra";
const char* temp2 = "Bleach";
printf("%s %u %u\n", recommend[0], (unsigned)recommend[0], (unsigned)temp1);
printf("%s %u %u\n", myhobbies[0], (unsigned)myhobbies[0], (unsigned)temp2);
printf("\n");
return 0;
}
출력)
playing the orchestra 2066456512 2066456512
Bleach 1401943328 2066455652
>> ptr의 경우에는 주소가 같은 반면에 배열의 경우는 주소가 다르다. !!
>> ptr이 가르키는 값은 사용자가 건들 수 없다.
728x90
'Computer Science > [C언어] 문법 정리' 카테고리의 다른 글
[C언어] 문자열을 출력하는 다양한 방법 (2) | 2022.11.21 |
---|---|
[C언어] 문자열을 입력받는 다양한 방법 (0) | 2022.11.19 |
[C언어] 메모리 레이아웃 (0) | 2022.11.18 |
[C언어] put()함수 소개 (0) | 2022.11.18 |
[C언어] 입력 스트림 (0) | 2022.11.18 |
Comments