CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2009
    Posts
    24

    Advantages of using "Const "

    Hi,
    I know that usage of "const" will replace the traditional macro "#define"
    but there are lots of other advantages using the "const" keyword.

    can some one explain the advantages of using "Const" over #define with reference "MEMORY CONSUMPTION"

  2. #2
    Join Date
    Apr 2009
    Posts
    598

    Re: Advantages of using "Const "

    Something declared with const does not change.
    If the compiler sees two identical const things, it might save space by having the same location referenced by these two things.

  3. #3
    Join Date
    Nov 2007
    Posts
    613

    Re: Advantages of using "Const "

    The amout of memory used is the same in both cases (if we're talking about unsigned integers). In either case the compiler will replace all the occurences of the symbol with the number you supplied.

    What const offers additionally is the fact that you can set a specific type and size for that value.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured