Arrays in C++ Understanding Decay and Pointer Conversion

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

I aspire to write c++ of the top of my head like you. We recently switched from js to typescript at my job and am having a lot of fun with types. Because of this i recently got into c++ and it is a beast. Ive watched your other videos and your clearly very skilled at many languages and have a great understanding of many different aspects of computer science. How did you get so good at it and learn how to be so resourceful?

leviwins
Автор

Good answer... You stated which language YOU like, but clarified that whatever we chose doesn't really matter

I'm really enjoying you channel

GoWokeGoBroke
Автор

So why not use some struct which contains a pointer to the array as well as the size so you always pass around both?

danielschmid
Автор

Stack alloc arrays have a constant size at compile time right? Just heap allocated ones can have dynamic size, and the function receiving the array (pointer) just goes to the heap. That way arrays basically don't do any pass by copy of the array on the stack, but instead pass a copy of the pointer to the array to the function. so shouldn't an array always be pass by const ref?

AgentM
Автор

Arrays and pointers are different by one level of indirection, examine the assembly source code generated by the compiler and you will understand what I mean.

HoSza
Автор

Then where is that length info useful? Why aren't arrays just pointers?

I'm a beginner to C so I don't quite understand

WlfCL
visit shbcf.ru