Thread: What exactly is the purpose of single quotes? For example, the following array here:

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    42

    What exactly is the purpose of single quotes? For example, the following array here:

    actually can you explain everything about this piece?


    Code:
    const char baseDigits[10] =
             {'0', '1', '2', '3', '4',
              'A','B','C','D', 'E'} ;
    SO I know the array contains 10 numbers and that they are the ones included in the bracket....what is const? What are the single quotes for????

  2. #2
    Registered User
    Join Date
    Sep 2011
    Location
    Stockholm, Sweden
    Posts
    131
    const means that the array of chars should be constant, i.e. not changed. If you try to change anything in the array the compiler will give you an error/warning.
    The single quotes means that it is a single char, and it's ascii value will be assigned to the array element.

    These two statements mean the same thing, but if you are dealing with characters it's easier to deal with them as letters rather than their ASCII-value counterparts.
    Code:
    char c;
    c = 'a';
    c = 97;

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Single quotes mean an ascii character as iceway points out... 'A' can be stored as a single byte.
    Double quotes mean a null terminated string... "A" actually needs 2 bytes... one for the A one for the trailing 0.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why am I using single quotes around "|"?
    By jackson6612 in forum C++ Programming
    Replies: 4
    Last Post: 09-20-2011, 09:55 AM
  2. single vs double quotes
    By innuendo in forum C++ Programming
    Replies: 17
    Last Post: 11-03-2008, 05:38 PM
  3. multiple characters within single quotes
    By BattlePanic in forum C Programming
    Replies: 4
    Last Post: 05-06-2008, 02:59 AM
  4. Multi line quotes used on single lines
    By CBUK in forum C Programming
    Replies: 7
    Last Post: 02-03-2005, 08:11 AM
  5. outputing quotes(') and double quotes(")
    By lostboy in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 02-26-2002, 06:17 PM