6-Scope Operator

6-Scope Operator - cout << "Local variable:...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// Scope operator :: #include <iostream> using namespace std; int variable = 22; int globalVar = 23; //int variable = 134; int main (void) { int variable = 5; // The scope operator can be used cout << "Local variable: " << variable << "\tGlobal variable: " << ::variable << "\tAnother Global: " << globalVar << "\tSame Global: " << ::globalVar << endl; // Without the scope operator the global variable // would have been hidden by the local variable { // another lower scope int variable = 99;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cout << "Local variable: " << variable << "\tGlobal variable: " << ::variable << endl; } // essentially, every pair of braces is a scope cout << "Local variable: " << variable << "\tGlobal variable: " << ::variable << endl; return 0; } /* Local variable: 5 Global variable: 22 Another Global: 23 Same Glo bal: 23 Local variable: 99 Global variable: 22 Local variable: 5 Global variable: 22 Press any key to continue . . . */...
View Full Document

This note was uploaded on 10/05/2011 for the course CS 37 taught by Professor Glenncuevas during the Summer '09 term at Irvine Valley College.

Ask a homework question - tutors are online