MEMORY-BOOK

来源:互联网 发布:银行软件开发笔试 编辑:程序博客网 时间:2024/06/06 03:32

1.when we assign a string to a char* or an array, the length of char* or array should be 1 more than the size of string, ending with '\0'. However, the end of string does not have '\0'.        

int main(){string str="hello world";char* str1;string::size_type strlen;int strtemp=0,str1temp=0;str1=&str[0];strlen=str.size();cout<<str<<endl<<str1<<endl;//if(str[strlen]=='\0')strtemp=1;//errorif(str1[strlen]=='\0')str1temp=1;//OK,output 1cout<<strtemp<<endl<<str1temp<<endl;system("pause");return 0;}


2.(++i): make i+1 then return the i you get; (i++): make i+1 but return the original i (the i before adding 1).

3. string type has default constructor while int type hasn't default constructor.Because int type is a built-in type.

string sa[10];//initialized to " "int ia[10];//initialized to 0int main(){      string sa2[10];//initialized to " "      ing ia2[10];//not be initialized}

4. 指针数组:存储指针的数组       int *p[2]

    数组指针:指向数组的指针       int (*p)[2]

    备注:[ ]优先级高于*

5.DOS and WINDOWS 's eof can put CTRL+Z. UNIX's is CTRL+D.