PDA

View Full Version : Pointers



ygfperson
05-11-2003, 07:10 PM
Are pointers necessary in C++?
Are pointers useful in C++?

(as opposed to references only)

sean
05-11-2003, 07:17 PM
I think so, but shouldn't this be in the C++ forum?

Perspective
05-11-2003, 07:20 PM
>> Are pointers necessary in C++?

in the most simple cases, no. but for any practicle program pointers are necessary ( you cant even have an array with out a pointer)

>> Are pointers useful in C++?

yes, extremely. usefull for so many reasons i cant even begin to list them.

golfinguy4
05-11-2003, 07:42 PM
Originally posted by ygfperson
Are pointers necessary in C++?
Are pointers useful in C++?

(as opposed to references only)

Function pointer, void pointer, if the location being pointed to needs to be changed

Brighteyes
05-11-2003, 08:50 PM
>Are pointers necessary in C++?
Yes. References remove most needs for pointers, but in just about any nontrivial program you'll find yourself using them liberally.

>Are pointers useful in C++?
Same question, different words. See above. :p

>(as opposed to references only)
What if you want to change where a reference refers? Or use a "null" reference?

>Function pointer
You can have references to functions, they just look funny because nobody's used to them. :)

rick barclay
05-11-2003, 10:30 PM
I always thought pointers were a way to manage memory, which
would make them useful.

thedumbmutt
05-12-2003, 12:54 PM
Absolutely, especially if your gonna do low-level type stuff.

Brian
05-12-2003, 05:15 PM
Originally posted by ygfperson
Are pointers necessary in C++?
Are pointers useful in C++?

(as opposed to references only)

I suppose you could program without them, if you just wanted to print something on screen.

No wait, you need pointers for that.



#include <iostream>
using namespace std;

int main()
{
cout << "Hello, pointer world" << endl; // The stuff in the speech marks is addressed by a pointer.
return 0;
}