#include <iostream>
using namespace std;
extern int i;
int main()
{
i=10;
cout<<"the value of i is"<<i<<endl;
}
views:
65answers:
1
+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
2010-06-16 14:46:52
but i defined it inside main. Is that wrong?
lakshman
2010-06-16 14:48:18
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
2010-06-16 14:50:20
No, you are just assigning i with 10, definition says what is i , is it an int or float
yesraaj
2010-06-16 14:51:21