Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


What is the difference between local and global scope in c++

Posted on 2009-02-17
Medium Priority
Last Modified: 2013-12-14

What is the difference between local and global scope?
Please provide an example if possible, only a beginner so simple english would be good

Many Thanks
Question by:AA321
  • 2
LVL 86

Accepted Solution

jkr earned 2000 total points
ID: 23662831
'Local scope' basically means local to the function a symbol has been declared in, 'global scope' means global to the file a symbol has been declared in. As a simple example:
#include <iostream>
usinf namespace std;
int global = 23;  // global to this file
int main () {
  int local = 42; // local to 'main()'
  cout << "Global: " << global << " Local: " << local << endl;
  return 0;

Open in new window

LVL 86

Assisted Solution

jkr earned 2000 total points
ID: 23662841

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question