r/cpp_questions • • 23h ago

SOLVED Performance of std::vector

26 Upvotes

In the university we had to implement quicksort, the unsigned ints are stored in std::vector. I have accidentally discovered, that all algorithms, despite how students implemented them, are much faster when instead of directly accessing data from the vector like that:

arr[n]

we write:

unsigned int *a = arr.data()

and access that data by writing:

a[n]

But I can't understand why is that, in both cases it translates to one and the same: *(a + n)

The code is compiled on Clion IDE if that changes anything, no custom settings for compilation are used.

I can't directly share the algorithms for copyright reasons as they are not mine.


r/cpp_questions • • 22h ago

OPEN Is there any free interactive learning like rustlings/ziglings for cpp?

13 Upvotes

I find rustlings/ziglings to be really strong at helping me learn concepts and have it stick.


r/cpp_questions • • 5h ago

OPEN Where to start learning C++?

11 Upvotes

Hi everyone! I want to start learning C++, but I’m not sure where to begin. As my first goal, I plan to build a simple 3D viewport to understand how everything works in practice. Could you please advise on where a beginner should start?


r/cpp_questions • • 10h ago

OPEN How to learn c++ effectively and be profficient in it?

7 Upvotes

Maybe you've heard this question before, but I want to know. I've been studying c++ for a month now, and I feel like I know some of the basics, but I know that I need a different approach. I feel like I just memorize it instead of getting it. I want to learn it truly,the right way. I write a lot of code cause I know thats the best but I fall short on the thinking like a programmer part. I want to lean c++ independently,then switch to ue5 and work on a game. I would love it if you would share your methods and links to some good c++ literature. I know I'm not dumb and I know it's not easy. I am not looking for a quick solution, just the right one.


r/cpp_questions • • 17h ago

OPEN What is the best way to learn C++ for control theory implementation? Should I learn python or C++?

2 Upvotes

My background:

I'm a 5th year mechatronics engineering student that is good with matlab/simulink and is looking to expand my skills for my future career in automation/control/robotics.

I already know the basics of C++ from the course I took in college. Also, I am pretty good at 86 assembly programming. I heared that python is only used for simulations but that is what I use matlab/simulink for.


r/cpp_questions • • 11m ago

OPEN Как устанавливать сторонние библиотеки на С++?

0 Upvotes

Hi everyone! I’m learning C++ and have a question: how do you install third-party libraries? For instance, in Python, you just type `pip install` in the terminal—what’s the equivalent for C++?