Thread: Question on char arrays

  1. #16
    C/C++ homeyg's Avatar
    Join Date
    Nov 2004
    Location
    Louisiana, USA
    Posts
    209
    Oh, sorry, typo. I meant array.

  2. #17
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    A dynamic array is stored on the heap; a static array is stored on the stack.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  3. #18
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    I don't believe there is any rule for where "The Empire Strikes Back" must be stored
    A constant string such as this is stored in static memory (along with any static and global variables).

  4. #19
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    Quote Originally Posted by sigfriedmcwild
    In c/c++ an array IS a pointer. They are equivalent in everything .

    WHOA!!! I just had to put my two cents in while reading this thread, then i saw all the gurus' already tore into you.
    ouch. Hope you figured it out now, if not search the board, you'll find tons on schooling on the difference.


    I said that an array is a pointer because that's what I've read in at least 2 books. I guess they just glossed over the important details.

    Sorry about that
    was the authour of your book named herbert schildt by the way?
    Last edited by caroundw5h; 12-22-2004 at 10:32 PM.
    Warning: Opinions subject to change without notice

    The C Library Reference Guide
    Understand the fundamentals
    Then have some more fun

  5. #20
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    A constant string such as this is stored in static memory (along with any static and global variables).
    But if they're stored in the same place as globals and static variables, which are modifiable, then where does this stuff about read-only memory come from? It makes sense if it's stored in the same way as const variables, but I just don't see it happening with globals.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  6. #21
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Sorry, I misspoke. I should have said that a string such as "The Return of the Temple of Doom" is stored in constant memory alongside static memory where static and global variables reside. If you would be so kind, pardon my zinger.

  7. #22
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>is stored in constant memory alongside static memory
    Maybe I should read a book about this So the constant memory block is adjacent to the static memory block, and string literals are stored in the constant memory block, while globals/statics are stored in the static memory block.

    Did I get it this time?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  8. #23
    Registered User
    Join Date
    Jan 2003
    Posts
    311
    The only requrement for a string literal is that it exist at the time of instansiation. Thus char *s="This is a string?"; s must contain the address of consecutive characters containing the string. The normal way this is done, and this is just an implementation issue, is that the string is contained within the code segment. Beause the instructions must be loaded before execution can begin, and string literals are often requred very early in program execution it makes sense to load these strings with the instructions. On modern computers memory is devided into pages, and some of these pages have different attributes. Pages that contain instructions don't change, so the processor tags them as read only. This lets the processor have two cache mechanisms, a write back and complicated cache for data and a much simpler cache for instructions. As self-modifiying code is frowned upon making this cache read-only saves a lot of effort.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. char ** and argv memory question
    By simo_mon in forum C Programming
    Replies: 3
    Last Post: 08-17-2008, 08:47 AM
  3. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  4. Passing pointers to arrays of char arrays
    By bobthebullet990 in forum C Programming
    Replies: 5
    Last Post: 03-31-2006, 05:31 AM
  5. Newb Question - Cant convert Char[41] to Char
    By Kalkran in forum C++ Programming
    Replies: 2
    Last Post: 08-19-2004, 10:05 AM