Thread: Question about pointers #2

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Remember that 'string' is a bad variable name to use, as it is already part of the std namepsace of the header <string>. You should use a more descriptive name too, such as:
    Code:
    char *lpchString; //Indicates that the variable is a pointer to a char
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >You should use a more descriptive name too, such as: <snip godawful hungarian notation>
    The name string or str or anything similar is silly anyway. A more descriptive name can easily be found, such as buffer or line or name, so that it more readily depicts how the string is going to be used. The code makes it obvious that the simulated array is to be used as a C-style string, the name should tell readers what the string is logically going to be used for.

    >>Will this work? No memory leaks, other problems etc...?
    >Yes.
    No, it won't. Mixing new[] with delete is undefined, delete[] should be used instead.

    >The very first memory address of ram (0) is classified as off-limits
    A null pointer doesn't have to be address 0, it just has to be some value that would not be a valid pointer.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Jun 2004
    Posts
    124
    In response to those who said my variable names were bad or misleading, I know, this was just an example I wrote to ask my question, I don't actually use names like this in my real programs, but thanks for pointing it out

    Thanks to all of you for helping me with my problem, this is a great community and I'm glad I stumbled across it, thanks all!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array pointers question?
    By ben2000 in forum C Programming
    Replies: 4
    Last Post: 07-26-2007, 01:31 AM
  2. A question on Pointers & Structs
    By FJ8II in forum C++ Programming
    Replies: 4
    Last Post: 05-28-2007, 10:56 PM
  3. simple pointers question
    By euphie in forum C Programming
    Replies: 4
    Last Post: 05-25-2006, 01:51 AM
  4. Very stupid question involving pointers
    By 7smurfs in forum C Programming
    Replies: 6
    Last Post: 03-21-2005, 06:15 PM
  5. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM