Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 30th, 2006, 8:20 AM   #11
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
'*' is not "the address of". '&' is "the address of" (in one of its guises). '*' is the opposite (the thangy residing at the address).
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Apr 30th, 2006, 10:26 AM   #12
Darkhack
Hobbyist Programmer
 
Darkhack's Avatar
 
Join Date: Dec 2005
Location: Kansas City
Posts: 105
Rep Power: 3 Darkhack is on a distinguished road
Send a message via AIM to Darkhack
Quote:
Originally Posted by DaWei
'*' is not "the address of". '&' is "the address of" (in one of its guises). '*' is the opposite (the thangy residing at the address).
Ooops!!! DaWei is 100% correct. I'm an idiot. This is why I only have PHP and C# listed as my languages in my profile. Let me try this one more time..

var x = My House
var *y = &x;
print x;   //prints My House
print y;   //prints 0x010000
print *y;  //prints My House

& is read as "the address of"
* is read as "contents of the address"

There are also "pointers to pointers" with **. But I won't go into that on the basis that I might screw up again. :o
Darkhack is offline   Reply With Quote
Old Apr 30th, 2006, 10:34 PM   #13
Twilight
Programmer
 
Join Date: Apr 2006
Location: Calgary, Alberta
Posts: 67
Rep Power: 3 Twilight is on a distinguished road
Quote:
Originally Posted by grumpy
Arrays are not pointers. In some contexts, in C and C++, pointers and arrays can be treated as if they are equivalent. In reality, however, they are very different things.

That is incorrect. It is easier to work with advanced data structures if you understand pointers. It is, however, possible to do advanced work with data structures with no pointer in sight. Some of the earliest advanced work on data structures (including implementation of linked lists and binary trees) was implemented using programming languages that did not even support anything like a pointer. The only issue is that, if pointers are not used, the bookkeeping techniques to identify (in a linked list) the next node are different. Given that people tend to misuse pointers quite regularly it is often true that, in practice, linked lists implemented without pointers are actually more robust because the programmer does better bookkeeping.
Yeah, I had a feeling I was gonna get called on the array thing, since it doesn't end up as a pointer when you convert it to assembly. But it's almost a pointer :p

However, I had no idea you could do LL's and BST's without pointers. Is it only other languages that can do that, or C++ too?
Twilight is offline   Reply With Quote
Old Apr 30th, 2006, 10:47 PM   #14
lectricpharaoh
SEXY SHOELESS GOD OF WAR!
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,193
Rep Power: 5 lectricpharaoh will become famous soon enough
Quote:
Originally Posted by Twilight
Yeah, I had a feeling I was gonna get called on the array thing, since it doesn't end up as a pointer when you convert it to assembly. But it's almost a pointer :p

However, I had no idea you could do LL's and BST's without pointers. Is it only other languages that can do that, or C++ too?
You can do it in pretty much any language, though if the language in question doesn't support user-defined types (structs, classes, or something roughly equivalent), it's much messier.

As to how to do it, it's simple: instead of using actual pointers, you allocate an array, and then store indices into the array. Of course, you still have issues regarding the need to resize the array, but even some languages that don't directly support pointers have facilities to do this.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is online now   Reply With Quote
Old Apr 30th, 2006, 10:49 PM   #15
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Quote:
Yeah, I had a feeling I was gonna get called on the array thing, since it doesn't end up as a pointer when you convert it to assembly.
Non-sequitur, has nothing to do with it.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old May 5th, 2006, 7:13 PM   #16
OopSheMishtamesh
Newbie
 
Join Date: Apr 2006
Location: Israel
Posts: 4
Rep Power: 0 OopSheMishtamesh is on a distinguished road
Quote:
Originally Posted by DaWei
Non-sequitur, has nothing to do with it.

couldn't agree more !
__________________
There will be blood...
OopSheMishtamesh is offline   Reply With Quote
Old May 5th, 2006, 7:43 PM   #17
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
I've read a couple of posts about how no one will pay you if you program without classes or pointer. That's a false statement and my paycheck proves it
Let's remember, C is a great language with many applications in embedded and linux, yet it doesn't have classes.
COBOL is good for business applications and data manipulation, yet it doesn't have pointers
OpenLoop is offline   Reply With Quote
Old May 7th, 2006, 12:11 PM   #18
mohamad_atef
Newbie
 
mohamad_atef's Avatar
 
Join Date: May 2006
Posts: 1
Rep Power: 0 mohamad_atef is on a distinguished road
pointers are so important and we can't do without them.
mohamad_atef is offline   Reply With Quote
Old May 7th, 2006, 1:57 PM   #19
Soulstorm
Hobbyist Programmer
 
Soulstorm's Avatar
 
Join Date: Jan 2006
Location: Menidi, Athens, Greece
Posts: 243
Rep Power: 3 Soulstorm is on a distinguished road
Quote:
Originally Posted by hervens48
Hey people.
Ive read so many tutorials about pointers, but i simply cant get them.
I understand their syntax and everything, but i cant understand what their really for. To me, their just simple intengers.
So is it possible to write a really really large program without using pointers or classes?
Although you can write most programs without the use of pointers, They will tend to be larger in size than otherwise.

Alsom without pointers, you can't proceed into understanding polymorphism in C++.

Although errors with pointers will give you the creeps at first, it is an essential part of C++ programming. And do not forget that the only reason that a thing like this exists, is to facilitate the work of programmmers, and not make it more difficult than it already is. So, as you understand, you will become more efficient if you use pointers and references.

Finally, without pointers, you will really have no luck if you intend to proceed into learning Objective-C (not that you said that you intend to, but just saying... )

Everyone sees it as a difficult part of C++ at first, and that is proved by the numbers of tutorials and threads on pointers on the internet. But don't let that intimidate you...
__________________
Project::Soulstorm (personal homepage)
Soulstorm is offline   Reply With Quote
Old May 7th, 2006, 4:00 PM   #20
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
There's a Pointer Basics link in my sig and Narue has a good one, too.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:49 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC