12345678910111213141516171819202122232425262728
#include <iostream> using namespace std; namespace Circle { const double pi = 3.14; double r = 100; double Area() { return (r*r*pi); } } namespace Rectangle { double a, b; double Area() { return (a*b); } } Rectangle::a = 20; Rectangle::b = 30; int main() { cout << "Circle: " << Circle::Area() << endl; cout << "Rectangle:" << Rectangle::Area() << endl; return 0; }
1234567891011
int main() { Rectangle::a = 20; Rectangle::b = 30; cout << "Circle: " << Circle::Area() << endl; cout << "Rectangle:" << Rectangle::Area() << endl; return 0; }
12345678910111213141516
#include <iostream> using namespace std; int x = 10; //declaration and initialization int y; //declaration y = 20; //assignment NOT ALLOWED here int main() { cout << "x:" << x << endl; cout << "y:" << y << endl; return 0; }
error: 'y' does not name a type