Pointers - needed as a beginner?

Started by
12 comments, last by sanguineraven 21 years, 10 months ago
I''ve been learning c++ for a bit, mainly off www.cprogramming.com Now exams are over and I have a few free months, in which I aim to get a decent understanding of the language. However, as many other new people, I have come across a few problems with pointers. I think I understand them, I will a bit better when I''m more awake, but my question is: As a beginner, do I need pointers yet? I mean I could learn some more, and do some basics such as a blackjack game or text based games, and then come back to pointers when I probably understand them better? Or should I make sure I learn and understand them now before proceeding? Thanks for any help. What about me? What about Raven?
Advertisement
In my opinion, pointers are such an important part of C/C++, that you have to understand at least the basics of them (how to declare and assign values to them, and their usage in functions), before trying to make a game.

I''m sure it''s possible to do a game without them, but they will make things so much easier, so if you ask me, learn about pointers.

/John
/John
Learn Pointers.

Pointers are good for you, they keep your programs trim and in good shape, as well as excercise the mind (for the first couple of months anyway)

Pointers are a necessary evil with any c-based language, and allow incredible powers of production (and for that matter destruction) of programs.

The choice you have is spend x effort to learn pointers asap, or spend x^2 effort remembering to use them in all the places you should have but didn''t becuase you did not know any better.

Once more...

Learn Pointers.
What problem do you have which you think requires a pointer as part of the solution?
Internally, pointers are used for just about everything—and I mean that literally. Now, from the programmer''s point of view, pointers are often used to implement certain data structures or. More generally, they''re used to access objects indirectly.

Don''t listen to the hype that pointers are "evil" or "dangerous." The alternative (references) is not much safer than pointers on a modern operating system, and the rest of the difference is syntax. In a language that allows both pointers and references, it''s often good to use pointers to make it clear that the object passed indirectly may be modified—in contrast to references which, conincidentally, look exactly like pass-by-value.
quote:Original post by sanguineraven
I''ve been learning c++ for a bit, mainly off www.cprogramming.com
Now exams are over and I have a few free months, in which I aim to get a decent understanding of the language. However, as many other new people, I have come across a few problems with pointers.
I think I understand them, I will a bit better when I''m more awake, but my question is:
As a beginner, do I need pointers yet? I mean I could learn some more, and do some basics such as a blackjack game or text based games, and then come back to pointers when I probably understand them better? Or should I make sure I learn and understand them now before proceeding?
Thanks for any help.

What about me? What about Raven?



Concept behind pointer isn''t difficult. It just the location of something in memory or in a file. For me anyway the hardest part was keep the syntax straight.
I find the thing with anything I learn is that I don't understand it until I see it used.

When a book explains something and shows a demo to explicitly demostraight HOW to use something I understand it, but my thoughts go along the lines of "Now why the hell do we need this!?".

When they start using it generally and practically without explicit use of it here, there and everywhere - then I start to understand it.

What I'm saying is that, I, along with quite a few people was clueless as to the point of pointers, until it's shown in a decent way, but I see the authors' reasoning behind pointers-only-demo-that-didn't-needpointers-and-just-for-no-reason-use-them.exe because they don't want to confuse you with other stuff. If you haven't learnt the reference/alias-variable things yet (I forget the proper name) then learn them, the tutorial might help you understand the pointer thing better.

[edited by - garconbifteck on June 10, 2002 3:24:28 PM]
I''m still looking for a good source to answer the "Why the hell do you use a pointer?" question. To me it''s just a couple extras lines and symbols to use a variable. And I''m making my own engine! *cackles*
Er, as a beginner you don''t need to learn how to use pointers, you should though. Or you''ll end up like me

------------
aud.vze.com - The Audacious Engine <-- It''s not much, yet. But it''s mine... my own... my preciousssss...
MSN: nmaster42@hotmail.com, AIM: LockePick42, ICQ: 74128155
_______________________________________Pixelante Game Studios - Fowl Language
Pointers are gods that can make your life easier or worse. Worse if you don''t know how to use them. Easier if you know their mighty powers.

You''ve got many responsed from people before me, you should read them because they''re all correct. But, I''ll point out something:
I know this is how people teach you using pointers:

  int a, *pa;a = 10;pa = &a*pa = 12;   // assign a value to a variable using pointersa = 12;    // why don''t we just do it this way??  


Frankly, this is not what (usually) pointers are used. The example just shows you how pointers work, but we never use them that way. It''s just stupid, allocating 2 variables for 1 value, what a waste of memory. Learn how to allocate memory, that''s where you can see the wonderful part of pointers. Imagine...storing values without variables...how godly is that!

My compiler generates one error message: "Doesn''t compile."
-Albert Tedja-
My compiler generates one error message: "does not compile."
An obvious use for pointers is dynamic memory allocation. Say you want an array of ints but you want the user to decide exactly how many ints there are:

int *int_ptr;

int_ptr = new int[user_supplied_value];

usually you would be better off using std::vector here but that essentially uses pointers to achieve this effect.

Then you could have a pointer acting as a cursor to the currently selected int to allow the user to select and modify one of the values.

Why not just use an unsigned int representing the array index for this? Well you may decide you want the user to manupulate some other random int which isn''t part of an array or anything. Because you used a pointer you can just assign the pointer to your random int and the code to allow the user to manipulate ints via the cursor can remain unchanged.

Various other pointer related delights lie in store for you. Pointers basically allow you to manipulate memory directly which gives you almost total control and is also very fast. As an exercise in pointers you could try knocking up a string class or a linked list class.


Geocyte Has Committed Suicide.
Geocyte Has Committed Suicide.

This topic is closed to new replies.

Advertisement