+ 2
What does *(a+2) mean
int arr[] ={1,2,3} P = *(arr +1) What is p here?
4 Respostas
+ 4
It seems your first question wasn't really answered; So C++ uses pointers when you make an array like that:
int arr[] = {...}// arr is a pointer now
When you add a number to a pointer, you are telling it to point at the next memory address. Because C++ will allocate consecutive memory addresses for arrays declared like this, adding (or subtracting) 1 will move the pointer along the array.
Using a star '*' will get the value that is at the memory address that the pointer is pointing to. So, to answer your first question, *(arr + 1) is moving the pointer to the next memory address from the start, and getting the value at that address, which is 2. But that part of your question was already answered by Michael 😊
+ 4
*(arr+1) accesses the data in arr[1]
https://code.sololearn.com/cRrda1dJBOaI/?ref=app
+ 4
Zeke Williams you are correct as validated by
https://www.programiz.com/cpp-programming/pointers-arrays
for those interested in reviewing further.
+ 2
Better to learn this topic go and search on YouTube mycodeschool channel and see pointer playlist