Fixed and Variable Length Arrays in C and C++

Fixed and Variable Length Arrays in C and C++

Jacob Sorber

3 года назад

43,745 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@soniablanche5672
@soniablanche5672 - 04.01.2024 01:52

careful with realloc, this might cause memory leak if realloc failed. if realloc fails it returns null so now you lost a reference to the older pointer if you do p = realloc(p, newsize).

Ответить
@pavolkucerak6011
@pavolkucerak6011 - 19.09.2023 00:33

Jacob, thank You for this and for other videos.

Ответить
@user-ot5xm7ye1v
@user-ot5xm7ye1v - 14.09.2023 19:46

Супер

Ответить
@BinGanzLieb
@BinGanzLieb - 27.06.2023 11:35

when you use realloc, the old 15 integers are deleted and the system allocate 20 new integers somewhere in the memory space

Ответить
@mintesnotteshale7705
@mintesnotteshale7705 - 16.03.2023 22:10

why we cann't assign array for an other array directly?

Ответить
@chefskiss651
@chefskiss651 - 08.03.2023 03:31

How would I go about creating a large array that uses the input and a loop to initialize the variables, while not having to initiialize my entire array.
For example: My array can contain 30 integers, but at some point I decide to only initialize 10 of them. How can I do this without having to just change the size of my array.

Ответить
@stdint.h
@stdint.h - 28.08.2022 17:26

The fact that for every single topic you say "if you are confused, I have a video on that" shows how good and complete your content is. Great job.

Ответить
@tannerted
@tannerted - 10.08.2022 20:02

Jacob, thank you for your insightful videos. I’m not certain, but I think we are both members of the same church (I can sorta just tell).

Could you make a video covering how variable-length arrays can be unsafe because they can overrun the stack? Also, it might be good to point out that the compiler will need to use dynamic sizing of stack frames rather than static sizing if you use VLAs, which can lead to some performance issues under some rare circumstances.

Ответить
@diegoporras7769
@diegoporras7769 - 01.08.2022 03:20

Great content! Thanks

Ответить
@shimadabr
@shimadabr - 04.07.2022 03:45

I was hoping you would talk about 2d variable length arrays. I'm having a hard time initializing and using them, specifically a 2d VLA of structs.

Ответить
@MECHANISMUS
@MECHANISMUS - 03.06.2022 16:12

...And I'll C/C++ you then.

Ответить
@anon_y_mousse
@anon_y_mousse - 26.04.2022 15:04

One of the reasons not to mix new/free and *alloc/delete is because of class/struct constructors/destructors. If you have an array of, or a single of, any intrinsic type, it would likely work, but still do <b>not</b> do it.

Ответить
@leviwillrich2637
@leviwillrich2637 - 03.02.2022 01:37

Arrays? No thanks. I prefer a raise (I don't get paid enough

Ответить
@xXDvitorxXD
@xXDvitorxXD - 12.01.2022 17:53

I'm a begginer in C/C++, can someone explain me how to resize an array/pointer size at run time? E.g. I create an char array/pointer with size 10 and I ask the user their name, let say their answer is bigger than 10, how can I avoid an error/overflow?

Ответить
@MrZauberwuerfel
@MrZauberwuerfel - 11.11.2021 05:09

I have a question:
For example I have a struct named Student and declare: struct Student student[100]; (or *student[100]?)
Can I have different sizes for: char student[0].name[?] ?
Essentially I want to have a larger array, if the students name is longer. Is this possible? Or do I just have to find the maximum length and then waste some space?

Ответить
@shawnmelody8346
@shawnmelody8346 - 04.11.2021 02:47

So glad I found your channel. Clear and understandable English, no blaring music in the background, or the opposite (like watching a silent movie in
super-speed...lol 😁). Very instructional, informative and engaging to say the least! Kudos! Thanks for the awesome work you put into such a great channel.

Ответить
@christophervaldez2986
@christophervaldez2986 - 30.09.2021 04:37

What IDE/environment is this?

Ответить
@aabdev
@aabdev - 22.08.2021 00:21

What is differential between C11 and C99?

Ответить
@wassimboussebha2561
@wassimboussebha2561 - 09.08.2021 00:23

can you please talk about 2d arrays ? from a C programmer prospective ( including pointers , addresses .. )

Ответить
@HimanshuSharma-sd5gk
@HimanshuSharma-sd5gk - 26.02.2021 05:38

Plz plz answer this question sir..
For passing multidimentional array to function how valid is to use
void function(int x, int y, int array[x][y]);
This worked fine on my system.
I am himanshu sharma from india

Ответить
@neillunavat
@neillunavat - 22.02.2021 12:23

how to return dynamic arrays from functions in C? (no resources found for this) (beginner programmer in C here...)

Ответить
@arielspalter7425
@arielspalter7425 - 15.02.2021 06:55

Good stuff, thank you! Subscribed. I find that if I feel like doing some low level stuff, C fits my style much better than C++. It's simple and to the point. Modern c++ is so cumbersome and it puts me off. Otherwise, I'm happy with C#(-:

Ответить
@sukivirus
@sukivirus - 12.02.2021 10:13

Loved it. I would love to learn compiler/interpreter design. May be create scripting language for my programs in C using C. I just love the way you try things in C. I am enjoying it :)

