Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > What is the Point of Pointer's

Reply
Thread Tools

What is the Point of Pointer's

 
 
Bill Potter
Guest
Posts: n/a
 
      08-04-2004
I am a learning programmer in C and i want to know why some one would use
pointers instead of going direct!


 
Reply With Quote
 
 
 
 
Goran Larsson
Guest
Posts: n/a
 
      08-04-2004
In article <(E-Mail Removed)>,
Bill Potter <(E-Mail Removed)> wrote:

> I am a learning programmer in C and i want to know why some one would use
> pointers instead of going direct!


The same reason why we use pointers in human languages, e.g.
"home" instead of "17859 Main Street"
"the car behind us" instead of "car with registration no KN5567YZ"
"you" instead of "Bill Potter"

--
Göran Larsson http://www.mitt-eget.com/
 
Reply With Quote
 
 
 
 
Mark F. Haigh
Guest
Posts: n/a
 
      08-04-2004
Bill Potter wrote:

> I am a learning programmer in C and i want to know why some one would use
> pointers instead of going direct!
>


Let's say you're shopping for a car at a car dealership and the dealer
asks you which car you like, what do you do?

1. __Point__ at a couple of cars...

or

2. Go to each car, and physically move each of them directly in front
of the dealer?


Probably #1, if you're at all concerned about efficiency. You can refer
to more cars quicker by pointing at them than moving them each directly
in front of you, one by one.

Does that help?


Mark F. Haigh
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Allan Bruce
Guest
Posts: n/a
 
      08-04-2004

"Bill Potter" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I am a learning programmer in C and i want to know why some one would use
> pointers instead of going direct!
>
>


for many reasons! 2 simple ones:

1) when passing a large structure to a function, we dont want to copy every
element and slow things down to a snail-pace. So pass a pointer instead,
which is very quick.

2) what if you want some information to be passed to a function and that
function modifies some data. For example a sort function. We pass a
pointer to an array to the function and let it do all the work.

Basically, pointers speed things up. They also allow dynamic memory
allocation using malloc() or equivalent. Things start to get more advanced
when you have pointers to pointers
Allan


 
Reply With Quote
 
osmium
Guest
Posts: n/a
 
      08-04-2004
Bill Potter writes:

> I am a learning programmer in C and i want to know why some one would use
> pointers instead of going direct!


In C - as distinct from C++ - using a pointer is the *only* way a called
function can alter the contents of a variable in the calling function.
Parameters are passed in C in what is called "pass by value", that is, a
*copy* is passed to the callee.


 
Reply With Quote
 
Jan Engelhardt
Guest
Posts: n/a
 
      08-04-2004
>> I am a learning programmer in C and i want to know why some one would use
>> pointers instead of going direct!

>
>In C - as distinct from C++ - using a pointer is the *only* way a called
>function can alter the contents of a variable in the calling function.
>Parameters are passed in C in what is called "pass by value", that is, a
>*copy* is passed to the callee.


In fact, C++'s references could be taken as a syntactic modification of The
Pointer, e.g.:

C> void callee(int *ptr) {
C> ++*ptr;
C> }

C++> void callee(int &ptr) {
C++> ++ptr;
C++> }


Jan Engelhardt
--
 
Reply With Quote
 
Stephen Sprunk
Guest
Posts: n/a
 
      08-04-2004
"Goran Larsson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> In article <(E-Mail Removed)>,
> Bill Potter <(E-Mail Removed)> wrote:
> > I am a learning programmer in C and i want to know why some one would

use
> > pointers instead of going direct!

>
> The same reason why we use pointers in human languages, e.g.
> "home" instead of "17859 Main Street"
> "the car behind us" instead of "car with registration no KN5567YZ"
> "you" instead of "Bill Potter"


Actually "17859 Main St" is a pointer as well; the house itself is not.
Obviously every time you invite someone over, you'd rather give them a
pointer to your house instead of building a copy and handing it to them.

S

--
Stephen Sprunk "Those people who think they know everything
CCIE #3723 are a great annoyance to those of us who do."
K5SSS --Isaac Asimov

 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      08-04-2004
Bill Potter wrote:
>
> I am a learning programmer in C and i want to know why some one would use
> pointers instead of going direct!



Look into a typical linked list implementation.




Brian Rodenborn
 
Reply With Quote
 
Goran Larsson
Guest
Posts: n/a
 
      08-04-2004
In article <U27Qc.33288$(E-Mail Removed)>,
Stephen Sprunk <(E-Mail Removed)> wrote:

> Actually "17859 Main St" is a pointer as well; the house itself is not.


No. "17859 Main St" is the name of the house (variable).

> Obviously every time you invite someone over, you'd rather give them a
> pointer to your house instead of building a copy and handing it to them.


No. You give them the name of the house. The problem starts when you
move and they continue to visit the hose by its name. The pointer "home"
should have been used instead.

--
Göran Larsson http://www.mitt-eget.com/
 
Reply With Quote
 
Michael Scarlett
Guest
Posts: n/a
 
      08-04-2004
"Bill Potter" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> I am a learning programmer in C and i want to know why some one would use
> pointers instead of going direct!


Pointers are direct. That's the point!
 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Share-Point-2010 ,Share-Point -2010 Training , Share-point-2010Hyderabad , Share-point-2010 Institute Saraswati lakki ASP .Net 0 01-06-2012 06:39 AM
Scenario 5: IS-IS routing on Frame Relay Multi-point and Point-to-Point David Sudjiman Cisco 0 06-08-2006 09:11 AM
point to point protocol Gopi VHDL 1 07-13-2004 02:37 PM
simulate point-to-point with 2620's np Cisco 11 03-04-2004 01:44 AM
help, please!! cisco 827H point per point configuration javi Cisco 1 10-16-2003 07:33 AM



Advertisments