Results 1 to 5 of 5

Thread: Can you explain me...??

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2000
    Posts
    50

    Can you explain me...??

    can you explain one primitive thing ???
    i dont understand this:

    Code:
    char * cp;
    cp = "Ahoj";

    ?? when i want to create a pointer to int's array, i write : int * iP[10], but when i want to create char's array (string), i use char * cP only. I hope that what i said here is right......o

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    When you put "sggrs" (or any other constant string) into your source, it is put as part of the final .EXE file in a static buffer. This means that:
    Code:
    char *pcStr; // Pointer variable
    pcStr = "hello"; // Assign to static variable in memory
    The compiler doesn't need to allocate any extra memory for it, since it's already there.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    int * iP[10]
    is an array of pointers to ints. while
    int * iP = new int[10]
    is a pointer to a int array.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    Originally posted by parksie
    Code:
    char *pcStr; // Pointer variable
    pcStr = "hello"; // Assign to static variable in memory
    Can i change this later, or is pcStr constant?
    Alcohol & calculus don't mix.
    Never drink & derive.

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You can change pcStr, but then you lose the pointer to that data. It's not a memory leak because it's static data anyway.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width