C++ program to illustrate the use of USING keyword and SCOPE RESOLUTION (::) operator in Namespace

#include <iostream>
using namespace std;
namespace Variables
{
    int i=4;
    float f=-12.456;
    char c='w';
}

int main()
{
   
cout<<endl<<"Using scope resolution operator (::)";
    cout<<endl<<"i="<<Variables::i;
    cout<<endl<<"f="<<Variables::f;
    cout<<endl<<"c="<<Variables::c;

    cout<<endl<<"Using selected members";
    using Variables::i;
    using Variables::f;
    cout<<endl<<"i="<<i;
    cout<<endl<<"f="<<f;
    cout<<endl<<"c can not be accessed directly";

    cout<<endl<<"Using all members:";
    using namespace Variables;
    cout<<endl<<"i="<<i;
    cout<<endl<<"f="<<f;
    cout<<endl<<"c="<<c;

    return 0;
}

No comments:

Post a Comment