int i=5; -> variable declaration and expression. OK with the compiler
outside a function block.

int i; -> variable declaration, no expression. OK with the compiler as well.

i=5; -> statement + expression... not cool outside a function block ->
compiler busts you.

i=5; needs to be inside a func block.

Cheers,

Zubin.

On Sat, Jan 31, 2009 at 6:42 AM, 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.
>  
>


[Non-text portions of this message have been removed]

Reply via email to