C语言两种定义字符串的方式

/**
     *  1.字符串的定义方式
     */
    //可变字符串(放到栈里边)栈里边放局部变量有几份变量就有几个内存空间
    char name[4] = "zkz";
     char name3[4] = "zkz";
    printf("name[4] = %p\n",name);//name[4] = 0x7fff5fbff79c
    printf("name3[4] = %p\n",name3);//name3[4] = 0x7fff5fbff798
     //不可变字符串     放到常量区且只有一份能存空间
    char *name1 = "zkz";
    char *name2 ="zkz";
    printf("name1=%p\n",name1);//name1 = 0x100000f86
    printf("name2=%p\n",name2);//name2 = 0x100000f86

 

posted @ 2016-03-20 10:57  张凯泽  阅读(900)  评论(0编辑  收藏  举报