c++ the use of understanding pointers -


i reading on c++ pointers. http://www.cplusplus.com/doc/tutorial/pointers/

#include <iostream> using namespace std;  int main () {     int firstvalue = 5, secondvalue = 15;     int * p1, * p2;     p1 = &firstvalue;  // store address of firstvalue = 5     p2 = &secondvalue; // store adrees of secondvalue = 15     *p1 = 10;          // p1 = 10      *p2 = *p1;         // p2 = 10     p1 = p2;           // p1 = 10     *p1 = 20;          // p1 = 20      cout << "firstvalue " << firstvalue << '\n';     cout << "secondvalue " << secondvalue << '\n';    return 0; } 

from understanding output should be

   firstvalue 20    secondvalue 10 

but when @ answers other way round

   firstvalue 10    secondvalue 20 

i don't understand quite pointers. please help

p1 = p2;           // p1 points p2 pointing @ *p1 = 20;          // *p2 = secondvalue = 20 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -