Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include <iostream>

using namespace std;

namespace AAA
{
	namespace BBB
	{
		namespace CCC
		{
			int num1, num2;
		}
	}
}

int main()
{
	namespace ABC = AAA::BBB::CCC;
	cout << ABC::num1 << ABC::num2 << endl;
	return 0;
}


What I have tried:

As you see, I didn't initialize variable num1, num2 in namespace AAA::BBB::CCC. In the normal case, It is correct that num1 and num2 should have garbage values, but I have confirmed that both were 0 after compilation. Why?
Posted
Updated 5-Aug-18 23:10pm

1 solution

That has nothing to do with namespaces. In C++ global variables are 0-initialised by default.
 
Share this answer
 
Comments
서형박 9-Aug-18 15:20pm    
oh i see...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900