why does the pointer value doesn;t change when I change it in funciton

Explanation of Pointer Value Not Changing in Function in C++

When you pass a pointer to a function in C++, it's passed by value, which means a copy of the pointer is created. When you modify the pointer inside the function, you're modifying the copy, not the original pointer. To modify the original pointer, you need to pass a pointer to the pointer or a reference to the pointer.

  1. Passing the Pointer to a Function: When you pass a pointer to a function, a copy of the pointer is created within the function's scope.

  2. Modifying the Copied Pointer: Any changes made to the pointer inside the function only affect the copied pointer, not the original pointer in the calling function.

  3. Scope of the Pointer: The copied pointer exists within the scope of the function, and any modifications to it are limited to that scope.

  4. Passing a Pointer to the Pointer or a Reference to the Pointer: To modify the original pointer, you can pass a pointer to the pointer or a reference to the pointer, allowing the function to directly modify the original pointer's value.

By understanding how pointers are passed to functions and the concept of passing pointers to pointers or using references to pointers, you can ensure that the original pointer's value can be modified within a function.