const int a = 1; // read as "a is an integer which is constant"
int const a = 1; // read as "a is a constant integer"
Both are the same thing. Therefore:
a = 2; // Can't do because a is constant
The reading backwards trick especially comes in handy when you're dealing with more complex declarations such as:
const char *s; // read as "s is a pointer to a char that is constant"
char c;
char *const t = &c; // read as "t is a constant pointer to a char"
*s = 'A'; // Can't do because the char is constant
s++; // Can do because the pointer isn't constant
*t = 'A'; // Can do because the char isn't constant
t++; // Can't do because the pointer is constant
출처 : http://stackoverflow.com/questions/162480/const-int-vs-int-const-as-function-parameter-in-c-and-c
'Programming > C & C++' 카테고리의 다른 글
[C++] different underlying type in enum 'enum class TypeName' (0) | 2019.06.14 |
---|---|
[C++] Inheritance: 'A' is an inaccessible base of 'B' (0) | 2019.06.12 |
C에서 날짜 출력하기 (0) | 2015.01.21 |
WindowsAPI C언어에서 파일 목록 가져오기 (0) | 2014.11.19 |
C++ SDL 콘솔창 숨기는법 (0) | 2012.08.23 |
C++ STL vector sort 정렬함수 (0) | 2012.08.18 |
C++ sstream( sscanf, 문자열스트림 ) (0) | 2012.08.18 |
__imp__WSACleanup@0 외부 기호(참조 위치: _main 함수)에서 확인하지 못했습니다 (0) | 2012.08.17 |