Structs (Structures) in C - An Introductory Tutorial on typedefs, struct pointers, & arrow operator

Поділитися
Вставка
  • Опубліковано 30 лип 2024
  • 0:00 Structs are Structures / Compound Data Types to group related variables
    0:55 The syntax of struct declarations in C with an example Point declaration with two members
    2:04 Declaring variables of struct types requires awareness of struct namespace
    2:46 Accessing members of a struct value using the dot operator
    5:05 Struct values are stack values by default and are located local within automatic stack memory
    6:40 Zero initializing C struct members with zeros with C99 standard initialization to 0s
    8:39 Initializing C struct members with specific values in curly braces
    10:17 Introduction to the typedef operator for aliasing types in C
    11:32 Using typedef with C struct types for shorter, more natural data typing in your programs
    14:08 Using typedef to alias and declare a C struct in a single statement
    15:58 Why is the name of a C struct repeated twice in a typedef statement?
    17:15 Challenge problem tracing code with struct values.
    23:35 Using struct values by accessing and assigning to its members
    24:08 Copying all members of a C struct from to another variable or memory location
    25:20 Be careful of the difference between a copy of a struct and a pointer to a struct
    30:21 Accessing members of pointers to structs with C's Arrow Syntax for dereferencing
    32:42 Next steps with structs: writing functions that work with structs using common C idioms

