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

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

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

13条回答
  •  伪装坚强ぢ
    2020-11-21 07:49

    A single quote is used for character, while double quotes are used for strings.

    For example...

     printf("%c \n",'a');
     printf("%s","Hello World");
    

    Output

    a  
    Hello World
    

    If you used these in vice versa case and used a single quote for string and double quotes for a character, this will be the result:

      printf("%c \n","a");
      printf("%s",'Hello World');
    

    output :

    For the first line. You will get a garbage value or unexpected value or you may get an output like this:

    While for the second statement, you will see nothing. One more thing, if you have more statements after this, they will also give you no result.

    Note: PHP language gives you the flexibility to use single and double-quotes easily.

提交回复
热议问题