# include<iostream.h>
int main()
{
int ar[2]={8,2}; // (1)
int var1=66; //(2)
int var2=111; //(3)
int* ptarray[5]; //(4)
ptarray[0]= ar; //(5)
ptarray[1]= &ar[1]; //Address of second element of array ar // (5)
ptarray[2]= &var1; //(6)
ptarray[3]= &var2; //(7)
ptarray[4]= &ar[0]; //(8)
// To keep code small I use a loop //(9)
for(int i=0;i<5;i++)
cout<<*(ptarray[i])<<endl; // (10)
}
Example
CASE1:
OUTPUT 1: 8
2
6
11
8
CASE 2: IF i replace *(ptarray[i]) with &(ptarray[i]) in LINE
NO 10 IN COUT << statement then output is
OUTPUT 2 : 0x 8fb8ffe4
0x 8fb8ffe6
0x 8fb8ffe8
0x 8fb8ffea
0x 8fb8ffec
CASE 3: IF I REPLACE *(ptarray[i]) with (ptarray[i]) in LINE
NO 10 THE OUT PUT IS
OUTPUT3:
0x8fb8fff2
0x8fb8fff4
0x8fb8fff0
0x8fb8fffe
0x8fb8fff2
question :
what is the difference between &ptarray[i] &
ptarray[i] due to that the address location of output 2 & output 3 is changing .
thanx in advaNCE
virendra