Pointers and Pointers to Pointers

I am reviewing some C and C++ source code, and I was wondering if someone could answer a question for me. What are the differences and uses for pointers and pointers to pointers in C and C++? How are they used in the C/C++ language versus other languages like VB, C#, and Java?
Who is Participating?
jkrConnect With a Mentor Commented:
You will find a comprehensive description at http://www.cplusplus.com/doc/tutorial/pointers/ - way better than I could explain it to you here.

>> How are they used in the C/C++ language versus other languages like VB,
>> C#, and Java?

Well, in short: There is nothing that can be compared to pointers in these languages, since they are basically all compiled into 'P-code' (http://en.wikipedia.org/wiki/P-code_machine)

Bill NolanConnect With a Mentor Owner, Lead Technology ProgrammerCommented:
jkr is correct, although the 'ref' keyword in C# provides a bit of that functionality.
Hugh McCurdyConnect With a Mentor Commented:
It occurs to me that, since you are reviewing code, that you might have specific questions.  If you post a bit of code where you are confused, perhaps you can get a specific answer.

It might also help to know your background.  Do you already  know one or more of Java, C# and VB?
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

user_nConnect With a Mentor Commented:
for me pointers in java are not the same thing that are pointers in C.
sarabandeConnect With a Mentor Commented:
pointers in C and C++ are same. they are pointing to an address in virtual memory where the variable they were pointing to resides.

a pointer to pointer is a pointer to a pointer variable or a pointer to the first element of an array of variables.

thenthorn1010Author Commented:
I am a software developer whom has been using VB .NET, C#, Java, C++, and several other languages across a spectrum of projects that do not last a long time. Due to recent downturns in the market, I have been picking up a lot of skills in various programming languages, but I am not on a project long enough to become "advanced" in it. So, I find myself constantly looking for answers on all forums instead of being able to know more answers on my own. I have been on and off working for five years, and my background began with C/C++ and quickly moved into VB. NET. With all of the programming language changes and not very much familiarity with just one, I am versatile but it takes me a while to get some of the projects done because I have to research some syntax that I am not used to, due to the various languages. I hope this gives a background on myself a little bit more.
user_nConnect With a Mentor Commented:
In C#, memory address pointers can only be used within blocks specifically marked as unsafe, and programs with unsafe code need appropriate permissions to run. Most object access is done through safe object references, which always either point to a "live" object or have the well-defined null value; it is impossible to obtain a reference to a "dead" object (one that has been garbage collected), or to a random block of memory. An unsafe pointer can point to an instance of a value-type, array, string, or a block of memory allocated on a stack. Code that is not marked as unsafe can still store and manipulate pointers through the System.IntPtr type, but it cannot dereference them.
Managed memory cannot be explicitly freed; instead, it is automatically garbage collected. Garbage collection addresses the problem of memory leaks by freeing the programmer of responsibility for releasing memory that is no longer needed.
In addition to the try...catch construct to handle exceptions, C# has a try...finally construct to guarantee execution of the code in the finally block.


Hugh McCurdyConnect With a Mentor Commented:
Thanks for the background.  Perhaps it would help you to do assignments while looking for work.  I do that even when not looking for work (unless I'm really busy).

One idea for pointers in C++, would be to create a class that contains, say, some basic information about some (fictitious) people.  Say, Name and height (in inches or cm).  Put that information into a flat text file.  Read it in an make objects and place them in an array as you go.  Print the results.

Then in phase 2, sort the array using some sort algorithm.  (You should be able to find one or you could ask for help here.)  You could start with bubble sort.  It's simple but SLOW.  Speed doesn't matter for  under a dozen records.  

Then, in phase 3, instead of sorting the array, make an array of pointers to that array and sort the array of pointers.

This will give you practice with pointers and may help you to understand.

Or you could try something else.  The point that I'm trying to make is write some code and learn from it.  If you get stuck, post some code and ask for conceptual help.

It would be better if you say you are trying to learn so the experts can try to teach, instead of just writing a quicksort algorithm for you.

Just my 2 cents.
thenthorn1010Author Commented:
Thank you to everyone for the great ideas on how to review pointers and the definitions of pointers. I have a good starting point now to look through for reviewing pointers.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.