Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • Last Modified:

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?
0
thenthorn1010
Asked:
thenthorn1010
  • 3
  • 2
  • 2
  • +3
8 Solutions
 
jkrCommented:
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)

0
 
Bill NolanOwner, Lead Technology ProgrammerCommented:
jkr is correct, although the 'ref' keyword in C# provides a bit of that functionality.
0
 
Hugh McCurdyCommented:
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?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
user_nCommented:
for me pointers in java are not the same thing that are pointers in C.
http://en.wikipedia.org/wiki/Pointer_%28computing%29
0
 
sarabandeCommented:
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.

Sara
0
 
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.
0
 
user_nCommented:
http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29
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.

http://en.wikipedia.org/wiki/Reference_%28computer_science%29

http://cslibrary.stanford.edu/106/
0
 
Hugh McCurdyCommented:
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.
0
 
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.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now