코드 영역에 저장되는건지 데이터 영역에 저장되는건지 말들이 다 다르다.

찾아봅시다..

 

 

VS 2017 이상에서는 리터럴을 char* 가 가리킬 수 없습니다. 반드시 const char* 가 가리켜야 하며, 덕분에 리터럴을 수정하는 괴랄한 짓을 컴파일 단에서 막을 수 있습니다.

 

아래  소스 코드는 VS2015로 한거다.

 

코드 영역인지 확인해보자

마우스를 가져다 대보면 const char[7]로 되어있다.  문자열 상수라고 볼 수 있다.

 

어셈블리어를 한번 살펴보자 

"abcdef"의 주소가 0468BDCh인가 봅니다. 한번 찾아가봅시다.

어디 영역인거지..??

 

 

여러 글들이나 문서들을 거르고 걸러서 분석하고 연구해본 결과

 

 

read only part of data segment 즉 rodata에 저장된다는 말이다.

 

 

 

 

 

 

----------------------------- 찾아본 곳들 -------------------------------

 

en.wikipedia.org/wiki/Data_segment

 

Data segment - Wikipedia

In computing, a data segment (often denoted .data) is a portion of an object file or the corresponding address space of a program that contains initialized static variables, that is, global variables and static local variables. The size of this segment is

en.wikipedia.org

myfreechild.tistory.com/entry/%EB%A9%94%EB%AA%A8%EB%A6%AC%EC%97%90-%ED%95%A0%EB%8B%B9%EC%9D%B4-%EB%90%98%EC%A7%80%EB%A7%8C-%EA%B0%92%EC%9D%84-%EB%B3%80%EA%B2%BD%ED%95%A0-%EC%88%98-%EC%97%86%EB%8A%94-%EB%A9%94%EB%AA%A8%EB%A6%AC-%EC%98%81%EC%97%AD

 

 

메모리에 할당이 되지만 값을 변경할 수 없는 메모리 영역?

다음은 어떤 데브피아 유저가 질문한 내용에 제가 답변한 글입니다. ------------------------------------------------------------------------------------- 제가 보고 있는 c 언어 책의 포인터와 문자열 부분..

myfreechild.tistory.com

 

 

------------------------- 

 

www.geeksforgeeks.org/storage-for-strings-in-c/

 

Storage for Strings in C - GeeksforGeeks

A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.

www.geeksforgeeks.org

 

-------------------------

 

codingdog.tistory.com/entry/c%EC%96%B8%EC%96%B4-%EB%AC%B8%EC%9E%90%EC%97%B4-%EB%A6%AC%ED%84%B0%EB%9F%B4-%EA%B0%92%EC%9D%B4-%EB%B3%80%EA%B2%BD%EB%90%98%EB%A9%B4-%EC%95%88-%EB%90%9C%EB%8B%A4

 

c언어 문자열 리터럴 : 값이 변경되면 안 된다.

 오늘은 간단하게 문자열 리터럴만 올리도록 하겠습니다. "chogahui", "xi" 이런 것들을 우리는 리터럴이라고 합니다. 그러면, 이것들은 어디에 어떻게 저장이 되길래, 이들을 바꾸려고 하면 RTE가

codingdog.tistory.com

 

 

jayy-h.tistory.com/6

 

문자열 리터럴: char* vs char []

문자열 리터럴이란 무엇일까? 다음은 문자열 리터럴을 설명해주는 좋은 예시이다. std::cout << "Hello World" << std::endl; 위 문장에서 "Hello World" 가 문자열 리터럴에 해당한다. 본 질문에 앞서 다음의

jayy-h.tistory.com

 

softwareengineering.stackexchange.com/questions/294748/why-are-c-string-literals-read-only/294750

 

Why are C string literals read-only?

What advantage(s) of string literals being read-only justify(-ies/-ied) the: Yet another way to shoot yourself in the foot char *foo = "bar"; foo[0] = 'd'; /* SEGFAULT */ Inability to elegantly

