C언어 문자열 변수, 문자열 상수

John Jeong (토론 | 기여)님의 2017년 4월 3일 (월) 18:05 판

1 개념

문자열 변수와 문자열 상수

2 문자열 변수

#include <stdio.h>

void main()
{
    char str[256] = "my name is John.";

    printf("%s\n", str);

    str[0] = 'M';

    printf("%s\n", str);
}
  • 실행
my name is John.
My name is John.

3 문자열 상수

#include <stdio.h>

void main()
{
    char *str = "my name is John.";

    printf("%s\n", str);

    str[0] = 'M';

    printf("%s\n", str);
}
  • 실행
my name is John.
Segmentation fault (core dumped)
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}