문자열 상수 포인터
C :
2007. 11. 3. 11:48
C에서 문자열 상수는 큰 따옴표로 나타낸다.
컴파일러가 이런 문자열을 만나면, 프로그램의 문자열 테이블에 저장하고
그 문자열에 대한 포인터를 생성한다.
p.213
#include <stdio.h>
int main()
{
char *p;
p="One two three";
printf(p);
return 0;
}
p.214_1
#include <stdio.h>
#include <string.h>
int main()
{
char *p="stop";
char str[80];
do {
printf("Enter a string: ");
gets(str);
} while(strcmp(p, str));
return 0;
}
p.215_1
#include <stdio.h>
int main()
{
char *p1 = "One";
char *p2 = "two";
char *p3 = "three";
printf("%s %s %s\n", p1, p2, p3);
printf("%s %s %s\n", p1, p3, p2);
printf("%s %s %s\n", p2, p1, p3);
printf("%s %s %s\n", p2, p3, p1);
printf("%s %s %s\n", p3, p1, p2);
printf("%s %s %s\n", p3, p2, p1);
return 0;
}