Thread: String

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    102

    String

    I'm reading something about string and came across something that i'm blur. Please do help me.

    char color[] = "blue"; //5-element array color containing 'b','l','u','e','\0'
    const char *colorPtr = "blue"; //create pointer variable colorPtr that points to the string "blue' somewhere in memory


    How is const char *colorPtr looks like in memory. I'm so blur about it. For char color[], I'm ok with it. Thanks

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    The char* will simply have the address of the first letter of the string literal, stored in a special section of your program's executable image.

    In other words, it points to the string.

  3. #3
    Registered User
    Join Date
    Aug 2011
    Posts
    102

    just another one

    Thanks for that. I understand. Just asking......What is

    int **blue;

    Does this means dereference twice? And i remember my lecturer told me that there are something like type int*, int*** or else .....quite confusing. What is actually this?

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    int **blue is a pointer to the pointer named blue.

    You would use this when you want to alter the pointer itself, not the values it points to.

    for example...
    Code:
    *blue = malloc(some_number * sizeof(int));
    assigns memory to blue to create an array.

  5. #5
    Registered User
    Join Date
    Aug 2011
    Posts
    102

    TY

    Ok thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 22
    Last Post: 07-28-2011, 01:26 PM
  2. Replies: 7
    Last Post: 06-16-2011, 06:21 PM
  3. Replies: 5
    Last Post: 05-09-2010, 10:58 AM
  4. Replies: 1
    Last Post: 10-31-2005, 11:36 AM
  5. Problem comparing string from text file with string constant
    By XenoCodex Admin in forum C++ Programming
    Replies: 3
    Last Post: 07-25-2002, 10:17 AM