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
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.
I appreciate the feedback here and am glad to have helped!
The UA-cam ‘algorithm’ is written in Perl
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.
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!
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 :)
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!
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!
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.
Thank you for the kind feedback!
Thank you very much, you make such a great videos! 👍
great refresher ...
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.
Got yourself a new subscriber! well done!
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.
Excellent! Very clear and didactic!
how is it didactic
Amazing stuff
great content!
thank so much ! nice to follow u
just awesome..
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
14:50 iss the important part
31:14 is important too
I get the Point awesome explanation
thank you
Nice!
Thx bro
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!
thx
Can confirm OS students were confused by typedef & repetition of struct name (I was one)
I'm optimistic the experience of OS will change dramatically once the pipeline of students who took 211 reaches the point of OS.
@@KrisJordan confident it will, low key it’s helped already (@gdb)
great
thank you so much for this important course sir , pls what is the name of the book that u are using and thank you .
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.
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;
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...).
About what book exactly you are talking about here?
Gruvbox?
Hi, which is your font ?
interesting video
You referenced a book and my eyes lit up. What book are you using?
The C Programming Language by Kernighan and Ritchie
@@KrisJordan Thanks again!
LOL @ 15:35
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
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.