Global vs. Local Variables

Published on: January 22, 2012

Welcome to another Easy Programming tutorial with C++. In this tutorial I answer a request about showing some things regarding local variables and global variables in C++. It is very useful to know when to use both and how they are both used and this program will explain their uses for you.

This tutorial is also a multi-task project for me, I am using Adobe Captivate for the first time as my screen capture software and I think it went pretty well. If you have any insight on Adobe Captivate, feel free to share.

If you have any questions about the program or anything in general relating to beginner C++ Programming, feel free to ask. I hope you enjoy the video and if you have any requests feel free to let me know.

Remember to checkout the Codesnip below to review the C++ code yourself! Feel free to copy the code, but I ask that you please provide credit if you leave the code unchanged when you use it.


//Programmer: Nazmus
//Program:  Global vs. Local Variables

#include <iostream>
#include <string>
using namespace std;

string var = "This is a global variable";
void variable();

int main()
 cout << var << endl;

 string var = "This is a local variable";

 cout << var << endl;

 cout << ::var << endl;



void variable()
 cout << var << endl;