C++ declaring a variable twice -


hello learning declaration of variables in c++.

now please tell me mistake here. why bad declare variable twice?

int fly = 0;  for(int fly = 0; fly < 10; fly++) {     cout << "this kite flying" << fly << endl: } 

these 2 seperate variable because declared in different scope. scope of variable "area" of code in it's visible.

as simple rule of thumb, place curly brackets are, or placed, new scope. fly inside loop, overrides other fly variable. if wasn't declared, or declared under different name. original variable still accessible.


Comments

Popular posts from this blog

javascript - Add class to another page attribute using URL id - Jquery -

android - MPAndroidChart - How to add Annotations or images to the chart -

IF statement in MySQL trigger -