指针和数组存储区

1.

    char *quot = "l1302-C-11250";   // *quot是字符串常量,存放在静态存储区
    char *p = quot;
    while(*p != '\0'){
        if(*p == '-'){
            *p = '_';   //出错
        }
        p++;
    }

2.

   char quot[20] = "l1302-C-11250"; //字符数组,存放在堆栈中
    char *p = quot;
    while(*p != '\0'){
        if(*p == '-'){
            *p = '_'; //正确
        }
        p++;
    }

posted @ 2013-01-30 16:55  jackie2018  阅读(230)  评论(0编辑  收藏  举报