Ответить
@moseschristopherb
@moseschristopherb - 06.02.2021 23:01

Your videos provide a lot of clear information. I've learnt a lot from your content. It's really amazing.
Thank You so much.

Ответить
@belesiu
@belesiu - 28.12.2020 08:21

Is c++ relevant for embedded system programming on small controllers? If so, then yes, let’s learn vectors and containers!

Ответить
@seanmacfoy5326
@seanmacfoy5326 - 27.12.2020 03:28

Since you mentioned older C standards didn't allow it, is there any overhead (apart from fetching from memory) associated with dynamically allocating an array with the value stored in an integer variable?

Ответить
@tanyasinghal3981
@tanyasinghal3981 - 23.12.2020 11:21

please make a video on vectors

Ответить
@adrianniebla
@adrianniebla - 22.12.2020 03:49

Just found your videos, and OMG thank you so much I have learned so much, your videos are so informative and the knowledge is great.

Ответить
@senorpesadillas
@senorpesadillas - 19.12.2020 13:45

Thank you for this!

Ответить
@khankashani7387
@khankashani7387 - 11.12.2020 00:30

Hi dear professor, do you have any C++ 20 tutorials????? Can make C++ tutorials PlesssssssssssssssssssZZZZZZZZZZ!!!!

Ответить
@anshul493
@anshul493 - 07.12.2020 13:02

hey:
to get the sizeof array: do
```{c}
int length=sizeof(array)/sizeof(array[0]);
```

Ответить
@moeaj1536
@moeaj1536 - 30.11.2020 05:34

We want more c++ videos ❤️

Ответить
@ctobi707
@ctobi707 - 29.11.2020 17:32

so a variable length array is a dynamic array under the hood?

Ответить
@ng3773
@ng3773 - 21.11.2020 18:54

Hi Jacob, are you planning to do some C++ tutorials?

Ответить
@sollyprogrammer3750
@sollyprogrammer3750 - 17.11.2020 09:31

I really like your videos. It helped me a lot. Please can u make tutorial videos for nasm?. Just for beginner!
I have tried to see it but i didn't understand anything

Ответить
@AwesomeSauceChris
@AwesomeSauceChris - 15.11.2020 23:47

I've recently revisited C/C++ having not really done much with it in about 15 years. Your videos have really helped strengthen my fundamentals and brush off a lot of the cobwebs. Thanks for that!

If you decide to cover some C++ topics, I'd love to see some stuff on the nitty gritty of streams. I can implement something using them but always felt that I've got a bit of a blind spot with what's going on under the hood.

Ответить
@amoghmund
@amoghmund - 15.11.2020 20:53

Can U ref to or create a video on handling charsets like utf8 utf16 in C

Ответить
@sumdim6427
@sumdim6427 - 15.11.2020 08:09

Hi! Jacob🙂. I learned a lot from your channel. I was having trouble about learning and using variable argument list when implementing printf for school project. After watched your video(the video is just about 4~5 minutes long, simple and straight to the point), Things came clear to me. I realized It is actually not that complicated.

Thanks for the helpful content!

I think It would be really helpful also if you can make a video about writing unit test, what general, edge case we should be careful for, (this may sound broad), and tool we can use, etc...

Ответить
@csbnikhil
@csbnikhil - 14.11.2020 09:29

Wouldn't myarray[5] in the function parameter be cast to just be a pointer to an int?

Ответить
@minhquando100
@minhquando100 - 14.11.2020 07:34

I would love to see a video on smart pointers in C++. Specifically how they work under the hood and what are some good use cases for when we should be using smart pointers and when not to use smart pointers. Also if possible, can you do a video on memory checking tools like valgrind? Great videos by the way!

Ответить