C++ Modify Pointers Last Updated : 05 Dec, 2022 Comments Improve Suggest changes Like Article Like Report Prerequisite: Pointer in C++ Pointers are an essential part of the C++ language. It allows us to store the memory address of a variable. One thing to note here is that if we change the value that a pointer is pointing to, then the value of the original variable also changes. Now, let's check the approach we are going to use. Approach: In the below example, we will first declare and initialize a string variable. Then, we will store the address of the string variable in a pointer. Finally, we will modify the value that the pointer is pointing to and print all the values associated with the program to the screen. Example: C++ // C++ program to demonstrate the // process of modifying a pointer #include <iostream> #include <string> using namespace std; int main() { string website = "ABC"; string* p = &website; cout << "The value of the variable: " << website << "\n"; cout << "The memory address of the variable: " << p << "\n"; cout << "The value that the pointer is pointing to: " << *p << "\n"; *p = "GeeksforGeeks"; cout << "The new value that the pointer is pointing to: " << *p << "\n"; cout << "The memory address of the variable: " << p << "\n"; cout << "The new value of the variable: " << website << "\n"; return 0; } OutputThe value of the variable: ABC The memory address of the variable: 0x7ffef00579f0 The value that the pointer is pointing to: ABC The new value that the pointer is pointing to: GeeksforGeeks The memory address of the variable: 0x7ffef00579f0 The new value of the variable: GeeksforGeeks In the above output, we can see that the value the pointer was pointing to changed from ABC to GeeksforGeeks. Consequently, the value of the website variable also changed from ABC to GeeksforGeeks. And, this doesn't affect the address of the website just changes the value inside it. Comment More infoAdvertise with us Next Article C++ Modify Pointers S sriparnxnw7 Follow Improve Article Tags : Technical Scripter C++ Technical Scripter 2022 cpp-pointer Practice Tags : CPP Similar Reads C++ Pointers A pointer is a variable that stores the address of another variable. Pointers can be used with any data type, including basic types (e.g., int, char), arrays, and even user-defined types like classes and structures.Create PointerA pointer can be declared in the same way as any other variable but wit 8 min read 'this' pointer in C++ In C++, 'this' pointers is a pointer to the current instance of a class. It is used to refer to the object within its own member functions. In this article, we will learn how to use 'this' pointer in C++.Let's take a look at an example:C++#include <iostream> using namespace std; // Class that 5 min read C++ Vector of Pointers Prerequisites Pointers in C++Vectors in C++ Vector of pointers are vectors that can hold multiple pointers. Each pointer within a vector of pointers points to an address storing a value. We can use the vector of pointers to manage values that are not stored in continuous memory. How to Create Vector 6 min read Smart Pointers in C++ In C++, pointers are the variables that stores the memory addresses. They are extensively used in dynamic memory location to store the address of allocated memory. But they bring a lot of issues.Problems with Normal PointersMemory Leaks: This occurs when memory is repeatedly allocated by a program b 4 min read Pointers in Objective-C In Objective-C, Pointers are the variables that hold the memory address of another variable. You must have declared the pointer variable before its use. The size of the pointer depends on the architecture of the system. The pointer variable can be defined as a char, int, float, double, or any other 5 min read void Pointer in C A void pointer is a pointer that has no associated data type with it. A void pointer can hold an address of any type and can be typecasted to any type.Example of Void Pointer in CC// C Program to demonstrate that a void pointer // can hold the address of any type-castable type #include <stdio.h 3 min read Pointer vs Array in C Most of the time, pointer and array accesses can be treated as acting the same, the major exceptions being:  1. the sizeof operator sizeof(array) returns the amount of memory used by all elements in the array sizeof(pointer) only returns the amount of memory used by the pointer variable itself 2. 1 min read Function Pointer in C In C, a function pointer is a type of pointer that stores the address of a function, allowing functions to be passed as arguments and invoked dynamically. It is useful in techniques such as callback functions, event-driven programs, and polymorphism (a concept where a function or operator behaves di 6 min read Pointers vs Array in C++ Arrays and pointers are two derived data types in C++ that have a lot in common. In some cases, we can even use pointers in place of arrays. But even though they are so closely related, they are still different entities. In this article, we will study how the arrays and pointers are different from e 3 min read C++ Pointer Operators Prerequisite: Pointers in C++ A pointer variable is a variable that stores the address of another variable or in other a pointer variable points to the variable whose address is stored inside it. Syntax: int *pointer_name; There are mainly two types of Pointer operators mainly used: Address of opera 2 min read Like