Thread: whats the difference between these types

  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, 10:26 AM
  3. What's the difference between var++ and ++var
    By ulillillia in forum C Programming
    Replies: 6
    Last Post: 05-31-2007, 02:27 AM
  4. Replies: 6
    Last Post: 08-26-2006, 11:09 PM
  5. Replies: 10
    Last Post: 11-06-2005, 09:29 PM