Thread: Am I correct on this?

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    204

    Am I correct on this?

    Code:
    void a_function(char const *foo); /* 1 */
    void another_function(const char *bar); /* 2 */
    On 1, the const keyword prevents the data being pointed to by foo to be modified.
    On 2, the const keyword prevents bar from pointing to somewhere else.

    Am I correct on this? Thanks

  2. #2
    C/C++Newbie Antigloss's Avatar
    Join Date
    May 2005
    Posts
    216
    No! It should be "char * const bar" for your second purpose

    const char *bar is equal to char const * bar

  3. #3
    ---
    Join Date
    May 2004
    Posts
    1,379
    I think Antigloss is right. I'm not an expert on the subject but I think I saw a thread on it not too long ago.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > I think Antigloss is right.
    So do I
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    C/C++Newbie Antigloss's Avatar
    Join Date
    May 2005
    Posts
    216
    So does the compiler

  6. #6
    Registered User
    Join Date
    Jun 2004
    Posts
    201
    Quote Originally Posted by Antigloss
    So does the compiler
    The One Compiler?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linux for GNU/Linux is not correct?
    By password636 in forum Linux Programming
    Replies: 8
    Last Post: 03-31-2009, 08:30 PM
  2. Is this correct : passing strings?
    By socket in forum C Programming
    Replies: 15
    Last Post: 11-25-2008, 02:03 PM
  3. correct order to insert new node?
    By campermama in forum C++ Programming
    Replies: 1
    Last Post: 06-16-2004, 07:51 PM
  4. Replies: 1
    Last Post: 05-26-2004, 12:58 AM
  5. Loop until enter correct value
    By jchanwh in forum C Programming
    Replies: 2
    Last Post: 11-27-2001, 01:23 AM