1

I have this in my Code, but if i run this part is ignored. This is not part of an function its just there, and if I delete this brackets the code doesnt work. Why are there these brackets ?

bool result = 0;
unsigned int n_comparisons = 0;
{ // what are they for ?
for(int i = 0; i < len; i++)
  array[i] = i;
 bool result = search<float>(array, len, len/2, n_comparisons); 
 }// what are they for ?

Sorry for my bad English.

kirekhar
  • 33
  • 1
  • 6
  • "and if I delete this brackets the code doesnt work". The code won't *compile* if you delete them, since in that case variable `result` would end up being declared twice in the same scope. But it actually appears that the second declaration is an error in any case. It is not possible to say without understanding the full intent. – AnT stands with Russia Feb 03 '17 at 22:28

1 Answers1

2

They identify a local scope. For example the bool you have listed only exists inside this scope:

{
    bool result = ...
}
cout << result; // Error! no such variable. 

Read more about scope here.

Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175