Problem:
Access the Elements of a Vector
Solution:
Elements of a Vector can be accessed using indexing. The [ ] brackets are used for indexing. Indexing starts with position 1 and not 0.
0 Access the Elements of a Vector
Solution:
Elements of a Vector can be accessed using indexing. The [ ] brackets are used for indexing. Indexing starts with position 1 and not 0.
If we need to exclude some values from a vector, we can use negative indexing.
We already created the vector v1 with 10 elements. Now, if we need to exclude the 1st element from v1, we can execute as below:
So, from the above output, we can see that 1st element “10” is missing.
Now, if we need to exclude a whole slice of 5 elements from vector v1, we can use the below code:
So, the above output shows that the new vector v5 has elements 10,20 and then 30-70 missing and then it has 80,90,100 as expected.
Thank You for reading!