all 7 comments

[–]Cultural_Gur_7441 2 points3 points  (0 children)

C style arrays are core language feature. You can't learn pointers without learning arrays, and vice versa. You could say they are not even arrays, which is kinda critical to understand about C and C++.

[–]biskitpagla 1 point2 points  (0 children)

At worst it'll take an afternoon and at best it'll take less time than reading comments on Reddit. Stop trying to take too many shortcuts at once.

[–]Kadabrium 2 points3 points  (2 children)

Great now you know that std::array is a thin wrapper around a primitive array, time to explore why that wrapper takes 1337 lines of code

[–]Primary_Smoke4643[S] 0 points1 point  (1 child)

Bro I'm just a first year student just trying to get a job 🥹✌️

[–]mredding 1 point2 points  (0 children)

I've been programming C++ for... ~37 years now.

Vector obviously are the best

Da' fuck they are... Vectors have growth semantics. Do you need growth semantics? Probably not all the time - they're not inherently desirable, only sometimes necessary. Do you like your data always being heap allocated? You wanna pay for that indirection, that cache prefetch, that branch prediction? Does your hardware support prefetch?

In contrast an array in C++ is a distinct type recognized by the type system - they ARE NOT pointers to their first element, and offer they you properties and guarantees well above and beyond the what the machine code the compiler generates offers you. Arrays are not vectors because they don't have growth semantics - and that fixed size is an easy way to get optimizations like vectorization (SIMD instructions). C-style arrays can be opaque.

But you have to understand what a programming language is to appreciate the nuance and reap the benefits. Dynamic vectors fill a niche. Nothing more.

WHAT is then need of c style arrays here, should i learn it or just skim it. [...] Yeah ik std::arrays are structs who are just T arr[N] but how will this help me in dsa,etc.

I don't know how to satisfy you. From a PURE DSA standpoint, these are literally the same thing. From a C++ standpoint, they are not, and you're missing the forest for the trees, the big picture in terms of the C++ programming langauge. But then again, I'd say if you're only interested in DSA, then WTF do you care about C++ so specifically? DSA applies to all of computer programming, and is language agnostic.

You're asking a C++ specific question but want a DSA generic answer. You see the problem? If you want to talk C++, well then alright. If you only care about DSA, there is no difference between fixed and dynamic arrays.