tags:

views:

65

answers:

1
#include <iostream>
using namespace std;
extern int i;
int main()
{

   i=10;
 cout<<"the value of i is"<<i<<endl;



}
+6  A: 

'extern' tells the compiler that i is defined in another compilation unit. It will not create storage for it but look for it at link time, when you get the error. So either link with a module that has i defined or remove the 'extern' qualifier.

Amardeep
but i defined it inside main. Is that wrong?
lakshman
You don't define it in main, you use it in main.And even if you would define a variable i in main, it would be 2 totally different i's. The "extern int i" can only refer to i as a global variable.
Patrick
No, you are just assigning i with 10, definition says what is i , is it an int or float
yesraaj