Variable Scope in C++
In this video, we are going to see variables in C++ in detail. This is actually a sequel to the last video where we talked about rules for naming a variable. But in this one, we will be looking at scopes of variables in C++. There can be a local variable or a global variable. We will learn how to create them and see their behavior in C++.
Series playlist ▶︎ https://youtube.com/playlist?list=PLt4rWC_3rBbWnDrIv4IeC4Vm7PN1wvrNg
Source Code:
#include <iostream>
using namespace std;
int COUNTRY_OFFERS = 10;
int main(){
int stateOffer = 15;
{
int stateOffer = 17;
int cityOffer = 20;
cout<< "The value of city offer is " << cityOffer << endl;
cout<< "The value of country offer is " << COUNTRY_OFFERS << endl;
cout<< "The value of state offer is " << stateOffer << endl;
}
// cout<< "The value of city offer is " << cityOffer << endl;
/* int number;
number = 15;
cout<< number << endl; */
return 0;
}
0 Comments