Variable Scope & Data Types in C++

 #include<iostream>

using namespace std;

int glo = 6;    //Global Variable
void sum()
{
    int a;
    cout<<glo;
}
int main()
{
    //We can make same name local and global variable but precedence will get local variable
    //local variable will get more importance as compare to global variable
    int glo=9;  //Local Variable
    glo=78;
    // int a = 4;
    // int b = 5;
    int a = 14, b = 15;
    float pi=3.14;
    char c = 'u';
    bool is_true = true;
    bool is_false = false;
    sum();
    cout<<glo<<is_true<<is_false;
    // cout<<"This is tutorial four.\nHere the value of a is "<<a<<"\nThe value of b is "<<b<<"\n";
    // cout<<"The value of pi is : "<<pi;
    // cout<<"\nThe value of c is : "<<c;
    return 0;
}

OUTPUT:
PS D:\C++> cd "d:\C++\" ; if ($?) { g++ tut4.cpp -o tut4 } ; if ($?) { .\tut4 } 67810 PS D:\C++>








Comments

Popular posts from this blog

Control Structures, If Else and Switch Case Statements in C++

Basic Input/Output & More in C++