'Strange Behavior with pointers with arrays in c++
Hello people of Stacked Overflow! Recently I've been learning about pointers and arrays in my college Computer Science class. In order to try to test the depth of my understanding of the two, I tried to come up with some confusing instances in order to see if I could correctly predict the outcome of the result, as well as the reason for why the result is what it is... Well I seem to have confused myself too much, because I don't understand these few instances that I have come up with.
int vals[] = {1,2,3,4,5,6};
int* valptr = vals;
cout<<*valptr<<endl;
cout<<(**&vals)+1<<endl;
//cout<<*(++valptr)<<endl;
// cout<<*(++vals)<<end1;
cout<<*&valptr[0]<<endl;
cout<<**(&valptr)<<endl;
cout<<valptr[0]<<endl;
Part of the main part of my confusion was solved, so I commented out a line on the code, I wanted to know why lines such as cout<<**(&valptr)<<endl; actually run, I'm just confused on why that works. why does it only work when I have the & on it?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
