29. Nested Namespace Declaration

#include <iostream>
using namespace std;

namespace Config {
    namespace ADC { int resolution = 12; }
    namespace PWM { int frequency = 1000; }
}

int main() {
    cout << "ADC.resolution=" << Config::ADC::resolution << "\n";
    cout << "PWM.frequency=" << Config::PWM::frequency << "\n";
    return 0;
}

 

Solution Explanation

  • The nested namespaces are already provided.
  • The learner just accesses them using Config::ADC::resolution and Config::PWM::frequency.
     

Layman’s Terms

It’s like we already made two subfolders inside Config — one for ADC, one for PWM. You just need to open them and read what’s inside.

 

Significance for Embedded Developers

This is very common in firmware projects:

  • Config::ADC might store ADC resolution settings.
  • Config::PWM might store PWM frequency values.

It’s a neat way to organize subsystem-specific parameters.

 

Loading...

Input

Expected Output

ADC.resolution=12 PWM.frequency=1000