Namespaces
Namespaces group names and avoid clashes. Use std:: instead of using namespace std in headers.
Example
#include <iostream>
namespace math { int add(int a, int b) { return a + b; } }
int main() {
std::cout << math::add(2, 3) << "\n";
namespace a = math;
std::cout << a::add(1, 1) << "\n";
return 0;
}Result
5 2
Exercise
Scope operator.
mathadd(1, 2)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.