{"id":2258,"date":"2025-02-10T22:48:55","date_gmt":"2025-02-10T22:48:55","guid":{"rendered":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/?page_id=2258"},"modified":"2025-02-15T17:43:06","modified_gmt":"2025-02-15T17:43:06","slug":"const-volatile-mutable-and-more","status":"publish","type":"page","link":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/topics\/c-details\/const-volatile-mutable-and-more\/","title":{"rendered":"const, volatile, mutable, and More"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"const_volatile_mutable_and_More\"><\/span>const, volatile, mutable, and More<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In C++, <strong>const<\/strong>, <strong>volatile<\/strong>, and <strong>mutable<\/strong> are type qualifiers that modify the behavior of variables.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"const\"><\/span>const<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>const<\/strong> specifies that a variable&#8217;s value cannot be changed after initialization. Any attempt to modify a <strong>const<\/strong> variable will result in a compile-time error.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"volatile\"><\/span>volatile<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>volatile<\/strong> indicates that a variable&#8217;s value can be changed by external factors outside the control of the program, such as hardware or another thread. It prevents the compiler from performing optimizations that might assume the variable&#8217;s value remains constant.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"mutable\"><\/span>mutable<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>mutable<\/strong> applies only to class members and allows modification of a member variable even within a <code><strong>const<\/strong><\/code> object. It is useful when a class has internal state that needs to be updated without affecting the object&#8217;s externally visible <strong>const<\/strong>-ness.<\/p>\n\n\n\n<p><strong>mutable<\/strong> may not be used in combination with <strong>static<\/strong> or <strong>const<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Some_C_Specification_Jargon\"><\/span>Some C++ Specification Jargon<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Here is some jargon from the C++ specification which may be a little esoteric, but you may find this jargon used in some compiler error and warning messages.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"cv_const_and_volatile_type_qualifiers\"><\/span>cv (const and volatile) type qualifiers<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>Any (possibly incomplete) type other than function type or reference type is a type in a group of the following four distinct but related types:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A <em>cv-unqualified<\/em> version.<\/li>\n\n\n\n<li>A <em>const-qualified<\/em> version.<\/li>\n\n\n\n<li>A <em>volatile-qualified<\/em> version.<\/li>\n\n\n\n<li>A <em>const-volatile-qualified<\/em> version.<\/li>\n<\/ul>\n\n\n\n<p>Array types are considered to have the same <em>cv-qualification<\/em> as their element types.<\/p>\n\n\n\n<p>A <em>const volatile object<\/em> is:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>an object whose type is <em>const-volatile-qualified<\/em>,<\/li>\n\n\n\n<li>a non-mutable subobject of a const volatile object,<\/li>\n\n\n\n<li>a const subobject of a volatile object, or<\/li>\n\n\n\n<li>a non-mutable volatile subobject of a const object.<\/li>\n<\/ul>\n\n\n\n<p>Behaves as both a <strong>const<\/strong> object and as a <strong>volatile<\/strong> object.<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Examples\"><\/span>Examples<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The following program exhibits a number of compile-time errors:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(0, 0, 0, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"\/\/\n\/\/  main.cpp\n\/\/  const, volatile, mutable\n\/\/\n\/\/  Created by Bryan Higgs on 2\/10\/25.\n\/\/\n\n#include &lt;iostream&gt;\n\nclass Example \n{\npublic:\n  Example(int a, int b, int c)\n    : constVar(a), nonConstVar(b), volatileVar(c), mutableVar(0)\n  {}\n\n  void modify() \n  {\n    nonConstVar = 10; \/\/ OK\n    constVar = 20; \/\/ Cannot assign to non-static data member 'constVar' with const-qualified type 'const int'\n                   \/\/ Non-static data member 'constVar' declared const\n    volatileVar = 30; \/\/ OK\n    mutableVar = 40; \/\/ OK\n  }\n\n  void constModify() const\n  {\n    nonConstVar = 10;\n    constVar = 20; \/\/ Cannot assign to non-static data member within const member function 'constModify'\n                   \/\/ Member function 'Example::constModify' is declared const\n    volatileVar = 30; \/\/ Cannot assign to non-static data member within const member function 'constModify'\n                      \/\/ Member function 'Example::constModify' is declared const\n    mutableVar = 40;  \/\/ OK to modify a mutable member in a const member function\n  }\n  \nprivate:\n  int nonConstVar;\n  const int constVar;\n  volatile int volatileVar;\n  mutable int mutableVar;\n};\n\nint main(int argc, const char * argv[])\n{\n  const Example constObj(1, 2, 3);\n  constObj.constModify();\n\n  Example obj(4, 5, 6);\n  obj.modify();\n\n  volatile int vol = 7;\n  const volatile int constVol = 8;\n\n  vol = 9; \/\/ OK\n  constVol = 10; \/\/ Cannot assign to variable 'constVol' with const-qualified type 'const volatile int'\n                 \/\/ Variable 'constVol' declared const\n  int x = vol; \/\/ Compiler must read the current value of vol\n  int y = constVol; \/\/ Compiler must read the current value of constVol\n\n  return 0;\n}\" style=\"color:#000000;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki light-plus\" style=\"background-color: #FFFFFF\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  main.cpp<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  const, volatile, mutable<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Created by Bryan Higgs on 2\/10\/25.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">#<\/span><span style=\"color: #001080\">include<\/span><span style=\"color: #000000\"> &lt;<\/span><span style=\"color: #001080\">iostream<\/span><span style=\"color: #000000\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">class<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Example<\/span><span style=\"color: #000000\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #001080\">public<\/span><span style=\"color: #000000\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #267F99\">Example<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #267F99\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">a<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #267F99\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">b<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #267F99\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">c<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    : <\/span><span style=\"color: #267F99\">constVar<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #267F99\">a<\/span><span style=\"color: #000000\">), <\/span><span style=\"color: #795E26\">nonConstVar<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">b<\/span><span style=\"color: #000000\">), <\/span><span style=\"color: #795E26\">volatileVar<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">c<\/span><span style=\"color: #000000\">), <\/span><span style=\"color: #795E26\">mutableVar<\/span><span style=\"color: #000000\">(0)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">modify<\/span><span style=\"color: #000000\">() <\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">nonConstVar<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #098658\">10<\/span><span style=\"color: #000000\">; <\/span><span style=\"color: #008000\">\/\/ OK<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">constVar<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #098658\">20<\/span><span style=\"color: #000000\">; <\/span><span style=\"color: #008000\">\/\/ Cannot assign to non-static data member &#39;constVar&#39; with const-qualified type &#39;const int&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                   <\/span><span style=\"color: #008000\">\/\/ Non-static data member &#39;constVar&#39; declared const<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">volatileVar<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #098658\">30<\/span><span style=\"color: #000000\">; <\/span><span style=\"color: #008000\">\/\/ OK<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">mutableVar<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #098658\">40<\/span><span style=\"color: #000000\">; <\/span><span style=\"color: #008000\">\/\/ OK<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">constModify<\/span><span style=\"color: #000000\">() const<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">nonConstVar<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #098658\">10<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">constVar<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #098658\">20<\/span><span style=\"color: #000000\">; <\/span><span style=\"color: #008000\">\/\/ Cannot assign to non-static data member within const member function &#39;constModify&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                   <\/span><span style=\"color: #008000\">\/\/ Member function &#39;Example::constModify&#39; is declared const<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">volatileVar<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #098658\">30<\/span><span style=\"color: #000000\">; <\/span><span style=\"color: #008000\">\/\/ Cannot assign to non-static data member within const member function &#39;constModify&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                      <\/span><span style=\"color: #008000\">\/\/ Member function &#39;Example::constModify&#39; is declared const<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">mutableVar<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #098658\">40<\/span><span style=\"color: #000000\">;  <\/span><span style=\"color: #008000\">\/\/ OK to modify a mutable member in a const member function<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #001080\">private<\/span><span style=\"color: #000000\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #267F99\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">nonConstVar<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">constVar<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">volatile<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">volatileVar<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">mutable<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">mutableVar<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">main<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">argc<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #001080\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">char<\/span><span style=\"color: #000000\"> * <\/span><span style=\"color: #001080\">argv<\/span><span style=\"color: #000000\">[])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0070C1\">Example<\/span><span style=\"color: #000000\"> constObj(1, 2, 3);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">constObj<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">constModify<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">Example<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">obj<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">5<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">6<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">obj<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">modify<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">volatile<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">vol<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #098658\">7<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0070C1\">volatile<\/span><span style=\"color: #000000\"> int constVol = <\/span><span style=\"color: #098658\">8<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">vol<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #098658\">9<\/span><span style=\"color: #000000\">; <\/span><span style=\"color: #008000\">\/\/ OK<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">constVol<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #098658\">10<\/span><span style=\"color: #000000\">; <\/span><span style=\"color: #008000\">\/\/ Cannot assign to variable &#39;constVol&#39; with const-qualified type &#39;const volatile int&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                 <\/span><span style=\"color: #008000\">\/\/ Variable &#39;constVol&#39; declared const<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">x<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #001080\">vol<\/span><span style=\"color: #000000\">; <\/span><span style=\"color: #008000\">\/\/ Compiler must read the current value of vol<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">y<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #001080\">constVol<\/span><span style=\"color: #000000\">; <\/span><span style=\"color: #008000\">\/\/ Compiler must read the current value of constVol<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"constexpr_Specifier_since_C11\"><\/span>constexpr Specifier (since C++11)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The idea of <strong>constexpr<\/strong> is to provide a performance improvement for programs by doing computations at compile time rather than run time. Note that once a program is compiled and finalized by the developer, it is run multiple times by users. The idea is to spend time in compilation and save time at run time (similar to <em>template metaprogramming<\/em> &#8211; see later&#8230;). &nbsp;<\/p>\n\n\n\n<p><strong>constexpr<\/strong> specifies that the value of an object or a function can be evaluated at compile-time and the expression can be used in other constant expressions.&nbsp;Such entities can then be used where only compile time constant expressions are allowed (provided that appropriate function arguments are given).<\/p>\n\n\n\n<p>A <strong>constexpr<\/strong> specifier used in an object declaration or non-static member function (until C++14) implies <strong>const<\/strong>.<\/p>\n\n\n\n<p>A <strong>constexpr<\/strong> specifier used in the first declaration of a function or static data member (since C++17) implies <strong>inline<\/strong>. If any declaration of a function or function template has a <strong>constexpr<\/strong> specifier, then every declaration must contain that specifier.<\/p>\n\n\n\n<p>It defines an expression that can be evaluated at compile time.<\/p>\n\n\n\n<p><em>Constant expressions<\/em> can be used as non-type template arguments, array sizes, and in other contexts that require constant expressions, for example:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(1 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(0, 0, 0, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"int n = 1;\nstd::array&lt;int, n&gt; a1; \/\/ Non-type template argument is not a constant expression\n                       \/\/ Read of non-const variable 'n' is not allowed in a constant expression\nconst int cn = 2;\nstd::array&lt;int, cn&gt; a2; \/\/ OK: \u201ccn\u201d is a constant expression\" style=\"color:#000000;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki light-plus\" style=\"background-color: #FFFFFF\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">n<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #098658\">1<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">std::<\/span><span style=\"color: #001080\">array<\/span><span style=\"color: #000000\">&lt;<\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #001080\">n<\/span><span style=\"color: #000000\">&gt; <\/span><span style=\"color: #001080\">a1<\/span><span style=\"color: #000000\">; <\/span><span style=\"color: #008000\">\/\/ Non-type template argument is not a constant expression<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">                       <\/span><span style=\"color: #008000\">\/\/ Read of non-const variable &#39;n&#39; is not allowed in a constant expression<\/span><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0070C1\">int<\/span><span style=\"color: #000000\"> cn = <\/span><span style=\"color: #098658\">2<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">std::<\/span><span style=\"color: #001080\">array<\/span><span style=\"color: #000000\">&lt;<\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #001080\">cn<\/span><span style=\"color: #000000\">&gt; <\/span><span style=\"color: #001080\">a2<\/span><span style=\"color: #000000\">; <\/span><span style=\"color: #008000\">\/\/ OK: \u201ccn\u201d is a constant expression<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>NOTE:<\/strong> We talk about templates in detail later, so, until then, bear with us&#8230;<\/p>\n<\/blockquote>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"constexpr_variable\"><\/span>constexpr variable<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>A variable or variable template (since C++14) can be declared <strong>constexpr<\/strong> if all following conditions are satisfied:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The declaration is a definition.<\/li>\n\n\n\n<li>It is of a literal type.<\/li>\n\n\n\n<li>It is initialized (by the declaration).<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"constexpr_Example\"><\/span>constexpr Example<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>Here is a simple example of the use of <strong>constexpr<\/strong> usage:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(0, 0, 0, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"\/\/\n\/\/  main.cpp\n\/\/  const, volatile, mutable\n\/\/\n\/\/  Created by Bryan Higgs on 2\/10\/25.\n\/\/\n\n#include &lt;iostream&gt;\n\nconstexpr int size = 5;\nint arr[size]; \/\/ Valid, size is known at compile time\n\nconstexpr int square(int x)\n{\n  return x * x;\n}\n\nint main(int argc, const char * argv[])\n{\n  constexpr int result = square(size); \/\/ evaluated at compile time\n  std::cout &lt;&lt; &quot;The square of &quot; &lt;&lt; size &lt;&lt; &quot; is &quot; &lt;&lt; result &lt;&lt; std::endl;\n\n  int num = 10;\n  int runtime_result = square(num); \/\/ evaluated at runtime\n  std::cout &lt;&lt; &quot;The square of &quot; &lt;&lt; num &lt;&lt; &quot; is &quot; &lt;&lt; runtime_result &lt;&lt; std::endl;\n  \n  return 0;\n}\n\" style=\"color:#000000;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki light-plus\" style=\"background-color: #FFFFFF\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  main.cpp<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  const, volatile, mutable<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Created by Bryan Higgs on 2\/10\/25.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">#<\/span><span style=\"color: #001080\">include<\/span><span style=\"color: #000000\"> &lt;<\/span><span style=\"color: #001080\">iostream<\/span><span style=\"color: #000000\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #001080\">constexpr<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">size<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #098658\">5<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">arr<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #001080\">size<\/span><span style=\"color: #000000\">]; <\/span><span style=\"color: #008000\">\/\/ Valid, size is known at compile time<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #001080\">constexpr<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">square<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">x<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">x<\/span><span style=\"color: #000000\"> * <\/span><span style=\"color: #001080\">x<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">main<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">argc<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #001080\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">char<\/span><span style=\"color: #000000\"> * <\/span><span style=\"color: #001080\">argv<\/span><span style=\"color: #000000\">[])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">constexpr<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">result<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #795E26\">square<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">size<\/span><span style=\"color: #000000\">); <\/span><span style=\"color: #008000\">\/\/ evaluated at compile time<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  std::<\/span><span style=\"color: #001080\">cout<\/span><span style=\"color: #000000\"> &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;The square of &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; <\/span><span style=\"color: #001080\">size<\/span><span style=\"color: #000000\"> &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; is &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; <\/span><span style=\"color: #001080\">result<\/span><span style=\"color: #000000\"> &lt;&lt; std::<\/span><span style=\"color: #001080\">endl<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">num<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #098658\">10<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">runtime_result<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #795E26\">square<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">num<\/span><span style=\"color: #000000\">); <\/span><span style=\"color: #008000\">\/\/ evaluated at runtime<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  std::<\/span><span style=\"color: #001080\">cout<\/span><span style=\"color: #000000\"> &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;The square of &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; <\/span><span style=\"color: #001080\">num<\/span><span style=\"color: #000000\"> &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; is &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; <\/span><span style=\"color: #001080\">runtime_result<\/span><span style=\"color: #000000\"> &lt;&lt; std::<\/span><span style=\"color: #001080\">endl<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>The program outputs:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The square of 5 is 25\nThe square of 10 is 100\nProgram ended with exit code: 0<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"constexpr_Example_with_a_Class\"><\/span>constexpr Example with a Class<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>Here&#8217;s an example of <strong>constexpr<\/strong> used with a class:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(0, 0, 0, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"\/\/\n\/\/  main.cpp\n\/\/  const, volatile, mutable\n\/\/\n\/\/  Created by Bryan Higgs on 2\/10\/25.\n\/\/\n\n#include &lt;iostream&gt;\n\n\/\/ 3. constexpr with class\nclass Rectangle {\npublic:\n    constexpr Rectangle(int w, int h) : width(w), height(h) {}\n    constexpr int area() const { return width * height; }\nprivate:\n    int width;\n    int height;\n};\n\nint main(int argc, const char * argv[])\n{\n    constexpr Rectangle rect(5, 10);\n    constexpr int rect_area = rect.area(); \/\/ evaluated at compile time\n    std::cout &lt;&lt; &quot;The area of the rectangle is: &quot; &lt;&lt; rect_area &lt;&lt; std::endl;\n    \n    return 0;\n}\" style=\"color:#000000;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki light-plus\" style=\"background-color: #FFFFFF\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  main.cpp<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  const, volatile, mutable<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Created by Bryan Higgs on 2\/10\/25.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">#<\/span><span style=\"color: #001080\">include<\/span><span style=\"color: #000000\"> &lt;<\/span><span style=\"color: #001080\">iostream<\/span><span style=\"color: #000000\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #008000\">\/\/ 3. constexpr with class<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #0000FF\">class<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Rectangle<\/span><span style=\"color: #000000\"> {<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #001080\">public<\/span><span style=\"color: #000000\">:<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">    <\/span><span style=\"color: #267F99\">constexpr<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Rectangle<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #267F99\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">w<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #267F99\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">h<\/span><span style=\"color: #000000\">) : <\/span><span style=\"color: #267F99\">width<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #267F99\">w<\/span><span style=\"color: #000000\">), <\/span><span style=\"color: #795E26\">height<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">h<\/span><span style=\"color: #000000\">) {}<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">constexpr<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">area<\/span><span style=\"color: #000000\">() const { <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">width<\/span><span style=\"color: #000000\"> * <\/span><span style=\"color: #001080\">height<\/span><span style=\"color: #000000\">; }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #001080\">private<\/span><span style=\"color: #000000\">:<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">    <\/span><span style=\"color: #267F99\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">width<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">height<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">main<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">argc<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #001080\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">char<\/span><span style=\"color: #000000\"> * <\/span><span style=\"color: #001080\">argv<\/span><span style=\"color: #000000\">[])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">constexpr<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">Rectangle<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">rect<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">5<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">10<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">constexpr<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">rect_area<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #001080\">rect<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">area<\/span><span style=\"color: #000000\">(); <\/span><span style=\"color: #008000\">\/\/ evaluated at compile time<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    std::<\/span><span style=\"color: #001080\">cout<\/span><span style=\"color: #000000\"> &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;The area of the rectangle is: &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; <\/span><span style=\"color: #001080\">rect_area<\/span><span style=\"color: #000000\"> &lt;&lt; std::<\/span><span style=\"color: #001080\">endl<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This program outputs:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The area of the rectangle is: 50\nProgram ended with exit code: 0<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"constexpr_Example_to_Calculate_the_Size_of_an_Array_at_Compile_Time\"><\/span>constexpr Example to Calculate the Size of an Array at Compile Time<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:75%\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(0, 0, 0, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"\/\/\n\/\/  main.cpp\n\/\/  const, volatile, mutable\n\/\/\n\/\/  Created by Bryan Higgs on 2\/10\/25.\n\/\/\n\n#include &lt;iostream&gt;\n\nconstexpr int product(int x, int y) { return (x * y); }\n\nint main(int argc, const char * argv[])\n{\n  int arr[product(2, 3)] = {1, 2, 3, 4, 5, 6};\n  std::cout &lt;&lt; &quot;Size of arr: = &quot; \n            &lt;&lt; sizeof(arr)\/sizeof(arr[0]) &lt;&lt; std::endl;\n  \n  return 0;\n}\" style=\"color:#000000;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki light-plus\" style=\"background-color: #FFFFFF\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  main.cpp<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  const, volatile, mutable<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Created by Bryan Higgs on 2\/10\/25.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">#<\/span><span style=\"color: #001080\">include<\/span><span style=\"color: #000000\"> &lt;<\/span><span style=\"color: #001080\">iostream<\/span><span style=\"color: #000000\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #001080\">constexpr<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">product<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">x<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">y<\/span><span style=\"color: #000000\">) { <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> (<\/span><span style=\"color: #001080\">x<\/span><span style=\"color: #000000\"> * <\/span><span style=\"color: #001080\">y<\/span><span style=\"color: #000000\">); }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">main<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">argc<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #001080\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">char<\/span><span style=\"color: #000000\"> * <\/span><span style=\"color: #001080\">argv<\/span><span style=\"color: #000000\">[])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">arr<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #795E26\">product<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">2<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">)] = {<\/span><span style=\"color: #098658\">1<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">2<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">5<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">6<\/span><span style=\"color: #000000\">};<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  std::<\/span><span style=\"color: #001080\">cout<\/span><span style=\"color: #000000\"> &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Size of arr: = &quot;<\/span><span style=\"color: #000000\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            &lt;&lt; <\/span><span style=\"color: #795E26\">sizeof<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">arr<\/span><span style=\"color: #000000\">)\/<\/span><span style=\"color: #795E26\">sizeof<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">arr<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">]) &lt;&lt; std::<\/span><span style=\"color: #001080\">endl<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span><\/code><\/pre><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:10%\"><\/div>\n<\/div>\n\n\n\n<p>This program outputs:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Size of arr: = 6\nProgram ended with exit code: 0<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"constexpr_Example_to_Convert_from_One_Unit_to_Another\"><\/span>constexpr Example to Convert from One Unit to Another<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:75%\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(0, 0, 0, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"\/\/\n\/\/  main.cpp\n\/\/  const, volatile, mutable\n\/\/\n\/\/  Created by Bryan Higgs on 2\/10\/25.\n\/\/\n\n#include &lt;iostream&gt;\n#include &lt;cmath&gt; \/\/ For standard declaration of pi (M_PI)\n\nconstexpr double ConvertDegreeToRadian(const double&amp; degrees)\n{\n  return (degrees * (M_PI \/ 180));\n}\n\nint main(int argc, const char * argv[])\n{\n  double angleInRadians = ConvertDegreeToRadian(90.0);\n  std::cout &lt;&lt; &quot;Angle in radians: &quot; &lt;&lt; angleInRadians &lt;&lt; std::endl;\n    \n  return 0;\n}\" style=\"color:#000000;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki light-plus\" style=\"background-color: #FFFFFF\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  main.cpp<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  const, volatile, mutable<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Created by Bryan Higgs on 2\/10\/25.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">#<\/span><span style=\"color: #001080\">include<\/span><span style=\"color: #000000\"> &lt;<\/span><span style=\"color: #001080\">iostream<\/span><span style=\"color: #000000\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">#<\/span><span style=\"color: #001080\">include<\/span><span style=\"color: #000000\"> &lt;<\/span><span style=\"color: #001080\">cmath<\/span><span style=\"color: #000000\">&gt; <\/span><span style=\"color: #008000\">\/\/ For standard declaration of pi (M_PI)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #001080\">constexpr<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">double<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">ConvertDegreeToRadian<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">double<\/span><span style=\"color: #000000\">&amp; <\/span><span style=\"color: #001080\">degrees<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> (<\/span><span style=\"color: #001080\">degrees<\/span><span style=\"color: #000000\"> * (<\/span><span style=\"color: #0070C1\">M_PI<\/span><span style=\"color: #000000\"> \/ <\/span><span style=\"color: #098658\">180<\/span><span style=\"color: #000000\">));<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">main<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">argc<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #001080\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">char<\/span><span style=\"color: #000000\"> * <\/span><span style=\"color: #001080\">argv<\/span><span style=\"color: #000000\">[])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">double<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">angleInRadians<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #795E26\">ConvertDegreeToRadian<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">90.0<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  std::<\/span><span style=\"color: #001080\">cout<\/span><span style=\"color: #000000\"> &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Angle in radians: &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; <\/span><span style=\"color: #001080\">angleInRadians<\/span><span style=\"color: #000000\"> &lt;&lt; std::<\/span><span style=\"color: #001080\">endl<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span><\/code><\/pre><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:10%\"><\/div>\n<\/div>\n\n\n\n<p>which outputs:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Angle in radians: 1.5708\nProgram ended with exit code: 0<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" style=\"padding-top:0;padding-bottom:var(--wp--preset--spacing--50)\"><span class=\"ez-toc-section\" id=\"constexpr_Example_to_Calculate_a_Value_in_the_Fibonacci_Sequence\"><\/span>constexpr Example to Calculate a Value in the Fibonacci Sequence<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"has-text-align-center\"><strong>The Fibonacci Sequence<\/strong><\/p>\n\n\n\n<p style=\"margin-bottom:5px\">In mathematics, the <strong>Fibonacci sequence<\/strong> is a sequence in which each element is the sum of the two elements that precede it. Numbers that are part of the Fibonacci sequence are known as <strong>Fibonacci numbers<\/strong>, commonly denoted <em>F<sub>n<\/sub><\/em>\u200a.<\/p>\n\n\n\n<p>The Fibonacci numbers may be defined by the <em>recurrence relation<\/em>:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/wikimedia.org\/api\/rest_v1\/media\/math\/render\/svg\/3c667d91153450b3a161371582ee8227af85951f\" alt=\"{\\displaystyle F_{0}=0,\\quad F_{1}=1,}\"\/><\/figure>\n\n\n\n<p style=\"padding-top:var(--wp--preset--spacing--40)\">and<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/wikimedia.org\/api\/rest_v1\/media\/math\/render\/svg\/4fa6d281e7a54e08aeffeef7458ddc0884333686\" alt=\"{\\displaystyle F_{n}=F_{n-1}+F_{n-2}}\"\/><\/figure>\n\n\n\n<p style=\"padding-top:var(--wp--preset--spacing--40)\">for <em>n &gt; 1.<\/em><\/p>\n<\/blockquote>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:75%\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(0, 0, 0, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"\/\/\n\/\/  main.cpp\n\/\/  const, volatile, mutable\n\/\/\n\/\/  Created by Bryan Higgs on 2\/10\/25.\n\/\/\n\n#include &lt;iostream&gt;\n\nconstexpr int fibonacci(int n) \n{\n  return (n &lt;= 1) ? n : fibonacci(n-1) + fibonacci(n-2);\n}\n\nint main(int argc, const char * argv[])\n{\n  constexpr int result = fibonacci(10);\n  std::cout &lt;&lt; &quot;Fibonacci(10) = &quot; &lt;&lt; result &lt;&lt; std::endl;\n\n  return 0;\n}\" style=\"color:#000000;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki light-plus\" style=\"background-color: #FFFFFF\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  main.cpp<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  const, volatile, mutable<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Created by Bryan Higgs on 2\/10\/25.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">#<\/span><span style=\"color: #001080\">include<\/span><span style=\"color: #000000\"> &lt;<\/span><span style=\"color: #001080\">iostream<\/span><span style=\"color: #000000\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #001080\">constexpr<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">fibonacci<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">n<\/span><span style=\"color: #000000\">) <\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> (<\/span><span style=\"color: #001080\">n<\/span><span style=\"color: #000000\"> &lt;= <\/span><span style=\"color: #098658\">1<\/span><span style=\"color: #000000\">) ? <\/span><span style=\"color: #001080\">n<\/span><span style=\"color: #000000\"> : <\/span><span style=\"color: #795E26\">fibonacci<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">n<\/span><span style=\"color: #000000\">-<\/span><span style=\"color: #098658\">1<\/span><span style=\"color: #000000\">) + <\/span><span style=\"color: #795E26\">fibonacci<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">n<\/span><span style=\"color: #000000\">-<\/span><span style=\"color: #098658\">2<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">main<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">argc<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #001080\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">char<\/span><span style=\"color: #000000\"> * <\/span><span style=\"color: #001080\">argv<\/span><span style=\"color: #000000\">[])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">constexpr<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">result<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #795E26\">fibonacci<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">10<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  std::<\/span><span style=\"color: #001080\">cout<\/span><span style=\"color: #000000\"> &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Fibonacci(10) = &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; <\/span><span style=\"color: #001080\">result<\/span><span style=\"color: #000000\"> &lt;&lt; std::<\/span><span style=\"color: #001080\">endl<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span><\/code><\/pre><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:10%\"><\/div>\n<\/div>\n\n\n\n<p>which outputs:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Fibonacci(10) = 55\nProgram ended with exit code: 0<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>NOTE:<\/strong> There is a limit (specific to each C++ compiler) to the evaluation of constexpr compile-time expressions. In the above case, the expression at line 17 is a call to a <em>recursive function<\/em>. It succeeds for a value of 10 (in my compiler), but if I change the value to 30, I get the following:<\/p>\n\n\n\n<p><strong>Constexpr variable &#8216;result&#8217; must be initialized by a constant expression<br>Constexpr evaluation hit maximum step limit; possible infinite loop?<\/strong><\/p>\n\n\n\n<p>Some compilers may crash instead of emitting such a compile-time error.<\/p>\n\n\n\n<p><\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"consteval_and_constinit_Specifiers_since_C20\"><\/span>consteval and constinit Specifiers (since C++20)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"consteval_Specifier\"><\/span>consteval Specifier<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>The <strong>consteval<\/strong> specifier declares a function that must be evaluated at compile time. Any call to a <strong>consteval<\/strong> function must occur in a context where a constant expression is required.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:75%\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(0, 0, 0, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"\/\/\n\/\/  main.cpp\n\/\/  const, volatile, mutable\n\/\/\n\/\/  Created by Bryan Higgs on 2\/10\/25.\n\/\/\n\nconsteval int multiply(int x, int y) \n{\n  return x * y;\n}\n\nint main(int argc, const char * argv[])\n{\n  constexpr int result1 = multiply(5, 3); \/\/ OK: evaluated at compile time\n  static_assert(result1 == 15);\n\n  int a = 5;\n  int result2 = multiply(a, 3); \/\/ Call to consteval function 'multiply' is not a constant expression\n                                \/\/ Read of non-const variable 'a' is not allowed in a constant expression\n  return 0;\n}\" style=\"color:#000000;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki light-plus\" style=\"background-color: #FFFFFF\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  main.cpp<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  const, volatile, mutable<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Created by Bryan Higgs on 2\/10\/25.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #001080\">consteval<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">multiply<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">x<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">y<\/span><span style=\"color: #000000\">) <\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">x<\/span><span style=\"color: #000000\"> * <\/span><span style=\"color: #001080\">y<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">main<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">argc<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #001080\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">char<\/span><span style=\"color: #000000\"> * <\/span><span style=\"color: #001080\">argv<\/span><span style=\"color: #000000\">[])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">constexpr<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">result1<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #795E26\">multiply<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">5<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">); <\/span><span style=\"color: #008000\">\/\/ OK: evaluated at compile time<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">static_assert<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">result1<\/span><span style=\"color: #000000\"> == <\/span><span style=\"color: #098658\">15<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">a<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #098658\">5<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">result2<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #795E26\">multiply<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">a<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">); <\/span><span style=\"color: #008000\">\/\/ Call to consteval function &#39;multiply&#39; is not a constant expression<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                                <\/span><span style=\"color: #008000\">\/\/ Read of non-const variable &#39;a&#39; is not allowed in a constant expression<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span><\/code><\/pre><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:10%\"><\/div>\n<\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"constinit_Specifier\"><\/span>constinit Specifier<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>The <strong>constinit<\/strong> specifier ensures that a variable with static or thread storage duration is initialized at compile time. It guarantees that the initialization is either zero initialization or constant initialization.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"has-text-align-center\"><strong>In C++ Formal Language<\/strong><\/p>\n\n\n\n<p>If a variable is declared with <strong>constinit<\/strong>, its initializing declaration must be applied with <strong>constinit<\/strong>. If a variable declared with <strong>constinit<\/strong> has <em>dynamic initialization<\/em> (even if it is performed as <em>static initialization<\/em>), the program is ill-formed.<\/p>\n\n\n\n<p>If no <strong>constinit<\/strong> declaration is reachable at the point of the initializing declaration, the program is ill-formed, no diagnostic required.<\/p>\n\n\n\n<p><strong>constinit<\/strong> cannot be used together with <strong>constexpr<\/strong>. When the declared variable is a reference, <strong>constinit<\/strong> is equivalent to <strong>constexpr<\/strong>. When the declared variable is an object, <strong>constexpr<\/strong> mandates that the object must have static initialization and constant destruction and makes the object <em>const-qualified<\/em>, however, <strong>constinit<\/strong> does not mandate constant destruction and <em>const-qualification<\/em>. As a result, an object of a type which has <strong>constexpr<\/strong> constructors and no <strong>constexpr<\/strong> destructor (e.g. <strong>std::shared_ptr&lt;T&gt;<\/strong>) might be declared with <strong>constinit<\/strong> but not <strong>constexpr<\/strong>.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><strong>Got that?<\/strong><\/p>\n<\/blockquote>\n\n\n\n<p>The <strong>constinit<\/strong> specifier is used to mark variables that must be initialized with compile-time constant expressions or constant-initialized constructors and it also ensures that the initialization will be done during the static initialization phase. It prevents the variables with static storage duration to be initialized at runtime. The variables specified with <strong>constinit<\/strong> specifier need to be initialized with a constant expression.<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:75%\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(0, 0, 0, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"\/\/\n\/\/  main.cpp\n\/\/  const, volatile, mutable\n\/\/\n\/\/  Created by Bryan Higgs on 2\/10\/25.\n\/\/\n\nconsteval int get_value() \n{\n  return 42; \/\/ The &quot;answer&quot;\n}\n\nconstinit int value1 = get_value(); \/\/ OK: Initialized at compile time\nconstexpr int value2 = 100;\nconstinit int value3 = value2; \/\/ OK: Initialized at compile time using constexpr\nconstinit constexpr int value4 = value2; \/\/ Cannot combine with previous 'constinit' declaration specifier\n\n\nint main(int argc, const char * argv[])\n{\n  static constinit int value5 = 123; \/\/ OK: static storage duration\n  \n  return 0;\n}\" style=\"color:#000000;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki light-plus\" style=\"background-color: #FFFFFF\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  main.cpp<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  const, volatile, mutable<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Created by Bryan Higgs on 2\/10\/25.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #001080\">consteval<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">get_value<\/span><span style=\"color: #000000\">() <\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #098658\">42<\/span><span style=\"color: #000000\">; <\/span><span style=\"color: #008000\">\/\/ The &quot;answer&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #001080\">constinit<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">value1<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #795E26\">get_value<\/span><span style=\"color: #000000\">(); <\/span><span style=\"color: #008000\">\/\/ OK: Initialized at compile time<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #001080\">constexpr<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">value2<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #098658\">100<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #001080\">constinit<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">value3<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #001080\">value2<\/span><span style=\"color: #000000\">; <\/span><span style=\"color: #008000\">\/\/ OK: Initialized at compile time using constexpr<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #001080\">constinit<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">constexpr<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">value4<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #001080\">value2<\/span><span style=\"color: #000000\">; <\/span><span style=\"color: #008000\">\/\/ Cannot combine with previous &#39;constinit&#39; declaration specifier<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">main<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">argc<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #001080\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">char<\/span><span style=\"color: #000000\"> * <\/span><span style=\"color: #001080\">argv<\/span><span style=\"color: #000000\">[])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">static<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">constinit<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">value5<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #098658\">123<\/span><span style=\"color: #000000\">; <\/span><span style=\"color: #008000\">\/\/ OK: static storage duration<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span><\/code><\/pre><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:10%\"><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>const, volatile, mutable, and More In C++, const, volatile, and mutable are type qualifiers that modify the behavior of variables. const const specifies that a variable&#8217;s value cannot be changed after initialization. Any attempt to modify a const variable will result in a compile-time error. volatile volatile indicates that a variable&#8217;s value can be changed [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":910,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2258","page","type-page","status-publish","hentry"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/pages\/2258","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/comments?post=2258"}],"version-history":[{"count":16,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/pages\/2258\/revisions"}],"predecessor-version":[{"id":2369,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/pages\/2258\/revisions\/2369"}],"up":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/pages\/910"}],"wp:attachment":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/media?parent=2258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}