Pointers for strings
#include<iostream>
using namespace std;
void main()
{
char arr1[15]={"HAPPY BIRTHDAY"};
char *arr2[]={"HELLO","WORLD"};//two dimensional array
char *arrptr1;//declaring character
int i,j;
arrptr1=arr1;//pointer to arr1
cout<<"\nPrinting first array using pointer notation: ";
for(i=0;i<=14;i++)
{
cout<<*(arrptr1+i);
}
cout<<"\nPrinting first array using array notation: ";
for(i=0;i<=14;i++)
{
cout<<arr1[i];
}
cout<<"\nPrinting second string using pointer notation: ";
for(i=0;i<=1;i++)
{
cout<<*(arr2+i)<<" ";
}
cout<<"\nPrinting second string using array notation: ";
for(i=0;i<=1;i++)
{
cout<<arr2[i]<<" ";
}
cout<<"\nPrinting second array using 2D array notation: ";
for(i=0;i<=1;i++)
{
for(j=0;j<=5;j++)
{
cout<<arr2[i][j];
}
}
cout<<endl;
}
EmoticonEmoticon