나의 작은 valley

[C언어] 문자열의 배열 본문

Computer Science/[C언어] 문법 정리

[C언어] 문자열의 배열

붕옥 아이젠 2022. 11. 19. 08:35
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
Comments