Sign ' is the same as \' ?

This is a discussion on Sign ' is the same as \' ? within the C Programming forums, part of the General Programming Boards category; Hello everyone, I am surprised to see that the value of sign ' is the same as \'. So, there ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    Sign ' is the same as \' ?

    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.

    Code:
    #include <string.h>
    
    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

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,639
    In this case there is no need since it is in a string literal, and thus the delimiters are double quotes. However, if you want to specify it as a char literal, you need to escape it:
    Code:
    char c = '\'';
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. mantissa, sign, exponent
    By -EquinoX- in forum C Programming
    Replies: 28
    Last Post: 03-05-2008, 01:25 PM
  2. My own itoa()
    By maxorator in forum C++ Programming
    Replies: 18
    Last Post: 10-15-2006, 11:49 AM
  3. Handle on MSN Messenger's Sign In "button"?
    By jmd15 in forum Windows Programming
    Replies: 3
    Last Post: 07-16-2005, 09:28 PM
  4. How to detect change in sign?
    By bugsmashers in forum C++ Programming
    Replies: 16
    Last Post: 02-20-2005, 06:27 PM
  5. Sign Up!: The Third Round, both contests
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 54
    Last Post: 07-20-2002, 05:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21