- Program :
#include <iostream>
#include <string>
using namespace std;
int main(){
cout <<"\n----------------POINTERS----------------\n";
cout <<"\n----------------Modify Pointer Value----------------\n";
string food = "Pizza";
string* ptr = &food;
// Output the value of food
cout << food << "\n";
// Output the memory address of food
cout << &food << "\n";
// Access the memory address of food and output its value
cout << *ptr << "\n";
// Change the value of the pointer
*ptr = "burger";
// Output the new value of the pointer
cout << *ptr << "\n";
// Output the new value of the food variable
cout << food << "\n";
return 0;
}
- Output :
No comments:
Post a Comment