I'm learning about pointers in C++. I understand that to assign the address of var1 to the pointer var2, you
int var1;
int *var2;
var2 = %26amp;var1;
I saw the code below just now and I don't understand it.
int *i, j[10];
double *f, g[10];
int x;
i = j;
f = g;
for(x=0; x%26lt;10; x++)
cout %26lt;%26lt; i+x %26lt;%26lt; ' ' %26lt;%26lt; f+x %26lt;%26lt; '\n';
j[10] and g[10] are arrays so what happens if you
i = j;
f = g;
when I compile the code, it seems that the address of j is assigned to i and g to f. So why is there no %26amp;?
Pointers in C++?
i=j;
Is the same as
i = %26amp;j[0];
And believe it or not,
i = j + 5;
is the same as
i = %26amp;j[5];
That is why
cout %26lt;%26lt; i+x
Prints out the successive elements of the array.
Reply:*j or J[10] Basically in this 2 Variables your declaring that they're arrays
*j ---- doesn't have any specified size of array
J[10] ---- the size of array is 10
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment