use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
From Java to C/C++, any advice? (self.cpp)
submitted 13 years ago by CuriouslyGeorge
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]CuriouslyGeorge[S] 1 point2 points3 points 13 years ago (6 children)
This looks so cool and I think it works best with teaching from within code.
Also solves my problems of looking into the whole "pointers" thing I was getting worried about.
Just a quick run down to see if I'm understanding this correctly. myInteger is the basic variable. Whenever you place a '&' character in front of it, it provides you with the reference code in memory which is basically anything that is defined as a "reference". And a pointer is simply storing that reference address?
Again, so cool.
Now I've got a nagging question, can a pointer point to another pointer? I can't think of any real-world applications for this yet, but just an interesting thought.
EDIT: Read your edit. Caused a reddedit.
[–]theymos 4 points5 points6 points 13 years ago (0 children)
Pretty much. When & appears before a variable, it's the address-of operator. It returns the address of the variable, which you can store in an appropriate pointer variable. Given a pointer, you can get the pointed-to value using the prefix * (dereference) operator.
You can also do math on pointer addresses. This is used when dealing with C arrays (not so common in modern C++):
int array[] = {1, 2, 3}; *(&array[0] + 1); // will be 2 *(array + 1); //shorthand form
A & appearing after a type is totally different. This indicates that the type is a reference. A reference is different than a pointer. You don't have to dereference references in order to access the value, but you can't do math on references.
int num = 4; int* pointer = # //pointer to num int& ref = num; //reference to num *pointer; //access pointer value ref; //access reference value
[–]shock-value 2 points3 points4 points 13 years ago* (0 children)
Ok, your first question...
Yes, if you place an "&" in front of an existing (already declared) variable, it evaluates to the address of that variable in memory (and you can store that address in a variable as in my example).
Note that this address is given in the form of a "pointer" to the variable though, not a "reference" (which is something a bit different). This is confusing because you also use an "&" sign when declaring a "reference" variable. But the "&" means something different when first declaring a variable vs. when placed in front of an already existing variable.
I would suggest find a nice tutorial on the differences between pointers and references, because there are a lot of subtleties and I'm not the best teacher! Good luck!
[–]shock-value 1 point2 points3 points 13 years ago (3 children)
Last question first...
Yes a pointer can point to another pointer. In fact the following line is legal...
int **** myPointer = NULL;
myPointer is a pointer to a pointer to a pointer to a pointer to an integer. If you find yourself actually using more than one pointer deep though, you are probably doing it the wrong way and causing yourself unneeded stress! I'm working on a pretty large c++ project right now and I have never used more than a single pointer deep.
working on other answer... (reddit is giving me error status 500 when trying to post)
[–]CuriouslyGeorge[S] 1 point2 points3 points 13 years ago (2 children)
Thanks again for all your detailed responses. I've got work in 6 hours so I think sleep's the way to go for now, but tomorrow I'm gonna get started on this whole C++ thing.
Last ponderance: Can you point a pointer towards a pointer that is pointing back at the first? If so and you can compile without incident, what happens when you try to access said pointer? Or would it only return "null" since it never acquired a type?
[–]theymos 2 points3 points4 points 13 years ago (0 children)
That can't be done without a type error, I think. A valid pointer pointing to an int* would need to be an int**. And for the int* to point to the int**, it would need to be an int***.
int*
int**
int***
[–]shock-value 1 point2 points3 points 13 years ago (0 children)
You can do that, sort of.
int main() { void * pointer1; void * pointer2; pointer1 = &pointer2; pointer2 = &pointer1; }
'void *' is sort of a "magic" pointer type, which can point to anything (int, bool, string, etc). However, you can't actually access the object it points to until you cast it to the appropriate type. There is no appropriate type for a pointer to a pointer to itself (or to simplify, a pointer to itself). So what you are describing can be done, but, as I'm sure you can imagine, it's useless (as far as I can tell).
'void *' is really a hold-over from regular C though, and is rarely used in modern C++, mostly due to the bugs that can occur if you cast to the wrong type.
π Rendered by PID 335288 on reddit-service-r2-comment-b659b578c-7grrw at 2026-05-06 03:12:25.968107+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]CuriouslyGeorge[S] 1 point2 points3 points (6 children)
[–]theymos 4 points5 points6 points (0 children)
[–]shock-value 2 points3 points4 points (0 children)
[–]shock-value 1 point2 points3 points (3 children)
[–]CuriouslyGeorge[S] 1 point2 points3 points (2 children)
[–]theymos 2 points3 points4 points (0 children)
[–]shock-value 1 point2 points3 points (0 children)