whats the difference between these types

This is a discussion on whats the difference between these types within the C++ Programming forums, part of the General Programming Boards category; assuming struct S is defined, 'const struct S *&' and 'struct S * const &' using VC6...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    552

    whats the difference between these types

    assuming struct S is defined,
    'const struct S *&' and 'struct S * const &'

    using VC6
    C Code. C Code Run. Run Code Run... Please!

    "Love is like a blackhole, you fall into it... then you get ripped apart"

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    552
    So the placement of the const determines what it is applied to? How do you determine what is constant and what isnt based on the type?
    C Code. C Code Run. Run Code Run... Please!

    "Love is like a blackhole, you fall into it... then you get ripped apart"

  3. #3
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    So the placement of the const determines what it is applied to?
    Yes.
    How do you determine what is constant and what isnt based on the type?
    const only applies to the pointer when it's placed after the asterisk. For example, these two declarations are equivalent:
    Code:
    const MyType* MyVar;
    MyType const* MyVar;
    Meaning, MyVar can change, but *MyVar cannot. However,
    Code:
    MyType* const MyVar;
    means MyVar cannot change, but *MyVar can.

  4. #4
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Or if you like symmetry:

    MyType const * const MyVar;
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Finding the difference in two times
    By muthus in forum C++ Programming
    Replies: 4
    Last Post: 01-24-2008, 06:36 PM
  2. Difference Equations / Recurrence Relations
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 10-05-2007, 11:26 AM
  3. What's the difference between var++ and ++var
    By ulillillia in forum C Programming
    Replies: 6
    Last Post: 05-31-2007, 03:27 AM
  4. Replies: 6
    Last Post: 08-27-2006, 12:09 AM
  5. Replies: 10
    Last Post: 11-06-2005, 09:29 PM

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