Ключевое слово const делает объявление после этого ключевого слова константой. код объясняет лучше, чем слова:
/////// Test-code. Place anywhere in global space in C/C++ code, step with debugger
char a1[] = "test1";
char a2[] = "test2";
char *data[2] = {a1,a2};
// Nothing const, change letters in words, replace words, re-point to other block of words
char **string = &data[0];
// Can't change letters in words, but replace words, re-point to other block of words
const char **string1 = (const char **) &data[0];
// Can neither change letters in words, not replace words, but re-point to other block of words
const char * const* string2 = (const char * const*) &data[0];
// Can change nothing, however I don't understand the meaning of the 2nd const
const char const* const* const string3 = (const char const* const* const) &data[0];
int foo()
{
// data in debugger is: {"test1","test2"}
**string = 'T'; //data is now {"Test1","test2"}
//1 **string1 = 'T'; //Compiler error: you cannot assign to a variable that is const (VS2008)
*string1=a2; //data is now {"test2","test2"}
//2 **string2='T'; //Compiler error: you cannot assign to a variable that is const (VS2008)
//3 *string2=a2; //Compiler error: you cannot assign to a variable that is const (VS2008)
string2=string1;
//4 **string3='T'; //Compiler error: you cannot assign to a variable that is const (VS2008)
//5 *string3=a2; //Compiler error: you cannot assign to a variable that is const (VS2008)
//6 string3=string1; //Compiler error: you cannot assign to a variable that is const (VS2008)
return 0;
}
static int dummy = foo();
/////// END OF Test-code
справа налево, строк постоянный указатель, указывающий на постоянный указатель, ссылающийся на константные набор символов? – Arunmu
Проводили ли вы какое-либо исследование того, как формируются декларации C? – Angew
@Pavan Вероятно, вы должны начать с этого. http://stackoverflow.com/questions/4949254/const-char-const-versus-const-char – Arunmu