0
Pointers & arrays using indexs from for loop
I know it is possible to send an index i to a vector and get a value. Ex. vector[i] and it gives u the element you need. Is it possible to do this using a for loop that keeps looping and sends in indexs for arrays? Can the same thing happen for pointers? Please provide an example for me to try out.
2 Respostas
+ 1
The vector is a template class from C++ library to extending and simplification work with arrays.
So, the array (without vector) uses indexes too too, but not supported other vector member functions
int a[10];
for (int i=0;i<10l;i++)
a[i]=2*i;
int b=a[3];
Using with pointers can be simillar, or not. Because exist many ways how to organize more pointers (and object values alllocated in pointers). They can be organized as a array of pointers (you can use indexes), or list of pointers (where use iterators to cross between pointers)
Looks for another container template classes in std library..
0
This is helpful, thanks.