Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scope hiding in C

Tags:

c

scope

Does C have scope hiding?

For example, if I have a global variable:

int x = 3; 

can I 'declare' inside a function or main 'another' int x?

like image 356
Belgi Avatar asked Jan 17 '23 18:01

Belgi


1 Answers

Yes, that's how C works. For example:

int x;

void my_function(int x){ // this is another x, not the same one
}

void my_function2(){
  int x; //this is also another x
  {
    int x; // this is yet another x
  }
}
int main(){
  char x[5]; // another x, with a different type
}
like image 121
Adiel Mittmann Avatar answered Jan 28 '23 10:01

Adiel Mittmann