const char * array[]和char * const array[]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int main()
{
    char abc[] = "abc";
    char def[] = "def";
    char * const array[] = {"abc", "def"};
    char * const array2[] = {abc, def};
    const char * array3[3] = {"abc", "def"};
    //char * const array3[2];    //error,定义的时候必须初始化,因为数组存储的是常量
    char mych[] = "hello world";
    array3[2] = mych;
    //array3[2][0] = 'z';        //error, 提示不能给常量赋值
    //array2[0] = mych;
    //array[0][0] = 'z';        //array[0]指针指向的字符串在文字常量区,不可更改
    array2[0][0] = 'z';        //array2[0]指针指向的字符串在栈区,可更改
    cout << array[0] << endl;
    cout << array2[0] << endl;
    getchar();
    return 0;
}
posted on   ︶ㄣ第二名  阅读(1409)  评论(0编辑  收藏  举报
努力加载评论中...

点击右上角即可分享
微信分享提示