Turbo-C
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
터보-C 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
Lua 게시판
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C/C++ Q/A
[5227] Re:Re:변수에 값을 변수로 사용하여는 방법 좀 알려 주세요
행인 [] 1579 읽음    2005-08-16 11:15
Character array literals

The place where strict constness is not enforced is with character array literals. You can say
char* cp = "howdy";
and the compiler will accept it without complaint. This is technically an error because a character array literal (“howdy” in this case) is created by the compiler as a constant character array, and the result of the quoted character array is its starting address in memory. Modifying any of the characters in the array is a runtime error, although not all compilers enforce this correctly.
So character array literals are actually constant character arrays. Of course, the compiler lets you get away with treating them as non-const because there’s so much existing C code that relies on this. However, if you try to change the values in a character array literal, the behavior is undefined, although it will probably work on many machines.
If you want to be able to modify the string, put it in an array:
char cp[] = "howdy";
Since compilers often don’t enforce the difference you won’t be reminded to use this latter form and so the point becomes rather subtle.

from Thining in cpp

+ -

관련 글 리스트
5203 변수에 값을 변수로 사용하여는 방법 좀 알려 주세요 김선태 1464 2005/08/06
5210     Re:변수에 값을 변수로 사용하여는 방법 좀 알려 주세요 심성현 1764 2005/08/07
5227         Re:Re:변수에 값을 변수로 사용하여는 방법 좀 알려 주세요 행인 1579 2005/08/16
5206     Re:변수에 값을 변수로 사용하여는 방법 좀 알려 주세요 행인 1559 2005/08/07
5208         Re:Re:행인님 도움 부탁합니다. 김선태 1517 2005/08/07
5212             Re:Re:Re:행인님 도움 부탁합니다. 행인 1525 2005/08/07
5215                 Re:Re:Re:Re:행인 님과 심성현님의 답변 감사합니다. 김선태 1445 2005/08/07
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.