C++ Notes

1.the difference of "string str=null;" and "tring str="";"

string str=null just declare the variable str,which points to a null,and don't allocate memory.

string str="" has allocated memory and str pointed to this space,which contains a "" character.

2.the difference of null and nullptr

null is a int type variable;

nullptr is a null pointer;

3.strange things

1)when you access the undefine space in string,it will not throw exception

example:

string str="aa";
cout<<str[5];

//run this code,there will be no exceptions,but the value of str[5] may be undefined.

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章