simple project to help me understand pointers.

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2007
Posts: 7
Reputation: avgprogramerjoe is an unknown quantity at this point 
Solved Threads: 0
avgprogramerjoe avgprogramerjoe is offline Offline
Newbie Poster

simple project to help me understand pointers.

 
0
  #1
Aug 16th, 2007
Hey guys, I "understand" pointers. But I do not understand how I could actually put them to use. If you could give me a few example programs of how they would be used, then I could try to make the programs. I don't want the code, just the logic behind the program. I don't someone to just hand me over the answer, it will be much more rewarding if I can figure it out on my own.

Thanks,

Joe
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,618
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1491
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: simple project to help me understand pointers.

 
0
  #2
Aug 16th, 2007
There are millions of examples because they are frequently used in every-day applications. But a simple introduction might be to write a function that sets all the bytes of a character array to 0. Function prototype might be
  1. void clear_array(char* array, int size);
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: simple project to help me understand pointers.

 
0
  #3
Aug 18th, 2007
Sample code
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int x; // A normal integer
  8. int *p; // A pointer to an integer
  9.  
  10. p = &x; // Read it, "assign the address of x to p"
  11. cin>> x; // Put a value in x, we could also use *p here
  12. cin.ignore();
  13. cout<< *p <<"\n"; // Note the use of the * to get the value
  14. cin.get();
  15. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC