#include <iostream>
using namespace std;
const int i = 1;
class T
{
public:
char arr[i];
enum{i = 2};
};
int main()
{
T a;
cout << sizeof(a.arr) << endl;
// getchar();
return 0;
}
Because char arr[i] is declared before enum{i = 2}, it will take the value of the global variable i. If enum{i = 2} is declared before char arr[i], the output is 2
Because
char arr[i]
is declared beforeenum{i = 2}
, it will take the value of the global variablei
. Ifenum{i = 2}
is declared beforechar arr[i]
, the output is 2