is it good or bad to reuse the variables?

后端 未结 9 2021
灰色年华
灰色年华 2020-12-17 15:03

I wonder if it is good or bad (or does not matter) if I reuse the variable names as much as possible? for example

int main(void){
  //...
  int x=0;

  //..
         


        
9条回答
  •  感情败类
    2020-12-17 15:24

      int x=0;
    
      //..
      x = atoi(char_var);
    
      //..
      int x = 0;
    

    You cannot redeclare x in the same scope. If you are not redeclaring it but using it for different purposes, you are free to do this. But it's a bad practice and should be avoided as it decreases code readability. Also you should find meaningful names for your variables for the same reasons.

提交回复
热议问题