What is the difference between 'a' and “a”?

前端 未结 6 844
离开以前
离开以前 2020-12-05 20:40

I am learning C++ and have got a question that I cannot find the answer to.

What is the difference between a char constant (using single quotes) and a s

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-05 21:03

    • "a" -> it denotes it is a string. in c++ string is a collection of characters array.
    • so string is terminated by delimiter '\0' it indicates the end of string.
    • so its size would be 2 because 1-byte for "a" and 1-byte for '\0'

    where in case of 'a'-> it is single character. so its size would be 1-byte.

    char str[]="a"; 
    

    or

    char *ptr = "c";
    
    for  'c' -> char c = 'a';
    

    or we can write as well

    char c = 97;
    

提交回复
热议问题