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

On Sat, Jan 31, 2009 at 2:34 PM, Saifi Khan <[email protected]>wrote:

>   Hi all:
>
> Here are two C++ programs.
>
> The first one doesn't work, while the second one does.
>
> // --------------------------------
>
> #include <iostream>
>
> int i;
> i = 5;
>
> int main(int argc, char *argv[])
> {
> return 0;
> }
>
> // --------------------------------
>
> On attempting to compile the program above, the following error
> is seen,
> error: expected constructor, destructor, or type conversion
> before '=' token
>
> // --------------------------------
>
> #include <iostream>
>
> int main(int argc, char *argv[])
> {
> int i;
> i = 5;
>
> return 0;
> }
>
> // --------------------------------
>
> Any suggestion as to why it is so ?
>
> thanks
> Saifi.
>  
>


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

Reply via email to