Public Group

# Shameful noob C++ question

This topic is 5037 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have been programming in C an Java for a while, and am just reading through a tute on C++ so most stuff is fine. One thing I dont get, however, is the difference between references in C++ and pointers in C when it comes to passing arguments to functions. In C (pointer) int x = 5; y = func(&x); where func prototype would be: int func(int*) In C++ (reference) int x = 5; y = func(x); where func prototype would be: int func(int&) Other than a notational difference, is there any difference between these methods? Can I still do the C method in C++ (I could test that out in a minute)?

##### Share on other sites
This might be a good read. Enjoy ;)

##### Share on other sites
Well pointers are more like a special kind of structure with * & -> operators for accessing where they point. References can be linked to one single object upon initilisation & you basically treat them asif they were that object. Also they attach only by reference (value) so passing the address would be no good.
char message[]="testing";reference(message);pointer(message);void reference(char &character){  ++character; // would increment the value. result: "uesting"}void pointer(char *character){  ++character; //would increment the pointing address of this local pointer}

You cannot edit where a reference goes once it has been linked because it just that - a link. infact most compilers should substitute it for the variable itself when it's compiled, so no new variable is created & no copying occours like a normal pointer. It's good that you're interested in references. use them whenever you can, they totally rule ;]

##### Share on other sites
Quote:
 Original post by visageThis might be a good read. Enjoy ;)
100% clear now. Thats a good site with alot of other useful info as well. Thanks

##### Share on other sites
Even though this problem appears to be solved, I just thought I'd step in and offer a little pointer. (pun intended [smile])

There is NO SUCH THING as a 'shameful noob question', especially not when it's regarding C++. EVERYONE was a newbie at one point, and when you don't know something, you don't know something, and there is no shame in asking for help, especially with something so complicated as a programming language. Heaven knows I did a lot of that [grin]

Cheers! If you ever have problems, don't hesitate to ask (provided you can't find the answers on your own of course)!

##### Share on other sites
You know its always so nice here. Who would have thought programmers would make such nice people!

##### Share on other sites
Since SirLuthor commented on this, one other even much more important thing about the topic title is that it doesn't say anything. Topic titles exist to describe the problem, so it's more easy for people to decide if they want to read it or not. "N00b problem" doesn't describe anything, we already know you have a problem. You should name your topics like "Differences between C++ pointers&references" or something like that. Read the FAQ for more infos about how to make good posts.

##### Share on other sites
And in addition to what mikeman said, you posted in the "beginner"-section, so there is no need to repeat that in your thread-title. Instead you should make it as easy as possible for those kind souls who are to help you by naming your thread something descriptive. :)

##### Share on other sites
I have been posting here for a while now and usually I am in the graphics programming theory section. The reason why I gave the thread the title I did was because I have been programming for years doing quite complex stuff and this is something that i really should have known by now, so its a bit embarrasing that I didnt.

Other than that, yes I agree the thread should have been better named, i usually do use sensible titles, but I will be more careful next time.

1. 1
2. 2
3. 3
4. 4
5. 5

• 14
• 9
• 9
• 10
• 12
• ### Forum Statistics

• Total Topics
632911
• Total Posts
3009183
• ### Who's Online (See full list)

There are no registered users currently online

×