Image
 
linkedin_logo.png rss_logo.jpg
twitter_logo.png youtube_logo.jpg
Latest Additions
 
EH-Net Login
Welcome Guest.






Lost Password?
No account yet? Register
Who's Online
We have 49 guests and 1 member online
 
Free Business and Tech Magazines and eBooks

You are here: Home arrow Ethical Hacking Discussions and Related Certificationsarrow Programmingarrow Learning C++
EH-Net
May 21, 2013, 02:09:09 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Go back to The Ethical Hacker Network Online Magazine Home Page
 
   Home   Help Calendar Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Learning C++  (Read 5885 times)
0 Members and 1 Guest are viewing this topic.
MatP
Newbie
*
Offline Offline

Posts: 37


View Profile WWW
« on: August 19, 2010, 11:28:25 AM »

Hey Smiley

So I'm in the process of learning C++. I have a small problem though.

I find it difficult at times to understand the point of pointers. Perhaps it's simply the textbook I am using doesn't provide a good explanation or a good example. I just can't think of any reason I'd want to use them in a program I was creating myself.

Now I'm sure there must be plenty of reasons out there as I've seen them in examples of other code so I'm wondering if anyone has a good resource to teach this aspect of programming or could provide an example problem that requires a solution using pointers?

Thanks for the help!
Logged

Equix3n-
Sr. Member
****
Offline Offline

Posts: 386



View Profile
« Reply #1 on: August 19, 2010, 11:52:18 AM »

Have you ever tried to pass an array as an argument to a function? How do you do this?<-- Think on this for a moment, and try to find a solution for it.
Also, how do you allocate dynamic memory?

I learned C programming (I'm not very good at C++ though I can read and understand the code) and especially pointers from a lot of books and online articles, so I can't direct you to any absolute resource. However, a good starting point will be to clear your concepts pertaining to arrays and strings and how they're stored in memory and then move to pointer. Learn all about pointers,pointers to arrays/strings, array of pointers (different form pointer to arrays), function pointers, pointers to other datatypes and try to compare how using a pointer is different from using that variable in a normal way. At each point try to visualize what's happening in the memory.

Here are some resource which might help you.
http://www.cprogramming.com/tutorial/lesson6.html
http://www.augustcouncil.com/~tgibson/tutorial/ptr.html
http://c-faq.com/ptrs/index.html
http://c-faq.com/malloc/index.html
http://c-faq.com/aryptr/index.html
Logged
zeroflaw
Full Member
***
Offline Offline

Posts: 208



View Profile
« Reply #2 on: August 19, 2010, 12:47:00 PM »

With pointers you have full control over the memory in your program. Also sometimes you need to work with memory addresses, they can be stored in pointers.

And like Equix3n said, how do you allocate dynamic memory? Or how do you access newly allocated memory? You need pointers for this. It's also needed when implementing polymorphism in your program. You have different types of objects, and sometimes you don't know the type in advance or want to change it. You can have your pointer point to a different type of object then.

There are also lots of functions from different API's that need pointers as arguments.



Logged

ZF
MatP
Newbie
*
Offline Offline

Posts: 37


View Profile WWW
« Reply #3 on: August 20, 2010, 08:55:23 AM »

Thanks for the help guys Smiley I appreciate it. I will definitely take a look at those links over the next few days.


I hadn't considered a lot of what you've given me. I'm still fairly new to C++ (and programming in general, haven't done anything beyond beginner stuff before) so there are a number of concepts still quite foreign to me. Anyway, I will continue reading/learning!

Thanks!
Logged

Equix3n-
Sr. Member
****
Offline Offline

Posts: 386



View Profile
« Reply #4 on: August 22, 2010, 07:59:57 AM »

You might also want to consider the following free lectures from Stanford.
CS106-B Programming Abstractions: Teaches C++ programming. Natural successor to CS106-A which teaches programming methodology in Java
http://see.stanford.edu/see/lecturelist.aspx?coll=11f4f422-5670-4b4c-889c-008262e09e4e
http://www.youtube.com/user/stanforduniversity?blend=2&ob=4#g/c/FE6E58F856038C69

CS106-A Programming Methodology
http://see.stanford.edu/see/lecturelist.aspx?coll=824a47e1-135f-4508-a5aa-866adcae1111
http://www.youtube.com/user/stanforduniversity?blend=2&ob=4#g/c/84A56BC7F4A1F852
I haven't gone through both of the above, but I checked the first video of CS106A and I guess you'll be fine if you jump straight into CS106B.

I'm currently going through CS107. Excellent stuff. It's a must if you want to learn some advanced programming basics. Highly recommended. It basically teaches what happens under the hood, so don't study from it if don't already know basic C/C++.
CS107 Programming Paradigms
http://see.stanford.edu/see/lecturelist.aspx?coll=2d712634-2bf1-4b55-9a3a-ca9d470755ee
http://www.youtube.com/user/stanforduniversity?blend=2&ob=4#g/c/9D558D49CA734A02

Edit: Just found a really good paper or Pointers. Do read it.
cslibrary.stanford.edu/102/PointersAndMemory.pdf
« Last Edit: August 22, 2010, 11:41:38 PM by Equix3n- » Logged
MatP
Newbie
*
Offline Offline

Posts: 37


View Profile WWW
« Reply #5 on: August 23, 2010, 09:24:20 AM »

Awesome, I will definitely look over all of those videos/the paper linked when I'm at home and have some time. Thanks for the links and all the resources you've provided so far. Slowly but surely I'll figure this stuff out and get into more advanced concepts Smiley
Logged

MatP
Newbie
*
Offline Offline

Posts: 37


View Profile WWW
« Reply #6 on: August 23, 2010, 01:09:57 PM »

So I've read over some of the content you linked in your first post Equix3n- and I've got to say that the text book I'm reading, which has been mostly pretty good, is really terrible at explaining the concept of pointers.

Thanks so much for your links Smiley
Logged

Equix3n-
Sr. Member
****
Offline Offline

Posts: 386



View Profile
« Reply #7 on: August 23, 2010, 01:15:50 PM »

Which book are you referencing?
Logged
MatP
Newbie
*
Offline Offline

Posts: 37


View Profile WWW
« Reply #8 on: August 23, 2010, 02:11:02 PM »

A First Book of C++, From Here to There
Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
Joomla Bridge by JoomlaHacks.com
Valid XHTML 1.0! Valid CSS!
Page created in 0.614 seconds with 22 queries.
 
Exclusive Deal

sansfire13_245x90_cw90.jpg
SANSFIRE 2013
June 15 - 22

5% Off w/ Code: EHN_5

SANS Deals 4 EH-Netters
5% OFF Any SANS Course in Any Format!
Coupon Code: EHN_5 Including SANS Rocky Mountain 2013 & SANS Boston 2013
Polls
Compared to this year, 2013 will be:
 
Recent Forum Topics
EH-Net News Feeds
Latest Additions
 
         
Advertisement

© 2013 The Ethical Hacker Network
Joomla! is Free Software released under the GNU/GPL License.