One of my learning books said that the dereference operator had the same precedence as incrrement and decrement operators. Doubting that I searched and found that de-reference is the same as prefix increment and decrement, but less than postfix. Just for grins I ran a test. Now I think my test is flawed, but cannot see where. Here is the code I wrote for Visual Studio C++ running under Windows 7:
After running the code x contains ADHK_BDIL
VS won't let me cut from the Locals page, but I hope I have the output right.
The problem is the last line of code and the last character in the string x. To my opinion the parens should force the k_itr to be de-reference before the increment. The results indicate that it is incremented then de-referenced.
What is going on here?
We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)
Code:
std::string a = "ABC";
std::string d = "DEF";
std::string h = "HIJ";
std::string k = "KLM";
std::string x;
string::iterator a_itr = a.begin();
string::iterator d_itr = d.begin();
string::iterator h_itr = h.begin();
string::iterator k_itr = k.begin();
x.push_back(*a_itr );
x.push_back(*d_itr );
x.push_back(*h_itr );
x.push_back(*k_itr );
x.push_back( '_' );
x.push_back(* ++ a_itr ); // incremented then de-referenced
x.push_back( * d_itr ++ ); // de-referenced then incremented
x.push_back( *( ++ h_itr) ); // incremented then de-referenced
x.push_back( ++( * k_itr) ); // incremented then de-referenced
VS won't let me cut from the Locals page, but I hope I have the output right.
The problem is the last line of code and the last character in the string x. To my opinion the parens should force the k_itr to be de-reference before the increment. The results indicate that it is incremented then de-referenced.
What is going on here?
We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)