Am I correct on this?

This is a discussion on Am I correct on this? within the C Programming forums, part of the General Programming Boards category; Code: void a_function(char const *foo); /* 1 */ void another_function(const char *bar); /* 2 */ On 1, the const keyword ...

  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
    212
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    C/C++Newbie Antigloss's Avatar
    Join Date
    May 2005
    Posts
    212
    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, 01: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, 12:23 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21