LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 08-13-2005, 12:22 PM   #1
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: LFS-Version SVN-20091202, Arch 2009.08
Posts: 1,450

Rep: Reputation: 63
C programming pointers & recursive


So C programmers what is your opinion on witch of these 2 concepts in C
programming are harder to understand for a learning programmer.


pointers or Recursion


I'm having issues being able to understand recursion my self but pointers
are equally challenging.
 
Old 08-13-2005, 12:38 PM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 1,997

Rep: Reputation: 107Reputation: 107
Pointers are harder cause recursion can be learned by doing something with the fibonacci seqence and analyze it to the nth degree.
 
Old 08-13-2005, 12:41 PM   #3
carl.waldbieser
Member
 
Registered: Jun 2005
Location: Pennsylvania
Distribution: Kubuntu
Posts: 197

Rep: Reputation: 32
Re: C programming pointers & recursive

Quote:
Originally posted by exvor
So C programmers what is your opinion on witch of these 2 concepts in C
programming are harder to understand for a learning programmer.


pointers or Recursion


I'm having issues being able to understand recursion my self but pointers
are equally challenging.
I always though recursion was the harder concept. Pointers always seemed to be very natural to me. I started out programming on a C64, though, and all the PEEK / POKE commands you had to do gave you a better understanding of the physical machine. Since pointers are a concept that basically maps to the hardware (putting issues like memory segmentation, virtual memory, paging, etc. aside for the moment), I guess that is why I felt they were easy to understand.

Recursion is a concept you see in lots of languages and in mathematics, too. To me, it is the "inside-out" way of looking at an iterative problem. However, there are situations where it is much easier to read a recusive program instead of an iterative program where you must maintain your own stack.
 
Old 08-13-2005, 01:59 PM   #4
lowpro2k3
Member
 
Registered: Oct 2003
Location: Canada
Distribution: Slackware
Posts: 340

Rep: Reputation: 30
In my opinion, pointers are much more important and should be focused on more when you're learning. Recursion is nice and if you keep it in the back of your mind, it can pop up as an obvious clean solution to certain problems. But pointers need to be mastered, you can generally get by as a C/C++ programmer without using recursion, but you certainly can't do any useful tasks without a decent knowledge of pointers. Heck I dont know of any API's that don't return pointers to structures/objects, and expect the same as parameters.

When I was learning I probably had an average amount of frustration with pointers, but I found they did come to me and I feel I understand them very well now. When I was in school my teachers focused on drawing memory diagrams and I would turn around and recommend this practice to everyone now. Recursion came a little slower to me. I'm working on walking directory trees using recursion, because in this situation recursion seems more natural. This is what I mean by learn "what" it is early in your learning days, then keep it in your mind until it springs up as a good solution to a problem. It was a while before I saw a good problem for recursion to solve. I think they told me in school that everything you can solve recursively you can solve iteratively.
 
Old 08-14-2005, 08:11 AM   #5
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 32
Pointers aren't a concept, they're a fundamental part of the language which you must master in order to write correct code. Recursion is merely a programming technique which the design of C facilitiates particularly easily).
 
Old 08-15-2005, 12:46 PM   #6
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 1,997

Rep: Reputation: 107Reputation: 107
Yeah, pointers are more important to understand, but the question was whether pointers or recursion was harder to understand. I personally love pointers, but to me, recursion is a much easier concept to understand.
 
Old 08-15-2005, 02:13 PM   #7
lowpro2k3
Member
 
Registered: Oct 2003
Location: Canada
Distribution: Slackware
Posts: 340

Rep: Reputation: 30
I guess I would say recursion is easier, because its so self-contained. If you're recursive function is acting up, you know where to immediately look. Tracing memory leaks due to pointers being used improperly takes a significant amount of time. So even though everyone "knows" pointers, they still can be mishandled and time must be wasted finding the root of the problem. I'm sure we've all had our share of segfaults
 
Old 08-15-2005, 03:22 PM   #8
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 32
Quote:
Originally posted by tuxdev
Yeah, pointers are more important to understand, but the question was whether pointers or recursion was harder to understand. I personally love pointers, but to me, recursion is a much easier concept to understand.
I'm not sure why people find pointers difficult to understand. They seem pretty straightforward to me. I come from an assembler background (actually hand-crafting machine-code back in the 70s!) so I got to understand what goes on at the machine level early on. Every language I've used since then has been "high-level" by comparison! Drawing pictures helps, I find, when explaining pointers to beginners.

I did once spend 20 minutes trying to explain a two line recursive function (not mine) to a maintenance programmer who just couldn't get it - in the end I waited 'til the coder left the project, raised a defect and "fixed" it so it worked efficiently without recursion (the entry and exit RAS overhead on the function really screwed performance with recursion).
 
Old 08-16-2005, 09:24 AM   #9
sundialsvcs
Senior Member
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 3,685

Rep: Reputation: 329Reputation: 329Reputation: 329Reputation: 329
Pointers are a bit of a problem in "C" because you have to use them so much. The original language does not have the concept of var or const parameters, and some compilers were quite loosy-goosy about what strangeness they would accept without saying anything... strangeness that, of course, was a bug.

When explaining a pointer to my classes, I always stressed that what it is is just an ordinary integer. What's different about it is what it does: namely, it contains an address. Therefore you can refer either to "the value of the integer that is in this pointer variable," or you can refer to "the whatever-it-is that presumably is to be found at that address." The choice is yours, and you'd better keep them straight. And I tell them that NULL corresponds to the special-value zero. Then, I just remind them to "draw a picture, just like I do."

Recursion has never been a problem. People just assume that a function should be able to call itself, if it wants to. I just have them write a little program that calls itself endlessly, so they can experience for themselves the totally-bogus error messages that usually pop out as a result.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Programming, Recursive/Iterative Calls on Folder Contents gtwilliams Linux - Newbie 1 07-06-2005 06:44 PM
Difference between Top Down programming & Bottom up programming minil Programming 1 06-17-2005 02:42 AM
C Programming: Help with Pointers to Functions devinWhalen Programming 2 03-04-2005 01:00 PM
Pointers && Gade PLZ HELP OutToSea Programming 6 06-15-2003 08:27 AM
c programming pointers (a factorial calculation) Randall Programming 5 02-23-2003 12:47 PM


All times are GMT -5. The time now is 03:09 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration