On Sat, Jan 31, 2009 at 5:12 PM, Saifi Khan <[email protected]>wrote:
> On Sat, 31 Jan 2009, chiluveru snehith wrote:
>
> > in Cu can declare a variable outside but u should extern key word
> > before it"extern
> > int i;"
> > u can't intilize the the variable outsideas i=5; this is wrong
> > if u want intilize it make it as static
> > "static int i=5;"
> > in C++
> > u cant declare variables outside outside ,if u want to declare use extern
> > key word
> > otherwise declare it in one class the class as default constructor in it
> > it will automatically initilize the variable inside the class
> >
>
> How does this piece of code work then ?
>
> // ------------------------------
>
> #include <iostream>
>
> int i = 5;
>
> int main(int argc, char *argv[])
> {
> return 0;
> }
>
> // ------------------------------
>
> thanks
> Saifi.
>
>
In the first piece of code you get an error because *you cannot have
assignments on global scope*, only initialisation.
In the second piece of code i is declared in main and then assignment is done
so that's fine......
-Mukund.