/* Write a program that defines a string and assign some data into it.
Print it out as individual characters, and then again backwards.
Note: you should use pointers. I.e. define a pointer to the beginning
of the string, print out the characters in a loop by incrementing the
pointer, and stop the loop when the pointer points to the last character.
Then go backwards. */
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str = "Sara ";
char *p; //declaring a pointer
p = &str[0]; //points to the beginning of the string
for (int i=0; i<str.length(); i++)
{
cout << *p;
p++; //points to the next memory cell that is the next character
}
cout << endl;
p--;
cout << "Now displaying the characters in reverse order:\n";
for (int i=0; i<str.length(); i++)
{
cout << *p;
p--;
}
cout << endl;
return 0;
}/* Create three separate integer variables and assign some data into them.
Use an array of pointers to reference the three integers and output them
on the screen, together with the address of the variables. */
#include <iostream>
using namespace std;
typedef int* IntPtr;
int main()
{
int number1 = 1, number2 = 2, number3 = 3;
IntPtr p[3];
p[0] = &number1;
p[1] = &number2;
p[2] = &number3;
cout << "Value\tAddress\n----------------\n";
for (int i=0; i<3; i++)
cout << *p << "\t" << p << endl;
return 0;
}الي يعرف للبونتر يشرحلي لاني ماني فاهمته هذا سؤال وحله