softwareengineering.stackexchange.com

 

ssinyoung.tistory.com/m/15?category=810263

 

11. [C / C++] 문자열 상수와 포인터

1. 문자열 상수(리터럴) 문자열 상수는 "HelloWorld"와 같이 프로그램 소스 안에 포함된 문자열을 의미합니다. (리터럴 : 소스코드의 고정된 값을 대표하는 용어 정수, 부동 소수점 숫자, 문자열 등등

ssinyoung.tistory.com

 

 

 

 

메모리에 할당이 되지만 값을 변경할 수 없는 메모리 영역?

다음은 어떤 데브피아 유저가 질문한 내용에 제가 답변한 글입니다. ------------------------------------------------------------------------------------- 제가 보고 있는 c 언어 책의 포인터와 문자열 부분..

myfreechild.tistory.com

 

 

메모리에 할당이 되지만 값을 변경할 수 없는 메모리 영역?

다음은 어떤 데브피아 유저가 질문한 내용에 제가 답변한 글입니다. ------------------------------------------------------------------------------------- 제가 보고 있는 c 언어 책의 포인터와 문자열 부분..

myfreechild.tistory.com

kldp.org/node/155779

 

C언어 주로 constant와 관련된 질문입니다. | KLDP

1) constant와 literal의 관계는? 상수가 리터럴을 포함하는 개념으로 이해하고 있습니다. 따라서 상수는 항상 리터럴이 될 수 있지만, 리터럴은 상수가 될 수 없는게 맞는건가요? 참고로 프로그램 소

kldp.org

 

 

melkia.dev/ko/questions/164194?page=3

 

segmentation-fault - 문자열 리터럴로 초기화 된 "char * s"에 쓸 때 분할 오류가 발생하지만 "char s []"가

...

melkia.dev

 

stackoverrun.com/ko/q/1201298

 

c - 메모리에서 문자열 리터럴은 어디에 있습니까? 스택/힙?

가능한 중복 : C String literals: Where do they go? 내가 아는 한 , 일반적으로 , 포인터의 malloc()에 의해 할당 에 있고, 힙 을 할당합니다 , free()에 의해 할당되지 않는다. 및 비 포인터 (INT, CHAR, 플로트, 등

stackoverrun.com

 

stackoverflow.com/questions/2245664/what-is-the-type-of-string-literals-in-c-and-c

 

What is the type of string literals in C and C++?

What is the type of string literal in C? Is it char * or const char * or const char * const? What about C++?

stackoverflow.com

 

 

 

modoocode.com/33

 

씹어먹는 C 언어 - <15 - 3. 일로와봐, 문자열(string) - 문자열 지지고 볶기 & 리터럴>

 

modoocode.com

 

perfectacle.github.io/2017/02/09/C-ref-004/

 

(C/C++) 참고용 정리 - 메모리 영역(Code, Data, Stack, Heap)

프로그램을 실행하게 되면 OS는 메모리(RAM)에 공간을 할당해준다.할당해주는 메모리 공간은 4가지(Code, Data, Stack, Heap)으로 나눌 수 있다. 이미지 출처: C언어의 메모리 구조 Code우리가 작성한 소스

perfectacle.github.io

 

 

ko.wikipedia.org/wiki/%EB%8F%99%EC%A0%81_%EB%A9%94%EB%AA%A8%EB%A6%AC_%ED%95%A0%EB%8B%B9

 

동적 메모리 할당 - 위키백과, 우리 모두의 백과사전

위키백과, 우리 모두의 백과사전. 동적 메모리 할당 또는 메모리 동적 할당은 컴퓨터 프로그래밍에서 실행 시간 동안 사용할 메모리 공간을 할당하는 것을 말한다. 사용이 끝나면 운영체제가 쓸

ko.wikipedia.org

 

 

 

 

+ Recent posts