Cannot assign value to global array in c++

前端 未结 2 1768
栀梦
栀梦 2021-01-15 20:27

I\'ve got this code:

 #include 
    int tabela[1];
    tabela[0] = 1;
    int main(){
        std::cout << tabela[0];
        std::cin.         


        
2条回答
  •  青春惊慌失措
    2021-01-15 21:08

    At the outermost level, a C++ file is a sequence of declarations. tabela[0] = 1; is not a declaration - it's a statement (in particular an expression-statement). A function body, however, is a sequence of statements, so it's fine to put this line inside the body of main (or any other function).

    Some statements are declarations (called declaration-statements), but in general they're not.

提交回复
热议问题