henszey
08-25-2002, 07:28 PM
I have been playing around with C++ for awhile now and I am still not sure what the purpose of pointers are. I know it can give you the memory address of a variable, but what purpose does that serve :confused:
Thanks in advance.
Squirm
08-25-2002, 07:48 PM
When you use ByRef in VB, you are passing a parameter by reference/pointer. That is, if the variable is modified within the procedure, the changes are reflected in the original variable outside the procedure.
void MySub(int x) {
x++;
}
void MySubPointer(int* x) {
*x++;
}
int z = 10;
MySub(z);
cout << z; //returns 10
MySubPointer(z);
cout << z; //returns 11
All this is explained much better by a decent beginner's C++ book. :)
Just fixing bad code. Maybe I shouldn't post at 3am
henszey
08-25-2002, 07:59 PM
I have been mostly learning off of http://www.cplusplus.com/doc/tutorial/ I think its really good. Do you have any recomendations for books?
Disguised
08-25-2002, 08:40 PM
Some common uses for pointers....
Accessing array elements
Passing arguments to a function when the function needs to modify the orginal argument and not just a copy.
Passing arrays and strings to functions.
Obtaining memory from the system.
Creating data structures such as linked lists and binary trees.
The List goes on........
Book recommendations....
Deitel and Deitels C++ how to program
Bruce Eckels Thinking in C++. This is available as a free e-book from his website. 2 volumes.
C++ Primer Plus and Object Oriented Programming in C++
Effective C++, more effective C++... Scott Meyers
The C++ Programming Language by Bjarne Stroustrup the inventor of the language. However, I never recommend this book to newbies. After you were to get through some of the others this would be a must read though.
henszey
08-26-2002, 01:19 AM
I have been using gpp to compile my programs on Red Hat Linux since i really dont want to buy Visual C++ if i am not sure if i want to use it or not, But what I am wondering is that if the basics of both compilers are the same. Since they are the same language i would assume so as long as i dont use any operating system dependent things.
If you have edonkey there are a lot of c/c++ books to download. I think some of them are not free so you shouldn't download those but there are some free also.
If you don't want to buy Visual C++ you can also use:
DJGPP (www.delorie.com/djgpp) is gpp for DOS so you
can compile the same in linux but run it on windows/dos plataforms
bye.
Ronq.
d1rtyw0rm
08-31-2002, 03:13 AM
Ive got a good movie for you that well explain whats a pointer
lol
http://205.151.63.123/PointerFunCppBig.avi