Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>const</code> does not change where things are stored it's a keyword to tell the compiler to prevent variables or functions from modifying things. Example:</p> <pre><code>std::string myNormalStr("Hello"); const std::string myConstStr("Don't Change Me"); myNormalStr = myConstStr; // this is ok myConstStr = myNormalStr; // this will give you a compile error </code></pre> <p>That's a super simplistic example but the same thing applies to <code>const</code> objects which are passed into functions, returned from functions, or if the function itself is <code>const</code>.</p> <p>Here's <a href="http://www.gotw.ca/gotw/006.htm" rel="nofollow">a great article by Herb Sutter</a> on all the correct ways to use the <code>const</code> keyword.</p> <p>Edit:</p> <p>Currently there is almost no reason to use the <code>auto</code> keyword as everything is implicitly auto within it's scope. This keyword is a storage class specifier for an automatic variable.</p> <p>However the <code>auto</code> keyword is changing as part of the new C++ standard in progress but is supported already by Visual Studio 2010 and some other compilers in it's new glorious form. It can be used like so in C++0x:</p> <pre><code>std::vector&lt;int&gt; numbers; for (std::vector&lt;int&gt;::const_iterator itr(numbers.begin()); itr != numbers.end(); ++itr) { // do something with each iterated element } // compiler auto deduces from rvalue // and determines that you want a // std::vector&lt;int&gt;::const_iterator type for (auto itr = numbers.cbegin(); itr != numbers.cend(); ++itr) { // do something with each iterated element } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload