Hi
Why isn't assignment to global variables allowed?
ThanksCode:int t;
t = 9; // error C2086: 'int t' : redefinition
int main()
{
return 0;
}
Printable View
Hi
Why isn't assignment to global variables allowed?
ThanksCode:int t;
t = 9; // error C2086: 'int t' : redefinition
int main()
{
return 0;
}
Because executable statements have to be inside functions. Either:Quote:
Originally Posted by sawer
orCode:int t = 9; // declaration and definition
int main()
{
}
Code:int t; // declaration - initialised to 0 by default
int main()
{
t = 9; // assignment (executable statement, must be in a function)
}
1, missing type specifier - int assumed. Note: C++ does not support default-int
2, 'int t' : redefinition
Becasue the "int assumed",so the compile think that is redefinition!
Huh? :confused:Quote:
Originally Posted by active2volcano
You used to be able to leave out the type name in C and the compiler would assume you mean int:Quote:
Huh?
Code:f(n)
{
return n;
}