What is an ‘undeclared identifier’ error and how do I fix it?

They most often come from forgetting to include the header file that contains the function declaration, for example, this program will give an ‘undeclared identifier’ error: Missing header int main() { std::cout << “Hello world!” << std::endl; return 0; } To fix it, we must include the header: #include <iostream> int main() { std::cout << … Read more

Java: define terms initialization, declaration and assignment

assignment: throwing away the old value of a variable and replacing it with a new one initialization: it’s a special kind of assignment: the first. Before initialization objects have null value and primitive types have default values such as 0 or false. Can be done in conjunction with declaration. declaration: a declaration states the type … Read more

Why is volatile needed in C?

volatile tells the compiler not to optimize anything that has to do with the volatile variable. There are at least three common reasons to use it, all involving situations where the value of the variable can change without action from the visible code: When you interface with hardware that changes the value itself; when there’s … Read more

Define a global variable in a JavaScript function

As the others have said, you can use var at global scope (outside of all functions and modules) to declare a global variable: <script> var yourGlobalVariable; function foo() { // … } </script> (Note that that’s only true at global scope. If that code were in a module — <script type=”module”>…</script> — it wouldn’t be at global … Read more