Skip to content

Const

:material-circle-edit-outline: 约 6 个字 :fontawesome-solid-code: 28 行代码

Pointers and constants

string p("Fe");
const string *p = &p1;
string const *p = &p1;
string *const p = &p1;
char c;
const char cc;

char *cp;
const char * ccp;

ccp = &c;
ccp = &c;

cp = &cc;   //illegal
ccp = &cc;
char *const p = "abc";
*q = 'c';//legal
q++;    //illegal
char *string p = "abc";
//(*p) is a const char
*p = 'b'; //illegal

String Literals

char *s = "ass";
// == const char* s
//Don't try and change the character values 

//If you want to change the string, put it in an array:
char s[] = "Hello, world!";