Блог пользователя saba_tavdgiridze

Автор saba_tavdgiridze, 10 лет назад, По-английски

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)

  • Проголосовать: нравится
  • -13
  • Проголосовать: не нравится

»
10 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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;
}