Single quotes vs. double quotes in C or C++

前端 未结 13 1224
别那么骄傲
别那么骄傲 2020-11-21 07:14

When should I use single quotes and double quotes in C or C++ programming?

13条回答
  •  梦谈多话
    2020-11-21 07:59

    In C & C++ single quotes is known as a character ('a') whereas double quotes is know as a string ("Hello"). The difference is that a character can store anything but only one alphabet/number etc. A string can store anything. But also remember that there is a difference between '1' and 1. If you type cout<<'1'<

    cout<

    This time the first line would be 48. As when you convert a character to an int it converts to its ascii and the ascii for '1' is 48. Same, if you do:

    string s="Hi";
    s+=48; //This will add "1" to the string
    s+="1"; This will also add "1" to the string
    

提交回复
热议问题