КОМЕНТАРІ • 47

  • @thisisreallyme3130
    @thisisreallyme3130 2 роки тому +16

    I'm confused why you do not have a lot more subscribers. :). I've watched a dozen other videos on introductory C, including the excellent CS50. You spending a full 30 minutes on this one topic is a perfect way to hammer the idea home. Thanks.

    • @KrisJordan
      @KrisJordan  2 роки тому +6

      I appreciate the feedback here and am glad to have helped!

    • @ridcully
      @ridcully 2 роки тому

      The UA-cam ‘algorithm’ is written in Perl

  • @not.harshit
    @not.harshit 3 роки тому +7

    You can also initialize your struct in this way.
    Point = {
    .x = 4.0,
    .y = 2.0
    };
    EDIT: This format also works when assigning values to structs.
    Point.x = 4.0;
    Point.y = 2.0;
    is equivalent to:
    Point = {
    .y = 4.0,
    .x = 2.0
    }
    (Notice that the elements of the struct can be listed in any order when assigning values)
    Currently only C(Clang) supports this style, C++ does not.

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

    At 17:09 I learned that, I have to use a struct name. I thought that the name was redundant, but it's absolutely not!
    Kris have an outstanding level of teaching, despite he's knowlegde of C properly feels like Kernigan!

  • @alfonsotoriz7563
    @alfonsotoriz7563 3 роки тому +2

    Thank you! I've been following Shaw's Learn C the Hard Way and thanks to your channel I've finally understood some key concepts :)

  • @quangdungle9658
    @quangdungle9658 2 роки тому +2

    I was struggling in class and your video really helped me. Love the small exercise in the video and how you explain it.
    Thank you!

  • @angry_moose94
    @angry_moose94 2 роки тому

    A topic that seems so simple yet it is so fundamental. Enjoyed the way you explained the topic with thoughts about how the whole thing works under the hood. Will make sure to watch the rest of your videos!

  • @shvideo1
    @shvideo1 2 роки тому +2

    Excellent and comprehensive introduction to structs. Thank you for this great tutorial that explains all the nuances and syntax so clearly. It is very useful.

    • @KrisJordan
      @KrisJordan  2 роки тому

      Thank you for the kind feedback!

  • @guilherme-gu7vv
    @guilherme-gu7vv 2 роки тому +1

    Thank you very much, you make such a great videos! 👍

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

    great refresher ...

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

    I'm a full time fast paced web dev student currently in C programming. Thank you so much for this video! I'm struggling to learn C as I have to complete 3 sections a week. I'm not spending enough time before I have 3 more projects due. I generally love C but I won't lie and say it makes a lot of sense. It could be because I am about 8 weeks in. I'd love to watch every video on anything C. I looked through the videos and was really interested in Loops in C if anyone would like to respond with a link. I'd appreciate it!
    Thanks for the video, Mr. Jordan! This is really helping me compared to tons of different websites and youtube videos. My curriculum doesn't come with any books or much material so I am expected to do all my own research. I'm super looking forward to your pointer in C video.

  • @adrianaerakovic9259
    @adrianaerakovic9259 2 роки тому

    Got yourself a new subscriber! well done!

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

    Nice video! I learned allot. But, making points about pointers to variables of type Point did get a little confusing. Maybe could have named the struct type Coordinate or something? lol.

  • @bobsprite6711
    @bobsprite6711 4 місяці тому

    Excellent! Very clear and didactic!

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

    Amazing stuff

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

    great content!

  • @mesv2009
    @mesv2009 3 роки тому

    thank so much ! nice to follow u

  • @arnabmukherjee5840
    @arnabmukherjee5840 2 роки тому

    just awesome..

  • @raphael.portela
    @raphael.portela 10 місяців тому

    subscribed, you are one of the best in C progrraming, ive always struggled with pointers and structs, i got the idea on what the pointer represents and the usages , but when comes to struct I never fully understood

  • @FMisi
    @FMisi 2 роки тому +2

    14:50 iss the important part
    31:14 is important too

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

    I get the Point awesome explanation

  • @issaabsi3804
    @issaabsi3804 2 роки тому

    thank you

  • @khomo12
    @khomo12 2 роки тому

    Nice!

  • @immyslave2952
    @immyslave2952 2 роки тому

    Thx bro

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

    Thanks a lot for your videos. I just found your channel as I want to learn to program in C. Probably you get this question a lot but didn't find the answer/comment in your other videos. What vim color scheme do you use here? Thanks in advance!

  • @0xMalWorld
    @0xMalWorld 2 роки тому

    thx

  • @juliaperkins744
    @juliaperkins744 3 роки тому +5

    Can confirm OS students were confused by typedef & repetition of struct name (I was one)

    • @KrisJordan
      @KrisJordan  3 роки тому +2

      I'm optimistic the experience of OS will change dramatically once the pipeline of students who took 211 reaches the point of OS.

    • @juliaperkins744
      @juliaperkins744 3 роки тому +1

      @@KrisJordan confident it will, low key it’s helped already (@gdb)

  • @amirhossein5055
    @amirhossein5055 2 роки тому

    great

  • @azizaydi7400
    @azizaydi7400 2 роки тому

    thank you so much for this important course sir , pls what is the name of the book that u are using and thank you .

  • @billc3114
    @billc3114 2 роки тому

    With the strict defined in stat.h, how could I view all members? I am thinking iteration. I can view st_ino. But I want to view all data with printf.

  • @derkeiler2573
    @derkeiler2573 2 роки тому

    21:20 i m a little confused.. someone told me, that in *C* it is not possible to create a copy of a struct like shown in your example:
    point a = {0};
    point b = a;

  • @redcrafterlppa303
    @redcrafterlppa303 2 роки тому

    23:25 I just explored java under the hood and discovered it's actually possible to get the equivalent of this code with some under the hood magic. Since every object except primitives are already pointers we can dereference them and write to the memory ignoring imaginary write protection (final, private...).

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

    About what book exactly you are talking about here?

  • @jonsunderland7708
    @jonsunderland7708 2 роки тому

    Gruvbox?

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

    Hi, which is your font ?

  • @AnimeMemesDaily
    @AnimeMemesDaily 3 роки тому

    interesting video

  • @Anythingforfreedom
    @Anythingforfreedom 2 роки тому

    You referenced a book and my eyes lit up. What book are you using?

  • @johnnyappleprng614
    @johnnyappleprng614 3 роки тому

    LOL @ 15:35

  • @riverrunsthrough8268
    @riverrunsthrough8268 3 роки тому +2

    why would you call your struct point in a vid where you will be discussing pointers? to be cheeky or..? unneccesary distraction in my opinion. good content otherwise though, subbed

    • @KrisJordan
      @KrisJordan  2 роки тому +2

      In a redo I would go with Vector2. I do like the familiarity and simplicity of a simple point in the context of a cartesian coordinate system.