I have had experience with programming in C++ in the past...

I have had experience with programming in C++ in the past. Since about ten years I have come to find myself busy with C# a lot more than any other language.

In the foreseeable future I will be occupied more with C++ again. One thing I have never gained full grip of is pointers and references and I'm not sure if I ever used them correctly and meaningfully, so I am a little bit worried.

I always wondered why it is useful to apply them, as it goes against my personal sense of readability; in many other (all of them?) languages you just use "normal" parameters and variables and things work just as well.

Excuse my potentially polarizing wording, but do you think it is ok to never ever use such pointers and references when programming in C++?

Pointers are mostly used to keep references to some memory you allocated on the heap, or to point to some particular part of memory. Modern idiomatic C++ dictates you should use stack for most stuff anyway. Just be careful about copying. One of the reasons to use pointers/refs to begin with is you can pass them around functions without the need for the datastructure itself to be copied.

if you knew C# you would knew how much references are used. ask again without lying.

>One of the reasons to use pointers/refs to begin with is you can pass them around functions without the need for the datastructure itself to be copied.

I can see that this is of advantage when you have a chain of functions that belong together and instead of having one big algorithm that does a lot of calculation, you go by the design principle of readability and refactoring to break that big calculation down into little methods that each do only one thing. For this it could be handy to use a "pointered" or variable, I suppose.
Other than that I just can't see why using them would be handy.

The thing is, I'm not a die-hard programmer. I know it just well enough to do the things I want to do to. I'm not a guru, I don't know how the languages work internally.

my god, i hope this is bait.

first of all, a purely functional programming style is indeed possible in C++, but just completely voids the goddamn purpose of the language. the whole point of working with referenced parameters is to avoid copy operations, and the ability to do so is one of the, if not the, core feature of C and C++. in other words: if you feel incapable of correctly using pointers and references, that means you're incapable of working with memory management in your head, which in turn means you should not be programming in unsafe languages. period.

it is, however, not that hard to wrap your head around. here's a few hints:

- a pointer is the address of some memory you can work with. pointers are most commonly used for heap allocated memory, which you should rarely come across when working according to modern best practices. this is of course not true if you're working with UI frameworks, which commonly use raw pointers to tie UI elements together, but it is true if you work mainly with the STL and style compliant libraries. RAII is your friend here.
- references are essentially aliases for things. a references, unlike a pointer, can never be empty and is by definition immutable, i.e. it always has to point to something and can then never be made to point somewhere else. use references whenever possible with any data that is not POD (plain old data), i.e. not int, float, double, char etc.
- avoid double raw pointers as they are the C way of expressing "address of array" and inherently unsafe. it is generally better to use zero cost abstractions like std::array or std::vector (which is zero cost considering it replaces the interface for reallocation array memory in C). more succinctly put, you want to avoid ** in favor of std::vector &.

it's really not that hard, but if you're not using referenced memory, there's really little point in using C++ at all.

if you're not an expert and have no intention of being one and you have no intention of using the core features of the language - nor the need to do so - why would you put the burden of C++ on yourself? just stick with something safe where you don't need to understand ownership concepts. stay with C#, go with Java, or if you have any possiblity at all, make your life nice and use Python.

Are you using the word "reference" the same way he's using it?
He's talking about pointers. You can technically use pointers and references in C# e.g.:
int x = 5;
int *ptr = &x;
But that's definitely not something most .NET programmers are going to bother doing.

thank you all for the elaborate answers!

if you learn assembly language and have to touch the memory more directly, the concept of pointers should become more clear to you

...

One situation where you more or less have to use pointers is when you want polymorphic behavior in a derived class. Also, some people will tell you that you should never use "raw" pointers, but instead always use a smart wrapper class like std::auto_ptr.

Things "work just as well" because those languages hide the implementation from you. Many languages always pass by reference for instance and that's not always good

C++ gives you full control. If you don't want to use pointers or references, go ahead. But you will pay a performance penalty. Learn them or you do not understand C++ that's all there is to it

Note that C++ is a thin layer on top of C which is a thin layer on top of assembly. It doesn't handle anything special for you

>Since about 10 years
Pajeeeeeet

>do you think it is ok to never ever use such pointers and references when programming in C++?
Assuming you picked C++ for the job because it was appropriate for the job, i.e. you needed to be able to reference data without copying it. In that case you won't be able to do anything useful without them
Pointers are taught wrong in books and it confuses the everliving shit out of people because they try to distinguish between pointers and data as if they are different. It's a shame, because pointers are actually nothing more than unsigned integers that happen to be memory addresses.
And C++/C# references are exactly like pointers except they are immutable.

>literally too stupid to even understand concept of pointing at something.

>C++ is a thin layer
kek

this is actually clearer than many C++ books

>I always wondered why it is useful to apply them,

So you don't have to copy the data (say of an XBOX huge array) and just point to its memory location. Sending the address (a number) by a pointer is much faster.

>in many other (all of them?) languages you just use "normal" parameters and variables and things work just as well.

In other programming languages, everything is just passed by reference.

>Excuse my potentially polarizing wording, but do you think it is ok to never ever use such pointers and references when programming in C++?

No.

actually, the majority of languages defaults to passing by value, not by reference. some offer passing by reference through special syntax.

WHERE ARE THE MODS WHY IS THIS THREAD STILL ALIVE GO TO

>Modern idiomatic C++ dictates you should use stack for most stuff anyway
have fun fitting all your shit into 2MB of memory