+ 2
I need someone's help to explain arrays to me simply and pointers plz
4 Respostas
+ 3
an array is simply memory allocated and holds/will hold up to a specified amount of data. so of we have int myArray [5]; this sets aside 20 bytes of memory so we can store 5 integer values there. let's say we have 1 2 3 4 5 stored there memory addresses should be 4 bytes apart. and this s where pointers come into play. let's say we wanted to know what those address where, so we can declare an integer type pointer variable that can look up integer data. this pointer variable is allowed access to memory locations. so of we use these two together in a small loop:
int myArray []={1,2,3,4,5};//array set to size 5
int* ptr;
for (int I =0;i <5;i++)
{ptr=&myArray [i];
cout <<ptr <<endl;
}
this will loop through each of the arrays indexes (the number inside the []).
also, array indexing starts at 0, so that's why the loop is like that
+ 1
http://www.sololearn.com/app/cplusplus/playground/cbZ46undNaW4/ here's an example program so you can see the outputs
0
@destroy thx for the help
0
pointers are those functions that indicate (point) where the data is stored.
basically it gives the address of the particular data.