24. Simple Namespace with Variables

#include <iostream>
using namespace std;

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

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

 

Solution Explanation

  • The namespace Config is predefined.
  • The user simply declares two variables inside it.

     
  • In main(), the variables are accessed as Config::baudRate and Config::threshold.

     

Layman’s Terms

Think of Config like a settings folder. You put baudRate and threshold inside, and the program fetches them from there.

 

Significance for Embedded Developers

This mirrors how embedded firmware often groups constants and configuration values in namespaces for organization and type safety.

Loading...

Input

Expected Output

Baud: 9600, Threshold: 50