how come no re-initialization here (pointers with new)?

Write your question here.
just wondering, whenever i do the following:

1
2
  char *wordArray = new char;
  char *wordArray = new char;


I get an error saying that there is re-initialization.

however whenever i do this:

1
2
3
4
  while{true}
  {
    char *wordArray = new char;
  }


there is no error, can anyone explain to me why?

thanks
Last edited on
You see, you have two wordArray in the same scope. Which wordArray should rest of your program use?
You are experiencing Scoping issues.
1
2
 char *wordArray = new char;
 char *wordArray = new char;  // You tried re-declaring the pointer WordArray  


1
2
3
4
  while{true} // this line should not compile though !, it should be while(true)
  { // start a new scope, so this declaration hides the one in main scope
    char *wordArray = new char;
  }
Topic archived. No new replies allowed.