字串char*
char *str1="abcde";
其實上面的char *str1是字串常量,儲存在靜態儲存區,是唯讀的,也就是說它是const char *str1 更好的表達它本身的意思。str1是乙個變數,代表的意思就是字串的第乙個字元的值
*(str1++);//可行
*(str1+2)='f';//不可行
假如
char *str2=str1;
"abcde"儲存的區域沒有改變,只是將str1的位址複製給str2;
字串陣列
char str3="abcde";
str3是陣列名,乙個常量
str3++; //不可行
str3[2]='f';//可行
假如
char *str4=&str3;
上面語句是將"abcde"複製一遍,然後再複製給是str4;
看看下面輸出的值是什麼
char str1 = "abc";
char str2 = "abc";
const char str3 = "abc";
const char str4 = "abc";
const char *str5 = "abc";
const char *str6 = "abc";
char *str7 = "abc";
char *str8 = "abc";
cout < < ( str1 == str2 ) < < endl;
cout < < ( str3 == str4 ) < < endl;
cout < < ( str5 == str6 ) < < endl;
cout < < ( str7 == str8 ) < < endl;
輸出為0 0 1 1 字串陣列char 和字串指標char 的討論
相同點 1.char a 和char a在作為形參的時候完全相同。2.在初始化時,都可以使用常量字串,區別1.內容位址不同 char a abcd 此時 abcd 存放在常量區,然後在棧上分配記憶體給a,並指向 abcd 在常量區的首位址。對於指標本身a來說,它是可變的,允許修改,可以指向其他的位址...
char 字串和char 字串的理解
一 char 字串 1.如何宣告乙個char 字串 你可以這樣 char str test str是乙個指標,存放在棧區,test 是乙個常量,存放在常量區,vs2017要求這句宣告前面必須加上const,因為它所指向的常量字串是不可更改的 delete str 還可以這樣 char str new...
字串 字元陣列 char指標 ???
最近軒少閒來無事,乘爽妹子,華晨宇,楊紫這些頂流明星攢了一波大瓜,讓微博程式設計師痛苦加班之際,又拿起c 研究了一番,對字串略有所感,在此記錄一下。大部分學c c 的人都是從 printf hello,world cout hello,world endl 開始。hello,world 是乙個字串常...