26. using namespace

#include <iostream>
using namespace std;

namespace Config {
    int baudRate = 9600;
    int threshold = 50;
}

int main() {
    using namespace Config;
    cout << "Baud: " << baudRate 
         << ", Threshold: " << threshold;
    return 0;
}

 

Solution Explanation

  • The namespace Config is predefined.
  • The using namespace Config; directive brings its members into scope.
  • Now baudRate and threshold can be used directly without prefix.
     

Layman’s Terms

It’s like saying: “From now on, I’ll work inside the Config folder, so I don’t have to write the folder name every time.”

 

Significance for Embedded Developers

This makes code shorter when accessing many values from the same namespace (e.g., Config::UART::baudRate, Config::UART::parity).

But in large projects, it can cause conflicts if different modules have variables with the same name.

Loading...

Input

Expected Output

Baud: 9600, Threshold: 50