Find First Free Position in Array in $O(\log n)$ Time Complexity

  • Context:
  • Thread starter Thread starter mathmari
  • Start date Start date
  • Tags Tags
    Position
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
36 replies · 7K views
mathmari said:
Should I declare [m]starsystem[/m] outside the if?? (Wondering)

The would help yes.
The life time of an object ends when we get to the matching closing brace. (Nerd)
 
Physics news on Phys.org
I like Serena said:
The life time of an object ends when we get to the matching closing brace. (Nerd)

What do you mean?? (Wondering)
 
I like Serena said:
When you have:
Code:
void function()
{
  int a = 2;
  {
    int a = 3;
    printf("%d\n", a);
  }
  printf("%d\n", a);
}
what do you think gets printed? (Wondering)

It will print:

3
2

right?? (Wondering)
 
mathmari said:
It will print:

3
2

right?? (Wondering)

Yep. (Nod)

When "int a = 3" is declared, local stack memory is allocated for it.
Furthermore it "hides" the "a" that was declared earlier.
When the closing brace comes by, the local stack memory is automatically released.
Afterwards, the original "a" becomes visible again. (Nerd)
 
I like Serena said:
Yep. (Nod)

When "int a = 3" is declared, local stack memory is allocated for it.
Furthermore it "hides" the "a" that was declared earlier.
When the closing brace comes by, the local stack memory is automatically released.
Afterwards, the original "a" becomes visible again. (Nerd)

Ahaa... Ok! (Muscle)I have also an other question...

When I declare 'starsystem', before the if statement, do I write it as followed??

[m] starsy_t *starsystem;[/m]

Or should I set it equal to [m]NULL[/m] ??

(Wondering)
 
mathmari said:
Ahaa... Ok! (Muscle)I have also an other question...

When I declare 'starsystem', before the if statement, do I write it as followed??

[m] starsy_t *starsystem;[/m]

Or should I set it equal to [m]NULL[/m] ??

(Wondering)

It is good practice to always set a pointer to NULL if you're not setting it to any other specific value. (Smirk)