Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Apr 29th, 2006, 2:34 PM   #1
hervens48
Hobbyist Programmer
 
Join Date: Apr 2006
Location: Montreal, Canada
Posts: 107
Rep Power: 3 hervens48 is on a distinguished road
Send a message via AIM to hervens48 Send a message via MSN to hervens48
Can you program without pointers?

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?
hervens48 is offline   Reply With Quote
Old Apr 29th, 2006, 2:46 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Quote:
To me, their just simple intengers.
Then you didn't
Quote:
understand their syntax and everything
Yes, you could write a really, really large program without pointer or classes. On the other hand, no one would PAY you to.
__________________
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 29th, 2006, 2:47 PM   #3
InfoGeek
Professional Programmer
 
InfoGeek's Avatar
 
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4 InfoGeek is on a distinguished road
Quote:
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?
hmmm...Yes.
Well, No.
__________________
PFO - My daily dose of technology.
InfoGeek is offline   Reply With Quote
Old Apr 29th, 2006, 2:53 PM   #4
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Quote:
Originally Posted by hervens48
Ive read so many tutorials about pointers, but i simply cant get them.
I bet you haven't read the 'Pointer Basics' in DaWei's signature.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Apr 29th, 2006, 5:46 PM   #5
OopSheMishtamesh
Newbie
 
Join Date: Apr 2006
Location: Israel
Posts: 4
Rep Power: 0 OopSheMishtamesh 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?

look dude, it's possible to write large program without pointers or classes , but it will be undebugable.. and probebly a crappy piece of code no one else understand ..

to understand pointers you need to use them, for example , try to implement a linked list.. or even send array as parameter to another function..

after i used VB for very long time, it took my a while to understand why you need pointers, you'll get it with time..

good luck m8
OopSheMishtamesh is offline   Reply With Quote
Old Apr 29th, 2006, 7:37 PM   #6
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 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.
Well, yes and no. Yes, the actual physical value stored in a pointer variable will be an integer, but this is different from an int data type. It will be integral simply because you cannot have fractional memory addresses. Even though a bit is the smallest unit of information used by a computer, a byte is the smallest amount of information that you can directly access (and is usually, but not always, 8 bits in size). So, in this respect, pointers are integers, but there are important semantic differences between pointers and ints, since they are used for different purposes. The former are used exclusively to store addresses of other things, while the latter are used to store whole numbers for whatever purpose you need.

As to what pointers are really for, one of their main purposes is to increase efficiency. Rather than pass a large block of memory, you can pass a pointer to the start of the block. On most modern systems, a pointer is 32 bits, or four bytes, while a block of memory might be quite a bit larger, like several megabytes. It's much faster to copy four bytes than it is to copy a few million.

Pointers are also used to allow you to create dynamic data structures. In other words, you can determine the size of arrays and other such things at run time, rather than compile time. This makes your program more efficient (since it doesn't need to allocate 10000 elements when it only needs 100), and more capable (since it doesn't choke when it needs more than a hard-coded 100 elements).

You will find pointers used extensively in most operating system APIs, for a variety of reasons. Without learning how to use them, you really won't be able to write anything but the most trivial programs. Even languages that try to do away with pointers usually have them. If you've ever heard of an 'object reference' in Java, it's essentially a pointer, and if you ask me, trying to hide them from the programmer creates more problems than it solves.
Quote:
Originally Posted by hervens48
So is it possible to write a really really large program without using pointers or classes?
The irony here is that if you write two versions of the same program, but only use pointers in one version, the non-pointer one will likely be significantly larger.
__________________
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 29th, 2006, 7:41 PM   #7
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5 grumpy will become famous soon enough
Quote:
Originally Posted by DaWei
Yes, you could write a really, really large program without pointer or classes. On the other hand, no one would PAY you to.
Professional Fortran 77 programmers (there are plenty around) ask you to shut up. Shhhh!!!
grumpy is offline   Reply With Quote
Old Apr 30th, 2006, 2:52 AM   #8
Twilight
Programmer
 
Join Date: Apr 2006
Location: Calgary, Alberta
Posts: 67
Rep Power: 3 Twilight is on a distinguished road
Odds are you've been using pointers all along and didn't even realize it. Like arrays for instance. All those really are is pointers.

And if you ever want to work with advanced data structures, or even 2D arrays really, you'll need to know them.

If you want to see an application of them, trying making a linked list, or binary search tree.
Twilight is offline   Reply With Quote
Old Apr 30th, 2006, 3:16 AM   #9
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5 grumpy will become famous soon enough
Quote:
Originally Posted by Twilight
Odds are you've been using pointers all along and didn't even realize it. Like arrays for instance. All those really are is pointers.
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.
Quote:
Originally Posted by Twilight
And if you ever want to work with advanced data structures, or even 2D arrays really, you'll need to know them.
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.
grumpy is offline   Reply With Quote
Old Apr 30th, 2006, 3:28 AM   #10
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
var x = My House
var *x = 555 main st.
var **x = Phone Book

Data is stored in memory (RAM). Each byte has an address associated with it. Something like 0x010000. I cant remember how long they are exactly but you get the idea. x is the data itself. *x is the address. **x is the address of where the pointer is located.

* could be read as "the address of". I too get confused by pointers and sometimes still do. You'll get better with practice.

Also, I agree with Grumpy. Java and many other languages where developers get big bucks, never use pointers. It just so happens that the things Java can do without pointers, C will make use of them in that situation.
Darkhack 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:37 AM.

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