<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.omnivision.website/index.php?action=history&amp;feed=atom&amp;title=3.4.3_Scope</id>
	<title>3.4.3 Scope - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.omnivision.website/index.php?action=history&amp;feed=atom&amp;title=3.4.3_Scope"/>
	<link rel="alternate" type="text/html" href="https://wiki.omnivision.website/index.php?title=3.4.3_Scope&amp;action=history"/>
	<updated>2026-08-24T13:25:26Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.9</generator>
	<entry>
		<id>https://wiki.omnivision.website/index.php?title=3.4.3_Scope&amp;diff=125&amp;oldid=prev</id>
		<title>Mr. Goldstein: Created page with &quot;=== 3.4.3 Scope === Imagine you have a secret diary. Only &#039;&#039;you&#039;&#039; can read and write in it. Your friend also has a secret diary, and only &#039;&#039;they&#039;&#039; can read and write in theirs. Your diary is &quot;private&quot; to you, and your friend&#039;s diary is &quot;private&quot; to them. You can&#039;t just open your friend&#039;s diary, even if you know they have one.  In programming, &#039;&#039;&#039;Scope&#039;&#039;&#039; refers to &#039;&#039;&#039;where in your code a variable or function can be accessed or &quot;seen.&quot;&#039;&#039;&#039; It defines the &quot;visibility&quot; and &quot;...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.omnivision.website/index.php?title=3.4.3_Scope&amp;diff=125&amp;oldid=prev"/>
		<updated>2025-07-08T12:32:46Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;=== 3.4.3 Scope === Imagine you have a secret diary. Only &amp;#039;&amp;#039;you&amp;#039;&amp;#039; can read and write in it. Your friend also has a secret diary, and only &amp;#039;&amp;#039;they&amp;#039;&amp;#039; can read and write in theirs. Your diary is &amp;quot;private&amp;quot; to you, and your friend&amp;#039;s diary is &amp;quot;private&amp;quot; to them. You can&amp;#039;t just open your friend&amp;#039;s diary, even if you know they have one.  In programming, &amp;#039;&amp;#039;&amp;#039;Scope&amp;#039;&amp;#039;&amp;#039; refers to &amp;#039;&amp;#039;&amp;#039;where in your code a variable or function can be accessed or &amp;quot;seen.&amp;quot;&amp;#039;&amp;#039;&amp;#039; It defines the &amp;quot;visibility&amp;quot; and &amp;quot;...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;=== 3.4.3 Scope ===&lt;br /&gt;
Imagine you have a secret diary. Only &amp;#039;&amp;#039;you&amp;#039;&amp;#039; can read and write in it. Your friend also has a secret diary, and only &amp;#039;&amp;#039;they&amp;#039;&amp;#039; can read and write in theirs. Your diary is &amp;quot;private&amp;quot; to you, and your friend&amp;#039;s diary is &amp;quot;private&amp;quot; to them. You can&amp;#039;t just open your friend&amp;#039;s diary, even if you know they have one.&lt;br /&gt;
&lt;br /&gt;
In programming, &amp;#039;&amp;#039;&amp;#039;Scope&amp;#039;&amp;#039;&amp;#039; refers to &amp;#039;&amp;#039;&amp;#039;where in your code a variable or function can be accessed or &amp;quot;seen.&amp;quot;&amp;#039;&amp;#039;&amp;#039; It defines the &amp;quot;visibility&amp;quot; and &amp;quot;lifetime&amp;quot; of variables. Just like your diary is only visible to you, a variable&amp;#039;s scope determines which parts of your program can use that variable.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Key Ideas:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Local Scope:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
** Variables declared &amp;#039;&amp;#039;inside&amp;#039;&amp;#039; a function (or a specific block of code) have &amp;#039;&amp;#039;&amp;#039;local scope&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
** This means they can &amp;#039;&amp;#039;&amp;#039;only be used within that function&amp;#039;&amp;#039;&amp;#039; or block. They are &amp;quot;local&amp;quot; to that area.&lt;br /&gt;
** Once the function finishes running, the local variables usually disappear from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;function greet():&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;   message = &amp;quot;Hello!&amp;quot; // &amp;#039;message&amp;#039; has local scope within &amp;#039;greet&amp;#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;   print(message)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;greet()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;// print(message) // ERROR! &amp;#039;message&amp;#039; cannot be seen outside &amp;#039;greet&amp;#039; function&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Global Scope:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
** Variables declared &amp;#039;&amp;#039;outside&amp;#039;&amp;#039; of any function (usually at the very top of your program file) have &amp;#039;&amp;#039;&amp;#039;global scope&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
** This means they can be &amp;#039;&amp;#039;&amp;#039;accessed and changed from anywhere&amp;#039;&amp;#039;&amp;#039; in your program.&lt;br /&gt;
** Global variables stay in memory for the entire time your program is running.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;program_name = &amp;quot;My Awesome App&amp;quot; // &amp;#039;program_name&amp;#039; has global scope&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;function display_name():&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;   print(program_name) // Can access global &amp;#039;program_name&amp;#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;display_name()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;print(program_name) // Can also access global &amp;#039;program_name&amp;#039; here&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Block Scope (in some languages):&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
** Some languages (like Java, C++, and modern JavaScript) also have &amp;#039;&amp;#039;&amp;#039;block scope&amp;#039;&amp;#039;&amp;#039;, meaning variables declared inside if statements, for loops, or other curly {} braces can only be used within those specific blocks.&lt;br /&gt;
&lt;br /&gt;
Understanding scope is important because it helps prevent accidental changes to variables and keeps your code organized. It also helps manage memory, as local variables are cleaned up when their function finishes.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Bibliography:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;GeeksforGeeks - Scope Rules in C&amp;#039;&amp;#039;&amp;#039;: https://www.geeksforgeeks.org/scope-rules-in-c/ (Concepts apply broadly)&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;W3Schools - JavaScript Scope&amp;#039;&amp;#039;&amp;#039;: https://www.w3schools.com/js/js_scope.asp&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Wikipedia - Scope (computer science)&amp;#039;&amp;#039;&amp;#039;: &amp;lt;https://en.wikipedia.org/wiki/Scope_(computer_programming)&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mr. Goldstein</name></author>
	</entry>
</feed>