Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Sign ' is the same as \' ?

Sign ' is the same as \' ?

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    George_George
    wrote on last edited by
    #1

    Hello everyone, I am surprised to see that the value of sign ' is the same as \'. So, there is no need to add sign \ before sign '? In my past knowledge of sign ', we always need to add sign \ before sign '. Any comments? Here is my simple program to test. int main (int argc, char** argv) { char* p1 = "Hello \'World\'"; char* p2 = "Hello 'World'"; int result = 0; result = strcmp(p1, p2); return 0; } thanks in advance, George

    CPalliniC 1 Reply Last reply
    0
    • G George_George

      Hello everyone, I am surprised to see that the value of sign ' is the same as \'. So, there is no need to add sign \ before sign '? In my past knowledge of sign ', we always need to add sign \ before sign '. Any comments? Here is my simple program to test. int main (int argc, char** argv) { char* p1 = "Hello \'World\'"; char* p2 = "Hello 'World'"; int result = 0; result = strcmp(p1, p2); return 0; } thanks in advance, George

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      My friend, is quite obvious that ' is different from \' :-D (just kidding). Talking a bit seriously, you need such an escape sequence (that is symbol \') in circumstances like the following:

      char c = '\'';

      :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

      In testa che avete, signor di Ceprano?

      G 1 Reply Last reply
      0
      • CPalliniC CPallini

        My friend, is quite obvious that ' is different from \' :-D (just kidding). Talking a bit seriously, you need such an escape sequence (that is symbol \') in circumstances like the following:

        char c = '\'';

        :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

        G Offline
        G Offline
        George_George
        wrote on last edited by
        #3

        Hi CPallini, Actually I am also confused when I tried that, "Hello 'World'" is the same as "Hello \'World\'". I have also tried your sample. Now I am more confused... 1. What is the rule when we should use \' or single ' ? 2. When there is no differences between \' and '? (like my Hello 'World' sample) regards, George

        D T 2 Replies Last reply
        0
        • G George_George

          Hi CPallini, Actually I am also confused when I tried that, "Hello 'World'" is the same as "Hello \'World\'". I have also tried your sample. Now I am more confused... 1. What is the rule when we should use \' or single ' ? 2. When there is no differences between \' and '? (like my Hello 'World' sample) regards, George

          D Offline
          D Offline
          DoomedOne
          wrote on last edited by
          #4

          Hi. You use single ' inside a string delimited by " characters i.e. char* p2 = "Hello 'World'"; You use the \' when iusing it as a single character that need to be quoted within ' characters i.e. char p1 = '\'';

          Habetis bona deum

          G 1 Reply Last reply
          0
          • G George_George

            Hi CPallini, Actually I am also confused when I tried that, "Hello 'World'" is the same as "Hello \'World\'". I have also tried your sample. Now I am more confused... 1. What is the rule when we should use \' or single ' ? 2. When there is no differences between \' and '? (like my Hello 'World' sample) regards, George

            T Offline
            T Offline
            toxcct
            wrote on last edited by
            #5

            as CPallini stated, you need to use \' only when the compiler can get confused. technically, \' is the same ascii code as the character '. just same as \" is the same ascii code as the character ". so, in brief, ben you use ' in a string (so, rounded with "s), you don't need to use the escapment char ( \ ). when you use " as a single char, no need either to use \. some examples: "Hello \'World\'" is the same as "Hello 'World'". "Hello **"**World"" is forbidden because the second " char is understood as the end of the string. here, you MUST write: "Hello **\"**World**\"**" '"' is the ascii code of the " character. '**'**' is forbidden. here again, the second ' char is understood as the end of the character specification. You MUST write: '**\'**'. get it now ? subsidiary question: please, for god' sake, in what school level are you, and how old are you ? i'm not judging you, i'm questionning myself.


            [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

            G 1 Reply Last reply
            0
            • D DoomedOne

              Hi. You use single ' inside a string delimited by " characters i.e. char* p2 = "Hello 'World'"; You use the \' when iusing it as a single character that need to be quoted within ' characters i.e. char p1 = '\'';

              Habetis bona deum

              G Offline
              G Offline
              George_George
              wrote on last edited by
              #6

              Good reply, thanks DoomedOne! regards, George

              1 Reply Last reply
              0
              • T toxcct

                as CPallini stated, you need to use \' only when the compiler can get confused. technically, \' is the same ascii code as the character '. just same as \" is the same ascii code as the character ". so, in brief, ben you use ' in a string (so, rounded with "s), you don't need to use the escapment char ( \ ). when you use " as a single char, no need either to use \. some examples: "Hello \'World\'" is the same as "Hello 'World'". "Hello **"**World"" is forbidden because the second " char is understood as the end of the string. here, you MUST write: "Hello **\"**World**\"**" '"' is the ascii code of the " character. '**'**' is forbidden. here again, the second ' char is understood as the end of the character specification. You MUST write: '**\'**'. get it now ? subsidiary question: please, for god' sake, in what school level are you, and how old are you ? i'm not judging you, i'm questionning myself.


                [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                G Offline
                G Offline
                George_George
                wrote on last edited by
                #7

                Cool toxcct! I must save your reply to somewhere. :-) regards, George

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups