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

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ก.ย. 2024

ความคิดเห็น • 19

  • @PortfolioCourses
    @PortfolioCourses  ปีที่แล้ว +6

    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. 🙂

  • @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.

  • @wonderfulworld2475
    @wonderfulworld2475 6 หลายเดือนก่อน +1

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

  • @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! :-)

  • @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: th-cam.com/video/R0qIYWo8igs/w-d-xo.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: th-cam.com/video/ssJY5MDLjlo/w-d-xo.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: th-cam.com/video/vr7qCQLrUt8/w-d-xo.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. :-)

  • @deczhu3425
    @deczhu3425 6 หลายเดือนก่อน +1

    memcpy or memmove

  • @mayanksrivastava7540
    @mayanksrivastava7540 7 หลายเดือนก่อน

    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 7 หลายเดือนก่อน

      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.

  • @cowdumdum
    @cowdumdum ปีที่แล้ว

    thanks for the video

  • @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. :-)