Variable Scope and Data Types

#include<iostream>
using namespace std;
int global = 9; //This is Global variable
void sum()
{
    int a;
    cout<<global;
}
int main()
{
    // int a = 14;
    // int b = 15;
    //We can make(Same Name) Local and Global variable of the Same name but
    // the precedence will be given always to Local variable
    int global = 10;    //This is Local Variable
    global = 22;        //This is Local Variable
    int a = 14, b = 15;
    float pi = 3.14;
    char c = 'd';
    bool isCheck = true;
    bool isCheck2 = false;
    cout<<"This is the Tutorial.\nHere the value of a is "<<a<<".\nThe value of b is "<<b;
    cout<<"\nThe value of pi is: "<<pi;
    cout<<"\nThe value of c is: "<<c<<"\n";
    sum();
    cout<<"\n"<<global<<"\n";
    cout<<isCheck<<"\n";
    cout<<isCheck2;
    return 0;
}
//OUTPUT:
//This is the Tutorial.
// Here the value of a is 14.
// The value of b is 15
// The value of pi is: 3.14
// The value of c is: d
// 9
// 22
// 1
// 0

Comments

Popular posts from this blog

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

Basic Input/Output & More in C++