why is this not giving error when I compile?
#include using namespace std; int main() { int *a = new int[2]; // int a[2]; // even t
Because undefined behavior == anything can happen. You're unlucky that it doesn't crash, this sort of behavior can potentially hide bugs.
As for a being define twice - that's a bug in the compiler.
a