Tuesday, July 14, 2009

How do pointers in C++ save memory space and how does memory work?

A space in memory holds some value of information that your program has specified it will need at some time. So if you have already declared a space and need to reference the value of that space, you can use a pointer, instead of creating a duplicate space in memory. Your pointer just keeps reference of the location in memory where your original information is stored. So it saves space by not keeping the entire length of your information in two different places in memory.

How do pointers in C++ save memory space and how does memory work?
Think about a cabinet with 10 x 10 drawers. A pointer is a reference to the drawer. You will just need two digits to specify the location of any item. Now your item may be as big as you want, and with some imagination, each drawer could hold another cabinet with each one 10x10 drawers... And you get a pointer of pointer...

survey questions

No comments:

Post a Comment