Reputation: 99
I have a global variable, i want to use it in my function without parameter. Example:
void main(){
int a[100];
earray();
}
void earray(){
//i want to use a[] here.
}
Upvotes: 0
Views: 136
Reputation: 837
It's not a global variable (it's local). I assume you're trying to achieve something like the following:
Pass the local value to the function as a parameter (better practice)
For example :
void earray(int array[]){
//array.
}
void main(){
int a[100];
earray(a);
}
Or, as a Global Variable (as you mentioned):
int a[100];
void earray(){
//a.
}
void main(){
earray();
}
Upvotes: 7
Reputation: 44256
That is not a global variabel when you declare it in main. Move it out of main like this:
int a[100]; // Global variable
void main(){
earray();
}
void earray(){
//i want to use a[] here.
}
Upvotes: 1