It's perfectly legal to "hide" the declaration of an object, with another declaration in tighter scope. Within your main function, a will refer to the local variable. Outside the main function, a will refer to the global variable.
As to whether it's "ok" - I would say "no". It's a bad idea, in that it's likely to make your code confusing, and more prone to accidentally introducing bugs. I wouldn't advise doing it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…