Delete An Array Element At A Specific Index | C Programming Example

Поділитися
Вставка
  • Опубліковано 1 жов 2024
  • How to delete a value at a specific position in an array using C (i.e. delete an element stored at a specific index). Source code: github.com/por.... Check out www.portfolioc... to build a portfolio that will impress employers!

КОМЕНТАРІ • 19

  • @PortfolioCourses
    @PortfolioCourses  Рік тому +7

    Note that this is a simple program for learning how to delete an array element, so we don't do any input validation. We could check to make sure that total entered is less than MAX_CAPACITY and greater than 0 using an if statement for example. We could also add a check to ensure the user entered an int value at all instead of something like "abc". But these things are left out of this video to focus on the problem of deleting the element. 🙂

  • @deczhu3425
    @deczhu3425 6 місяців тому +1

    memcpy or memmove

  • @wonderfulworld2475
    @wonderfulworld2475 6 місяців тому +1

    Thank God for Java & Python with their string & array functionalities.

  • @OCEAN-fc9wl
    @OCEAN-fc9wl Рік тому +3

    Had a C programming exam yesterday and your videos helped me a lot!

    • @PortfolioCourses
      @PortfolioCourses  Рік тому +1

      That's awesome! :-) Thank you for sharing that with me, the biggest reason I love making these videos is that they might help students and beginner programs, so it's excellent for me to hear that the videos helped you out.

  • @naboulsikhalid7763
    @naboulsikhalid7763 Рік тому +1

    Unbelievable, so clear and understandable. thank you

    • @PortfolioCourses
      @PortfolioCourses  Рік тому

      You’re welcome Naboulsi, I’m glad the video was clear and understandable for you! :-)

  • @mayanksrivastava7540
    @mayanksrivastava7540 8 місяців тому

    I am sorry but how are we supposed to account for the last element in array because the declaration which we initially did(arr i = arr (i + 1) ) will work for every element except for the last element . This will happen so because the last element is supposed to be given a value which is not even there in array .
    It would be great if you could clear my doubt . Thank you!

    • @safaabdalah3317
      @safaabdalah3317 8 місяців тому

      He answered it in the video and he actually brought up this very scenario. Because we are keeping track of how many elements are in the array even if there is still an element at the end we dont have to deal with it. When we print out whats in the array it will only print out 5 elements even if there is a 6th element in there at the end.

  • @fabimawn
    @fabimawn Рік тому

    I started learning C this week after mastering Lua, and if I watch BroCode's C course, and want to know all the specifics of a something in C, you are now my go to!!!. I got some questions though. I understood that besides setting pointers to NULL, there is no way besides ASM to wipe them out of RAM (or allocating space to the adresses again), now here in this video example if you want to delete an element, you can't really from what I understood. When writing a program that might generate milions of new variables, and deletes others every time, doesn't RAM slowly fill up? How is that generally managed?

    • @PortfolioCourses
      @PortfolioCourses  Рік тому

      We use what's called dynamic memory allocation to make sure that RAM does not "fill up". We allocate space to store data, and then when we are done working with it, we can free the space using free() to make it available again for other uses. This video covers dynamic memory allocation: ua-cam.com/video/R0qIYWo8igs/v-deo.html. Also, I'm sure BroCode's C course is great, but just you know this is a full course on C you can watch too: ua-cam.com/video/ssJY5MDLjlo/v-deo.html. :-)

  • @USAmerica-777
    @USAmerica-777 Рік тому

    I have a question: Is there a way to get rid of the last trailing element after the data is shifted forward? The "4" still remains in memory at array[5] after the data in the array is shifted. Is there a way to free the array[5]?
    Also, I wanted to say I have been watching your videos since last semester lol. And thanks to you I have been able to pass all my classes. I am taking Data structure and Algo this semester. I definately feel my skills have improved and its all thanks to u! You have all these videos on how to do basic things in C; if i get confused I come here to your channel and I know what needs to be done. Thank you for these videos!

    • @PortfolioCourses
      @PortfolioCourses  Рік тому +3

      Great question! :-) We could set the element to 0, or some other special value that we interpret as "unused". But we can't really free the memory for that element when we have an array on the stack. If we were using dynamically allocated memory, we could use realloc() to decrease the size of the array. This video covers realloc: ua-cam.com/video/vr7qCQLrUt8/v-deo.html. And thank you so much for the kind feedback, I'm really glad to hear you enjoy the videos. My biggest motivation for making this channel was to reach and help out students like you with their programming classes, so it really means a lot to me to know these videos have helped you out. :-)

  • @pranavc747
    @pranavc747 Рік тому +1

    Python users be like: pop()

    • @PortfolioCourses
      @PortfolioCourses  Рік тому +3

      It's wild, I know they are different languages that typically solve different problems, but every time I go to make a Python video I'm reminded just how easy it is to do simple things compared to C. It's like driving a car in manual vs automatic. :-)

  • @cowdumdum
    @cowdumdum Рік тому

    thanks for the video