Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>"lexical" means that it is related to the source code.</p> <p>For example, <code>1</code> is a lexical constant. OTOH, <code>sizeof(char)</code> is also a compile-time integral constant expression, but it is not a lexical constant. Lexically, it is an invocation of the <code>sizeof</code> operator.</p> <p>Lexical operators work on the source code. The preprocessor operators fall into this category.</p> <p>In most cases, it makes no difference whether I use <code>1</code> or <code>sizeof(char)</code> anywhere in my program. But, as the argument of the lexical operators <code>#</code> or <code>##</code> it makes a considerable difference, because these work on the actual code and not the result of evaluation:</p> <pre><code>#define STR(x) #x std::string one = STR(1); std::string also_one = STR(sizeof(char)); </code></pre> <p>Finally, lexical scope means the portion of the program source code where are identifier exists (is recognized, can be used). This is in contrast to the dynamic scope, also known as object lifetime, which is the portion of the program where the object exists (maintains its value and may be manipulated indirectly via pointer or reference, even though the name is not in lexical scope).</p> <pre><code>string f(string x) { return "2" + x; } // main's "y" is not in lexical scope, however it is in dynamic scope, and will not be destroyed yet int main(void) { string y = "5.2"; // y enters lexical scope and dynamic scope string z = f("y"); // y leaves lexical scope as f is called, and comes back into lexical scope when f returns return z.size(); // z leaves lexical and dynamic scope, destructor is called } </code></pre>
 

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