struct Basics | C Programming Tutorial

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

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

  • @PortfolioCourses
    @PortfolioCourses  8 หลายเดือนก่อน +17

    Also note in this video when we assign y to x, this would *also* be a memory leak, which is bad! 🙂 I was trying to stay focused on structs in this video, but this other video covers memory leaks which are important to avoid: th-cam.com/video/lQCLAKfcYI4/w-d-xo.html.

  • @OCEAN-fc9wl
    @OCEAN-fc9wl ปีที่แล้ว +135

    This channel is awfully underrated. Respect.

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

      Thank you so much for the kind feedback, I really appreciate that. :-)

    • @SIGSEGV200
      @SIGSEGV200 9 หลายเดือนก่อน

      frfr

  • @daishakpatel224
    @daishakpatel224 2 ปีที่แล้ว +51

    There can't be a better video on structs other than this one on youtube. Pretty much everything covered in one video.

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

      Thank you for the positive feedback Daishak, I'm glad to hear you enjoyed the video! :-)

  • @Peter_1986
    @Peter_1986 ปีที่แล้ว +2

    Structures confused the hell out of me when I started reading about them;
    this video made them much more clear.

  • @togotog1330
    @togotog1330 ปีที่แล้ว +8

    This channels quality content gonna be remembered for generations he teaches clear and concise thank you sir for your service to this populace

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

      Thank you very much for sharing such positive feedback, that really motivates me to keep going with these videos! :-)

  • @naparcasc
    @naparcasc 10 หลายเดือนก่อน +3

    Very clear explanation about how pointers contain a reference to some area in memory and not the content of that memory area itself and why you need to be extra careful when reasigning pointers. Thank you so much for your work!

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

    this is the best c tutorial in entire youtube, i have been searching for months and now got the best content for c, thank you so much man

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

    My teacher is totally useless. This channel is the only thing, keeping me from failing. Thank you so much, you have a knack for explaining hard material so a noob can understand it.

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

      You’re very welcome, I’m really happy to hear you’re finding the channel helpful! :-)

  • @Algebraiic
    @Algebraiic ปีที่แล้ว +9

    Once again an EXCELLENT tutorial!
    You really make me love C, honestly.

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

      Thank you very much for the positive feedback! :-) And I’m glad these videos are encouraging your own enthusiasm about C, I definitely love using it!

  • @mah-b
    @mah-b ปีที่แล้ว +1

    using this video to study for structs on my next exam and you made everything super clear holy crap

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

      I’m glad the video made everything super clear, and good luck on your final exam! :-)

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

    This is perfect. Thank you. Pretty much everything you need to know about structs all in one easy to understand video.

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

      You’re welcome! Thanks for sharing that you enjoyed it, that’s excellent to hear! :-)

  • @nephewtechnologies
    @nephewtechnologies 9 หลายเดือนก่อน

    After you explained struct I was about to leave to find a video about typedef then you explained it. Great video!

    • @PortfolioCourses
      @PortfolioCourses  9 หลายเดือนก่อน +1

      I'm glad you liked it! :-)

  • @undercoverz99
    @undercoverz99 9 หลายเดือนก่อน

    its crazy how such high quality material is hidden on the internet. your videos should have millions of views!

    • @PortfolioCourses
      @PortfolioCourses  9 หลายเดือนก่อน

      I’m glad you enjoy them! :-)

  • @lradhakrishnarao902
    @lradhakrishnarao902 2 ปีที่แล้ว +2

    You have explained the topic of shallow copy operation very well.

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

    Omg thank you so much, this is so much better than two two hours lectures i had on structs...
    I have an exam next week and gonna watch the other videos on pointers and strings if you have any❤❤❤

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

    wow, struct fully explained. Thank you for helping me and others to understand what you r self strive for.

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

      You’re very welcome Naboulsi, I’m glad the video helped you out! :-)

  • @dollyguarana7077
    @dollyguarana7077 11 หลายเดือนก่อน +1

    I've learned so much about C these last two/ three months thanks to you :)! Muito obrigado pelos seus vídeos!!!

    • @PortfolioCourses
      @PortfolioCourses  11 หลายเดือนก่อน +2

      I’m so glad to hear these videos are helping you out, thank you for sharing this! :-)

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

    This is by far the best video on struct, very good content.

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

      I'm glad that you enjoyed it, and thank you for sharing this positive feedback! :-)

  • @phytoplancton4038
    @phytoplancton4038 ปีที่แล้ว +1

    you are my favourite teachher so far thank youuu

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

      Wow, thank you so much, you're welcome! :-)

  • @nunomartins467
    @nunomartins467 ปีที่แล้ว +3

    I wanted to ask something about the data struct and when you declared x = y.
    That struct only has a pointer variable so when you did x = y you are assigning the pointer value of y to x right? That's why when modifying x.array[0] if you print both x.array[0] and y.array[0] they have the same value, so in that example as we assigned the x pointer variable to be the same as y we lost the pointer to the original array that x was pointing to right? It still exists in memory but we can't used it?

    • @jcamargo2005
      @jcamargo2005 ปีที่แล้ว +1

      Yes, the block is still on the heap, but we lost the pointer. It is one way to produce a memory leak

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

    The best explanation on struct ever!!

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

      Thank you very much for the kind feedback, I’m glad you’re enjoyed it! :-)

  • @adamaqil1965
    @adamaqil1965 ปีที่แล้ว +1

    You helped me a lot understanding struct. Thanks!

  • @fadieid5638
    @fadieid5638 2 ปีที่แล้ว +5

    Very clear and concise, thank you for this quality content.

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

      You’re welcome Fadi! I’m glad to hear you enjoyed the video. :-)

    • @ramakrishna4092
      @ramakrishna4092 2 ปีที่แล้ว +1

      @@PortfolioCourses hi sir I am having a doubt why we used strcpy to assign string to structure members of " name and ID " Instead OF ASSIGNING directly like normal structure variable of age and grades . I have tried to assign string to structure members of "name and ID " when I compiled my code I got an error .
      why and what is the difference can you pls explain me ???😊

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

      @@ramakrishna4092 We can initialize the string when we declare the struct using an initializer list as in this example: www.delftstack.com/howto/c/c-initialize-struct/. But if we first declare the struct, and then set the members with individual assignment statements, we cannot later use = to assign to the string.
      It's like how in C we can initialize an array once with the {1,2,3,4,...} type syntax, when it is declared, but not afterwards.
      When we make a char array we can initialize it once to a string literal when it is declared:
      char string[] = "store this string";
      But if we had this it would not work:
      char string[20];
      string = "store this string";
      The same thing is happening here essentially, when we declare the struct the string is essentially declared and created similar to the above example. We cannot assign to it later with = "some string", we then need to use strcpy().
      It's just how C works that it's like this really. 🙂

  • @fifaham
    @fifaham 9 หลายเดือนก่อน

    @4:00 Hi Kevin, I have watched this before and would love to learn how to copy this struct from an Excel Spread Sheet, and Paste it and Save it to Excel Spread Sheet. I appreciate if you have the time to do a video on that. This makes a very useful tool for embedded design. Thanks a million, Kevin.

    • @PortfolioCourses
      @PortfolioCourses  9 หลายเดือนก่อน +1

      Is the Excel filed saved as a CSV file? That may be do-able. If it's not some kind of binary .xls format I'm not sure how. :-)

    • @fifaham
      @fifaham 9 หลายเดือนก่อน

      CSV file would do it, yes.

  • @mohamedhossam3645
    @mohamedhossam3645 ปีที่แล้ว +1

    your channel is a gem

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

      Thank you for the positive feedback Mohamed, I appreciate it! :-)

  • @ItachiUchiha-jj9tm
    @ItachiUchiha-jj9tm 2 ปีที่แล้ว

    that thing i can only comment is it was so clear... thanks and good luck!!!!!

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

      You’re welcome Itachi! I’m glad you found it clear. :-)

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

    Hopefully your courses will help me get an A in my technician year. Good work

  • @MrBlaze777
    @MrBlaze777 9 หลายเดือนก่อน

    This is truely a detailed source
    Thank you bro!!

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

    Thank you very much, please keep uploading videos. Much love!

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

      You’re welcome, and I’ll definitely keep uploading videos! :-)

  • @RustysAdventures
    @RustysAdventures 2 ปีที่แล้ว +1

    Wow! This video really blew me away. Great video to learn struct

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

    hammer on a nail. Simple short to the point.

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

    Thank you, You did very good explanation with exampels. You finally made me learn to use structs properly and to pass them correctly to different functions.

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

      You're welcome! :-) I'm really glad to hear that this video helped you to learn how to use structs!

  • @Jonathan-mu5nx
    @Jonathan-mu5nx ปีที่แล้ว +1

    best tutorials you can find!

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

      Thank you very much for the positive feedback Jonathan! :-)

    • @Jonathan-mu5nx
      @Jonathan-mu5nx ปีที่แล้ว

      @@PortfolioCourses always helping mate. thank you so much!
      i have an assignment now with an array of struct to represent items in a shop (name, price, amount). they asked us to make a program with different functions so the user can add a product and buy a product from that shop and so the array has to be synchronized between all functions. I don't know how to make it happen because we didn't learn pointers yet.

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

      @@Jonathan-mu5nx I have some videos on pointers and structs you might like:
      Introduction To Pointers: th-cam.com/video/2GDiXG5RfNE/w-d-xo.html
      Arrow Operator: th-cam.com/video/w5XM1N7hLgc/w-d-xo.html
      Dynamically allocate an array of structs: th-cam.com/video/lq8tJS3g6tY/w-d-xo.html
      Good luck! 🙂

  • @ramisa_draws
    @ramisa_draws 6 หลายเดือนก่อน

    Thank you! this video made so many things clearer for me! Any chance you'll make SDL tutorials for C?

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

      I don’t have plans to right now but maybe it’s something I can do one day. :-)

    • @ramisa_draws
      @ramisa_draws 6 หลายเดือนก่อน

      @@PortfolioCourses yeyy, thank you!

  • @ابوأحمد-ث9ت4ض
    @ابوأحمد-ث9ت4ض ปีที่แล้ว

    Best c tutorial ever

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

    Can i know why you didn't use the typecasting with malloc in this case
    Or at least recommend a video to me to understand ,and thanks ❤️❤️

  • @yunosukemiro8802
    @yunosukemiro8802 11 หลายเดือนก่อน +1

    Sir,can I know which compiler you use

  • @blockcrafterxy6967
    @blockcrafterxy6967 ปีที่แล้ว +1

    Love your videos! Learned more in two weeks than 5 months of studying. I have one question tho: When calling the function (at around 9:10 in the video) I get the error: a parameter list without types is only allowed in a function definition; when I try to compile it. (the error for the function call in the main body)

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

      The source code for the video is here, does using this help? github.com/portfoliocourses/c-example-code/blob/main/struct.c

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

    thank you for making it easy on us champ.

  • @AnalogDude_
    @AnalogDude_ 10 หลายเดือนก่อน

    19:55 x = y, wouldn't that be a memory leak? since you lost the original pointer (location) with the data still being there.

  • @mdanishossain026
    @mdanishossain026 2 ปีที่แล้ว

    thremendous tutorial in c
    fullplaylist is superb
    sir ❤❤❤💖💖💖💖💖💖

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      I’m really happy to hear that you’re enjoying the tutorial and playlist! :-D

  • @chrislazarou2682
    @chrislazarou2682 11 หลายเดือนก่อน +2

    which IDE do you use?

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

    Thanks for this wonderful, clear and succint explanation

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

      You're welcome Rahmat, I'm glad you enjoyed it! :-)

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

    I have seen alot of your videos and are helpful,
    I have a little problem how would I get computer serial Number.
    system("wmic get bios serialnumber>sn.txt");
    And store it in an array of character and then print it on screen.?
    I really need help with that.

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

    Great video. I have a question. What's the difference between a struct and class? And when to use them. I know class is by default private but how to use these two terms properly.

    • @zacherymcclendon3945
      @zacherymcclendon3945 11 หลายเดือนก่อน

      I don’t think C has classes that’s C++ but I’m also confused on like why classes were a necessary change from C to C++ I’m pretty sure it has something to do with OOP but I’m not too sure

    • @zacherymcclendon3945
      @zacherymcclendon3945 11 หลายเดือนก่อน

      Just looked it up I guess classes have a deinitializer function that destroys instances of the class so I guess you can’t tell if the structs are getting destroyed

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

    el mejor video explicando structs, gracias por hacer este video!

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

    quick question, what happens to the previous malloc'ed memory region of x after pointing it to y? does it just float in memory to be reclaimed by the OS later?

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

      It's a memory leak. :-) Which means the memory has been allocated, but is no longer accessible by our program. It also won't be "returned" to the OS until the program terminates. So we call it a memory leak because the memory is no longer available for our program, but it's also not being used in a useful way either.

  • @svenwaibel7007
    @svenwaibel7007 9 หลายเดือนก่อน

    Great channel with great explanations, thank you!
    I just fiddled around with memory and leaks. I hope this is correct and may help someone.
    #include
    #include
    typedef struct {
    int *array;
    } Data;
    void print_array(const char *name, Data data) {
    printf("Array %s
    ", name);
    for (int i = 0; i < 2; i++) {
    printf("%i: %d
    ", i, data.array[i]);
    }
    printf("
    ");
    }
    void separate_data() {
    Data x;
    x.array = (int *) malloc(sizeof(int) * 2);
    x.array[0] = 1;
    x.array[1] = 8;
    print_array("x", x);
    Data y;
    y.array = (int *) malloc(sizeof(int) * 2);
    y.array[0] = 9;
    y.array[1] = 9;
    print_array("y", y);
    free(x.array);
    free(y.array);
    }
    void same_data() {
    Data x;
    x.array = (int *) malloc(sizeof(int) * 2);
    x.array[0] = 1;
    x.array[1] = 8;
    print_array("x", x);
    Data y;
    y.array = (int *) malloc(sizeof(int) * 2);
    y.array[0] = 9;
    y.array[1] = 9;
    print_array("y", y);
    // deallocate memory of x because pointer x will be moved to y
    free(x.array);
    x = y;
    print_array("x=y", x);
    free(y.array);
    }
    int main() {
    separate_data();
    same_data();
    }

  • @carlbroman1135
    @carlbroman1135 29 วันที่ผ่านมา

    Very well explained! I will hear ”points” in my sleep now tho ⚰️

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

    23:00 In case it was not mentioned, you also get a memory leak on the x.array block, and a duplicate reference to the y.array block... Common pitfalls to the begginers...

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

      Yes, we need to watch out for these things. :-)

  • @jayjenous7601
    @jayjenous7601 2 ปีที่แล้ว +2

    I'm learning C, i'm an amateur wannabe from python, can i take the structs as objects, and the variables declared from the structs as instances?, I feel them like that

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

      Great question Jay! :-) And yes that’s correct, when we define a type of struct it’s a lot like defining a class in Python (in other words, a type of object). And when we declare variables of that struct type, those are a lot like object instances.

    • @jayjenous7601
      @jayjenous7601 2 ปีที่แล้ว

      @@PortfolioCourses thanks boss, i was kinda Lost on this till i related structs with classes

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      You’re welcome! :-)

    • @lradhakrishnarao902
      @lradhakrishnarao902 2 ปีที่แล้ว +1

      difference between structs and class is that in structs, functions are private and data members are public, while in class, it's opposite. However, C does not have any concept of objects, as we don't instantiate. In C, structures are mainly used for the purpose of grouping various information under one name.

    • @shashank12able
      @shashank12able 2 ปีที่แล้ว

      ​@@lradhakrishnarao902

  • @lradhakrishnarao902
    @lradhakrishnarao902 2 ปีที่แล้ว

    I have a question. In the assignment of structures, does the addresses of the structures also gets copied? E.g., When we do p1 = p2, does p1 also contains the address of p2?

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      Great question! :-) No, p1 and p2 each have their own address at which a struct is stored. And when we do p1 = p2, a memcpy() will effectively happen where p2's contents are copied to p1. But p1 and p2 each still are in different memory addresses.

  • @nicholasjoiles8999
    @nicholasjoiles8999 2 ปีที่แล้ว +1

    very detailed. Thank you. 💯💯

  • @anastasiosvervantidis2026
    @anastasiosvervantidis2026 9 หลายเดือนก่อน

    Your introduction is very elaborate and comprehensive 😁. But Kevin 40 is quite old for a student, isn't he? 🤣

    • @PortfolioCourses
      @PortfolioCourses  9 หลายเดือนก่อน +1

      He’s a mature student. :-)

  • @deep2mixer
    @deep2mixer 10 หลายเดือนก่อน

    Excellent ..very good channel.

  • @karolinariddle6359
    @karolinariddle6359 2 ปีที่แล้ว

    thank you, the best content I have seen about this topic. Great! :)

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      You’re welcome Karolina, and thank you for the positive feedback! :-)

  • @Anonymous-XY
    @Anonymous-XY ปีที่แล้ว

    Thank you, Amazing work.

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

      You’re welcome, and I’m glad you enjoyed it! :-)

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

    thanks for the video, and great presentation

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

      You're welcome, I'm glad you enjoyed it! :-)

  • @ltcqqn
    @ltcqqn 2 ปีที่แล้ว +1

    very helpful! thank you so much

  • @amandaliu7409
    @amandaliu7409 2 หลายเดือนก่อน

    very helpful thank you

  • @alexander-ud9bs
    @alexander-ud9bs ปีที่แล้ว

    thank you for this great job

  • @dbak6924
    @dbak6924 2 ปีที่แล้ว

    thank you! very good explaining😄

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      You're welcome, I'm glad you enjoyed the explanation! 🙂

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

    awesome content
    always my go to

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

      I'm so glad to hear you're enjoying the content! :-)

  • @shanjosebastian8482
    @shanjosebastian8482 2 ปีที่แล้ว

    Nice tutorial.... Very helpful

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      Thank you for the kind feedback Shanjo! :-)

  • @dimphomokoena4982
    @dimphomokoena4982 2 หลายเดือนก่อน

    Please do pointers

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

    Merci a LOT 🙂

  • @jmesguerra2664
    @jmesguerra2664 6 หลายเดือนก่อน

    so structs is a class without functions?

    • @PortfolioCourses
      @PortfolioCourses  6 หลายเดือนก่อน

      In C, essentially yes. :-) In C++ struct is a lot more like class though, just so you know: learn.microsoft.com/en-us/cpp/cpp/classes-and-structs-cpp?view=msvc-170

  • @stonedcodingtom9097
    @stonedcodingtom9097 2 ปีที่แล้ว +2

    Thx!

  • @skeeberk.h.4396
    @skeeberk.h.4396 ปีที่แล้ว

    This is heaven 😍

  • @MrMits92
    @MrMits92 2 ปีที่แล้ว

    do we need to free() the x and y array somehow, since we use malloc() ?

    • @MrMits92
      @MrMits92 2 ปีที่แล้ว

      i actually found a solution:
      we need to free x.array before we make x=y assign, then at the very end we free y.array. I was trying to free both x and y array at the very end but there was still a leak, so hope it might help someone
      check for leaks on Mac with: CK_FORK=no leaks --atExit -- ./a.out

    • @MrMits92
      @MrMits92 2 ปีที่แล้ว

      #include
      #include
      #include
      typedef struct {
      int *array; // pointer to dynamically allocated array
      } Data;
      int main() {
      // initialise two structures named x and y of type Data
      Data x;
      Data y;
      // stores 5 int in dynamically allocated array
      x.array = malloc(sizeof(int) * 5);
      y.array = malloc(sizeof(int) * 5);
      printf("
      X's pointer: %p
      ", x.array);
      printf("Y's pointer: %p
      ", y.array);
      x.array[0] = 1;
      x.array[1] = 2;
      x.array[2] = 3;
      x.array[3] = 4;
      x.array[4] = 5;
      printf("
      ////// x.array ///////////

      ");
      for(int i = 0; i < 5; i++) {
      printf("x.array[%d] = %d
      ", i, x.array[i]);
      }
      y.array[0] = 9;
      y.array[1] = 9;
      y.array[2] = 9;
      y.array[3] = 9;
      y.array[4] = 9;
      // 'x' with it's pointer to the array it has been set to point to the same array that 'y' is pointing to
      // so they point to the same array,
      // cuz the STRUCTURE STORES A POINTER TO THE ARRAY THAT WE DYNAMICALLY ALLOCATE
      free(x.array); // free up the allocation before we assign
      x = y;
      // here we see that they both now point to the same pointer for an array
      printf("
      X's pointer: %p
      ", x.array);
      printf("Y's pointer: %p
      ", y.array);
      printf("
      ////// x.array after assign to y ///////////

      ");
      for(int i = 0; i < 5; i++) {
      printf("x.array[%d] = %d
      ", i, x.array[i]);
      }
      printf("
      ");
      // if we change one value of x array, those changes apply also to the y, cuz after x=y assign they both point to the same array
      x.array[0] = 10;
      printf("
      ////// y.array after x.array[0] was changed ///////////

      ");
      for(int i = 0; i < 5; i++) {
      printf(" y.array[%d] = %d
      ", i, y.array[i]);
      }
      printf("
      ");
      free(y.array);
      return 0;
      }

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

      @@MrMits92 That is correct!

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

    Thanks!

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

      Wow thank you so much for the 'super thanks'!!! :-D

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

    謝謝!

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

      WOW thank you very much for the super thanks!!! :-D

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

    Génial !

  • @user-cd7xk9jv3k
    @user-cd7xk9jv3k ปีที่แล้ว

    Amazing

  • @muhammadmahmoud2054
    @muhammadmahmoud2054 2 ปีที่แล้ว

    1:42 A forty years old student! I guess you never stop learning ;-)

  • @smoothoperatah
    @smoothoperatah 6 วันที่ผ่านมา

    correct me if i’m wrong but p1 = p2 doesn’t copy the struct. it only copies the memory address (pointer) to the strut. since p1 and p2 are only pointers. so in essence p1 is destroyed and all that remains is two pointers to the original p2. perhaps you explain this later i haven’t watched to the end yet.

  • @danieldevito414
    @danieldevito414 8 หลายเดือนก่อน +1

    I absolutely love these videos, but I think it's important to point out that when you use malloc, you have to free the space before reassigning the pointer, or a memory leak is created. And I only say this because the dementia patients in the Whitehouse just urged us all to stop using these languages for this reason.

    • @PortfolioCourses
      @PortfolioCourses  8 หลายเดือนก่อน +1

      You're right, I was trying to stay focused on structs in this video and keeping it to a reasonable time, I've made note of this and pinned a link to this other video on memory leaks now: th-cam.com/video/lQCLAKfcYI4/w-d-xo.html

  • @Graham_Rule
    @Graham_Rule 9 หลายเดือนก่อน

    The popup tools in your editor are too distracting.

  • @drissnafi3
    @drissnafi3 2 หลายเดือนก่อน +1

    10:00

  • @theyamo
    @theyamo 21 วันที่ผ่านมา

    who spells char as car nice vid btw

  • @AA-mf2up
    @AA-mf2up 10 หลายเดือนก่อน

    you dont have enough place in char name for osas

  • @mdsalmanfarse8914
    @mdsalmanfarse8914 9 หลายเดือนก่อน

    You teach very good undoubtedly but if you could give separate examples of every items instead of massing everything in a single code, it would be better to understand for us.... You can copy and paste from the previous code that you needed for the next example but please give separate examples instead of giving a very long example.

  • @Jeremyak
    @Jeremyak 2 หลายเดือนก่อน

    tfw you're Kevin

  • @ryanalnaser914
    @ryanalnaser914 2 ปีที่แล้ว +1

    whatever anything

  • @ryanalnaser914
    @ryanalnaser914 2 ปีที่แล้ว

    whatever anything I do or did

    • @ryanalnaser914
      @ryanalnaser914 2 ปีที่แล้ว

      whatever anything I know or knew or do or did and in 7:14 or more you did something you know what I mean

    • @ryanalnaser914
      @ryanalnaser914 2 ปีที่แล้ว

      I am not sure when exactly and whatver anythign

    • @ryanalnaser914
      @ryanalnaser914 2 ปีที่แล้ว

      Anything*

    • @ryanalnaser914
      @ryanalnaser914 2 ปีที่แล้ว

      whatever anything I do or did or anything

  • @danielpopa1320
    @danielpopa1320 2 ปีที่แล้ว

    11:23

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

    Thanks!

  • @user-cd7xk9jv3k
    @user-cd7xk9jv3k ปีที่แล้ว

    Amazing