How to print the value of the i variable inside namespace B?

namespace A{
    int var = 10;
    namespace B{
        int i = 15;
    }
}

a) cout<<A::i;
b) cout<<B::i;
c) cout<<A::B::i;
d) cout<<i;

1 thought on “How to print the value of the i variable inside namespace B?”

  1. c
    Explanation: Here namespace B is nested inside the namespace A. Hence to access the variable i we need to mention through B and A. So it should A::B::i, which means i belongs to namespace B which is defined inside the namespace A.

Leave a Comment