35. Using Namespace Directive

#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;
}

Explanation & Logic Summary:

  • The namespace Config is predefined.
  • The using namespace Config; directive brings its members into the local scope.
  • The variables baudRate and threshold can now be accessed directly.

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

Firmware Relevance & Real-World Context:
In firmware projects, namespaces are commonly used to group configuration values (e.g., UART, SPI, GPIO settings).
Using using namespace can reduce verbosity but should be used cautiously in large codebases to avoid name collisions.

 

 

 

 

 

Loading...

Input

Expected Output

Baud: 9600, Threshold: 50