Void Pointers | C Programming Tutorial

Поділитися
Вставка
  • Опубліковано 24 січ 2025

КОМЕНТАРІ • 53

  • @StreuB1
    @StreuB1 Рік тому +16

    You honestly have a gift for teaching this stuff. Typecasting is an obtuse topic at times and a typecast pointer is very obtuse. I've never really understood them and how they are used, until now.

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

      Thanks so much for the kind feedback Brian, and I'm glad the video was able to help clear that up for you! :-)

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

    when it's great, it is always great and always will be. The pointers were my roadblock until now, but things have become smoother and I can follow without fear. Thanks, Kevin, for the great effort which is priceless.

  • @siya.abc123
    @siya.abc123 Рік тому +5

    Another complex topic explained simply. Thank you for all your teachings. Your teaching style is top tier

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

      You're very welcome Siya, I'm glad you enjoy the videos! :-)

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

    holy crap not to be weird but im high and i was literally just wondering about void pointers and your video just came out so this is great!! thank you!!
    also your tutorials are so helpful. i greatly value the knowledge you impart.

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

      Hahaha I had a weird feeling that "today, I should make a video on void pointers", maybe it was destiny! :-) You're welcome Anthony, I'm really glad to hear you enjoy the tutorials.

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

      😂 cheers

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

      @@PortfolioCourses "Destiny is all " : Uhtred of Bebbanburg.

  • @GianlucaSibaldi
    @GianlucaSibaldi 2 місяці тому

    Awesome tutorial! 😃
    To be even less ambiguous I always prefer to attach the star to the type, I mean:
    int* p = &a
    instead of
    int *p =&a.
    This way in my opinion it’s very clear that the variable type is “int pointer”. And this way also you make a clear difference between the way you declare a pointer variable and the way you deference a pointer variable. Which I often noticed leads to some initial confusion at the early stages of understanding pointers.

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

    I found ur videos about c and u are an absolute genius in explaining things! Thank u so much for ur content!

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

    Extensive explanation about this topic, Thanks Kevin.

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

    the GOAT in c

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

    I was curious if you will mention that pointer arithmetic on void pointers is illegal according to ISO C. You did mention it!
    Excellent tutorial! Thank you so much!
    If we don't need a cast after malloc in C, can we use the following syntax to keep the instruction more generic?
    int* ptr = malloc(n * sizeof(*ptr));
    (No need to adjust the right side of the assignment if the pointer type of "ptr" should change).
    Is this legal according to ISO C?
    Would you do it the same way professor?
    Thank you very much!

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

      You're welcome! I'm not sure if that's legal according to ISO C, though it seems to compile OK in gcc at least and I don't see why it would be illegal. I don't know if I would do it that way or not, I think if I was changing the type of 'ptr' anyways, then it might not be a big deal to change the sizeof() as well. On the other hand it's nice to only have to change one thing, so I think it may depend on the situation.

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

      @@PortfolioCourses Ok! Thank you very much!👍

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

      You're welcome! :-)

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

      @@PortfolioCourses I found it in the Standard (the latest one).
      Page 82 (Not the PDF page, but the page number that the document itself lists).
      6. 5. 3. 4 The sizeof and alignof operators
      Paragraph 6.
      I would like to post the link, but then UA-cam deletes my post.
      There is also an example on "cppreference" in the chapter malloc.

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

      ​@@starc0w Yes I have seen examples like this on "cppreference" and according to ChatGPT the sizeof operator does not need to
      dereference ptr to determine its size, it only needs its type.

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

    Again, great video!
    I see the void pointer as a multi-type pointer with some restrictions.
    When I 'malloc' memory, I use the data type(s) to format the memory to the desired type in pedagogical way.

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

      Thanks! :-) I always think of void pointers as something like "polymorphic behaviour" in C programming.

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

      @@PortfolioCourses I think it's because you are an IT-professor and I'm absolutely not... :o)
      Your pedagical skills are also great and not many are capable of combining these two very diffrent tasks in a good way.
      I'm actually have dyslectic issues, but your very clear voice makes the learning much easier.
      Sorry for my English.

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

    If I saw *((char *)p) before, I'd definitely freak out! Thanks for your videos, this is no longer the case.

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

      Me too and the difference between making a pointer and get the value from a pointer.

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

      You're welcome, I'm glad the video helped with that! :-)

  • @NikolaNevenov86
    @NikolaNevenov86 Рік тому +2

    To me the whole thing with pointers devolves to simply memory access. A type pointer will read the memory address depending on the type(int* will read 4 bytes and will decode the bits as int). A void pointer is a typeless pointer, it holds a memory address but does not know what is there. I think the fact that all pointers(regardless of type) are of the same size was a big eye opener to me.
    That being said, when we are moving the void pointer via pointer arithmetic, then the movement acts like that of the char* where each move is done in 1 byte * n . A type pointer will move depending on it's type, like a int* will move 4 bytes.
    Thus recently I wondered if there is any benefit to a void pointer since it acts like a char*. Of course one of the benefits is that it's typeless and thus can be a pointer to any type. Making it more universal.

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

      I agree that the size of all pointers being the same is a big eye opener for people as to 'what pointers are really doing'. :-)

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

    Nice explanation, thank you Kevin.

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

      I’m glad you enjoyed it Firas, and you’re welcome, I hope you are well! :-)

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

    Thank you so much for great explanation

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

    Would you mind making a playlist on all the pointer videos you've done so I can follow them chronologically?

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

    Great stuff as always.

  • @MultiScott1000
    @MultiScott1000 7 місяців тому

    nice explanation. thanks.

  • @Joao-oo8yj
    @Joao-oo8yj 6 місяців тому

    I did understand pretty well this thing about pointers... but I was wondering why the heck the function `qsort` you show in the video takes a pointer parameter which type is void*? `qsort` is gonna iterate over each contiguos address of the array, but how will it do that if the pointer type is void* which doesn't accept arithmetic operations?

    • @PortfolioCourses
      @PortfolioCourses  6 місяців тому

      You provide a function to qsort, and that function does the comparisons, typically using a typecast to convert from void * to something you can do comparisons with.

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

    Is it fair to say that, when you “p is pointing to a memory address if any type of data” for void *p that we could also say: “p is pointing to a memory address that can hold a data type of any size”? If I am thinking of a memory address (size depending on the hardware if course) then it is a series of bits that are either high or low…and the data type tells us (in addition to helping write correct programs) how many bits we can store there? or am I taking my microcontroller class (in assembly) too seriously? 😅

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

    Great video

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

    hi can you make a video about serial communication in c?

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

      I've never done serial communication before Ozkan, but thank you for the idea you never know maybe one day I can cover it, I'm looking into it now and it's interesting. :-)

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

      @@PortfolioCourses 😁

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

    please could you do an example using _Generic keyword??

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

    Saw a video of something similiar to manipulate floats, i think it was indirection or something… like this:
    float a;
    uint32_t temp = *(uint32_t*)&a;
    then manipulate the bits on the float and cast (float*) on it again

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

    Nice

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

    Dear Professor
    Since you usually replied soon, I suspect you missed my message below. :-)

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

    awesome bro plz cont.....

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

    So why not using only void pointers!? Any disadvantages in size of such pointer?

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

      Great question! :-) When we use a double pointer, and do pointer arithmetic, the compiler will adjust the pointer arithmetic to make it work for the size of a double (and this goes for any other type). With void pointers, this won't work. Typed pointers also allow the compiler to give us errors/warnings if we try to use them in ways that are unexpected.