saba_tavdgiridze's blog

By saba_tavdgiridze, 10 years ago, In English

Hi ,my solution for this problem is getting MLE .Can you give me any advises how to lessen memory use .

And also i have one question: how can i initialize global variable in main() function that i could use this variable in every other function (like this) :


void foo(void) { cout<<x<<endl; x+=5; } int main() { int x=5; foo(); return 0; }

Of course this program gets Compilation error.
Thanks in advance ^_^ . (sorry for my bad English)

  • Vote: I like it
  • -13
  • Vote: I do not like it

»
10 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Well, you can initialize global variable in main(), but it seems that you can't declare global variable in main function.

int x; // declaration of global variable

void foo(void)
{
   cout<<x<<endl;
   x+=5;
}

int main()
{
    x=5; // initialization of global variable
    foo();
    return 0;
}