Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,110 --> 00:00:08,490
So in this video, we are going to talk about structs having a raise as data members.
2
00:00:08,940 --> 00:00:12,060
OK, so we know that strikes can be simple.
3
00:00:12,060 --> 00:00:19,350
Instructs may be complicated, but in these video, we are going to mix a little bit of a couple of
4
00:00:20,340 --> 00:00:23,280
different data types in a simple struct.
5
00:00:24,120 --> 00:00:31,950
So this struct that we are going to use in this video is basically a struct for representing an employee
6
00:00:32,190 --> 00:00:33,360
at some company.
7
00:00:33,720 --> 00:00:34,200
OK.
8
00:00:34,470 --> 00:00:39,630
We could also use it like typedef struct student two to represent the student.
9
00:00:40,020 --> 00:00:46,590
Let's simply stick with the example that we have to represent a certain employee.
10
00:00:47,190 --> 00:00:47,580
OK.
11
00:00:48,150 --> 00:00:50,910
So we have an employee, we have this structure.
12
00:00:51,150 --> 00:00:59,280
And if we read this structure line by line, we can say that we have the first member of these employees.
13
00:00:59,280 --> 00:01:01,560
Struct is an array.
14
00:01:02,650 --> 00:01:03,490
Of sites then.
15
00:01:04,730 --> 00:01:05,270
OK.
16
00:01:06,050 --> 00:01:17,700
And also, we have float age and an integer I.D. So if I try to basically basically to to demonstrate
17
00:01:17,730 --> 00:01:23,280
you visually how a variable of this structure should look like, it should be something like that.
18
00:01:23,300 --> 00:01:24,860
OK, so let me draw it.
19
00:01:27,190 --> 00:01:32,190
This is a variable of an employee type, and we will have something like this.
20
00:01:32,490 --> 00:01:34,290
It will be IED.
21
00:01:35,100 --> 00:01:37,530
It will be an age.
22
00:01:37,590 --> 00:01:38,100
OK?
23
00:01:38,490 --> 00:01:40,710
A floating point and integer in here.
24
00:01:40,710 --> 00:01:41,910
We will have the name.
25
00:01:42,870 --> 00:01:45,420
Which is an array of size 10.
26
00:01:45,480 --> 00:01:50,220
OK, so basically here at the same, we will have an array.
27
00:01:51,130 --> 00:01:52,780
With 10 values.
28
00:01:53,700 --> 00:01:54,610
Characters, OK.
29
00:01:54,690 --> 00:01:57,330
Zero, one, two, three and so on, up until nine.
30
00:01:58,840 --> 00:01:59,230
So.
31
00:02:00,230 --> 00:02:03,140
This structure consists of three members.
32
00:02:03,500 --> 00:02:08,390
The first one is an array of characters of size 10, and it's called name.
33
00:02:08,660 --> 00:02:11,960
The second one is age and it's a fly off type float.
34
00:02:12,170 --> 00:02:14,990
And the third one is ID of typing.
35
00:02:15,350 --> 00:02:16,030
That's it.
36
00:02:16,040 --> 00:02:20,090
That's the whole structure that we created this new box.
37
00:02:20,900 --> 00:02:22,490
OK, good.
38
00:02:22,970 --> 00:02:29,750
So now what we are going to do is basically to look at how can we create an object of this type?
39
00:02:30,710 --> 00:02:34,880
OK, so first of all, we create an object called MMP one employee one.
40
00:02:35,540 --> 00:02:38,420
And these employee one, we can say, let's let's leave it as this.
41
00:02:38,420 --> 00:02:40,490
OK, so that will be the employee one.
42
00:02:41,450 --> 00:02:43,820
We didn't specify what should be its values.
43
00:02:43,880 --> 00:02:44,930
OK, no problem.
44
00:02:45,170 --> 00:02:47,570
It's just kind of empty.
45
00:02:48,530 --> 00:02:55,610
We also create the second employee MP two, and we initialize it with a few values.
46
00:02:55,610 --> 00:02:59,990
We specify that there is Jake and there is some values.
47
00:02:59,990 --> 00:03:04,550
So there will be like J a k e zero.
48
00:03:04,610 --> 00:03:05,150
Of course.
49
00:03:05,300 --> 00:03:05,660
OK.
50
00:03:06,170 --> 00:03:12,680
That's for the name, and that's for the age and for the ideas over the ages.
51
00:03:12,710 --> 00:03:16,610
We're twenty four point five and the adds one two three.
52
00:03:17,610 --> 00:03:18,960
OK, very simple.
53
00:03:19,350 --> 00:03:21,240
We created MP two.
54
00:03:21,540 --> 00:03:26,250
We created two variables of an employee type.
55
00:03:26,460 --> 00:03:32,700
One of them we initialized with some values, while the other we did not use them to initialize anything.
56
00:03:34,200 --> 00:03:35,670
OK, so far, so good.
57
00:03:36,540 --> 00:03:43,410
And we are now going to see how we can use these signing operator to copy value by value.
58
00:03:43,740 --> 00:03:44,160
OK?
59
00:03:44,190 --> 00:03:50,940
The members of one struct variable to another struct variable, which should be of the same type.
60
00:03:51,570 --> 00:03:56,640
OK, so we are going to copy all the members from impaired to.
61
00:03:57,740 --> 00:03:58,760
To him, be one.
62
00:03:59,150 --> 00:04:01,490
OK, we are going to copy member by member.
63
00:04:02,330 --> 00:04:02,720
All right.
64
00:04:03,630 --> 00:04:04,080
And.
65
00:04:05,040 --> 00:04:10,380
That's something that we can do using, and B one equals two MP two.
66
00:04:11,340 --> 00:04:20,160
So since we know that both of them are of the same type MP, one equals two MP, two, MP one and the
67
00:04:20,160 --> 00:04:22,440
MP two are of employee one type.
68
00:04:23,130 --> 00:04:26,250
So we can copy the member by member.
69
00:04:26,640 --> 00:04:32,640
So afterwards there will be simply hear a value of twenty four point five.
70
00:04:32,760 --> 00:04:36,570
Here will be a value of one two three and here will be your Jake.
71
00:04:37,500 --> 00:04:39,450
OK, pretty much that what happens?
72
00:04:41,730 --> 00:04:44,640
And just one thing that I want to specify.
73
00:04:44,670 --> 00:04:45,100
OK.
74
00:04:45,150 --> 00:04:51,250
That's just that you will be familiar that you can use the a sign from one struct variable to another.
75
00:04:51,270 --> 00:04:54,990
OK, just copying the values, but be very careful on this one.
76
00:04:55,000 --> 00:04:59,280
We will talk about some notes regarding this part.
77
00:04:59,280 --> 00:04:59,700
OK?
78
00:05:00,060 --> 00:05:05,190
Maybe in the next video, what will happen if we you are copying pointers that are going to dynamic
79
00:05:05,190 --> 00:05:05,970
memory allocation?
80
00:05:06,300 --> 00:05:07,770
Maybe, maybe, maybe.
81
00:05:08,130 --> 00:05:10,260
I'm not sure that we are going this way.
82
00:05:10,260 --> 00:05:13,950
But if you has to proceed with the course, he will get this material.
83
00:05:13,950 --> 00:05:18,150
If not, so maybe this is not part of this section or maybe of these course.
84
00:05:18,750 --> 00:05:28,710
So nevertheless, let's just basically talk also about this note that I've written here that simply
85
00:05:28,710 --> 00:05:34,440
says that you remember when you had to erase, OK, let's say, to erase of integers.
86
00:05:34,890 --> 00:05:42,210
We could not copy each element from every one into a redo in just one line of code.
87
00:05:42,330 --> 00:05:42,720
Right.
88
00:05:43,350 --> 00:05:50,880
We what we've done is we simply took some loop and iterated over all of the elements and copy them one
89
00:05:50,880 --> 00:05:51,290
by one.
90
00:05:51,300 --> 00:05:58,590
So a great index one equals two error two at index to its index one and copied just element by element
91
00:05:58,590 --> 00:05:59,250
from erase.
92
00:06:00,030 --> 00:06:03,690
But now we have strikes, although we have these arrays.
93
00:06:03,690 --> 00:06:06,720
That's one of the notes that I wanted to give you in this video.
94
00:06:07,140 --> 00:06:13,050
Although we have these is a race we can simply Ray Downey and P1 equals twin P2.
95
00:06:13,680 --> 00:06:15,090
So it will copy it.
96
00:06:15,090 --> 00:06:17,400
It will take care of it behind the scenes.
97
00:06:18,510 --> 00:06:20,850
All right, awesome.
98
00:06:21,270 --> 00:06:26,550
So now just to make sure that everything is copied, let's it's basically this part.
99
00:06:26,550 --> 00:06:31,320
Let's go inside out and let's see that MP, one that name and empty to that name.
100
00:06:31,440 --> 00:06:33,360
Both of them are identical.
101
00:06:33,420 --> 00:06:36,750
Let's take a look at it so we can see that employee.
102
00:06:36,750 --> 00:06:39,350
One name is Jake and also the employee.
103
00:06:39,570 --> 00:06:41,250
Two name is also Jake.
104
00:06:41,580 --> 00:06:43,860
Since we used these shopping.
105
00:06:44,850 --> 00:06:48,030
Now the question comes, is what will happen?
106
00:06:48,300 --> 00:06:48,750
OK?
107
00:06:48,780 --> 00:06:55,230
Just basically to make sure that everything is copied and not and they are not kind of pointing to the
108
00:06:55,230 --> 00:06:56,370
same region in memory.
109
00:06:56,970 --> 00:07:02,970
So just to emphasize it, I will change some of the members in MP one.
110
00:07:03,330 --> 00:07:10,260
I will change the name from Jake to John, and also I will change the ad to be instead of one to three,
111
00:07:10,710 --> 00:07:11,520
to be four or five.
112
00:07:11,530 --> 00:07:11,910
Six.
113
00:07:12,480 --> 00:07:12,900
OK.
114
00:07:13,290 --> 00:07:21,300
And this will show you that these two strikes can be one and demob two with all of its members are basically
115
00:07:21,300 --> 00:07:22,650
two separated units.
116
00:07:22,980 --> 00:07:23,460
OK.
117
00:07:24,090 --> 00:07:31,020
Because sometimes you may have seen in different programs or something like that when you copy one thing
118
00:07:31,710 --> 00:07:36,750
and you have like a copy of it and you modify the copy, then also the source is being changed.
119
00:07:37,110 --> 00:07:42,330
OK, so I want to show you that it's not the case here, specifically in this example and the way we
120
00:07:42,330 --> 00:07:42,780
use it.
121
00:07:43,260 --> 00:07:50,670
So it's the RCP wing just copying a string John into the name P1.2 name and then changing the ad by
122
00:07:50,670 --> 00:07:57,810
accessing the member I.D. inside of the variable MP one and changing the value to four or five six.
123
00:07:58,170 --> 00:08:01,860
So now basically what we will have, let me get the yellow color.
124
00:08:02,280 --> 00:08:06,150
What we are going to have is something like that.
125
00:08:06,600 --> 00:08:08,610
Here we will have John.
126
00:08:09,390 --> 00:08:12,530
And here we will have what it will have four or five.
127
00:08:12,540 --> 00:08:12,930
Six.
128
00:08:14,490 --> 00:08:21,960
OK, so just to make sure of it, let's run down some commands to print the results to the screen and
129
00:08:21,960 --> 00:08:24,690
make sure that we see exactly what we expected.
130
00:08:24,990 --> 00:08:28,590
So let's run it in hope for the best.
131
00:08:28,980 --> 00:08:31,320
OK, so let's go command this poor talent.
132
00:08:31,320 --> 00:08:32,880
We don't need it right now.
133
00:08:34,110 --> 00:08:35,130
That's wrong.
134
00:08:35,880 --> 00:08:38,010
So, employee, one name.
135
00:08:38,280 --> 00:08:42,200
Here it is, is John employed to name is Jake.
136
00:08:42,210 --> 00:08:50,130
Employee one is four or five six and employed to I.D. is one two three, exactly as we expected.
137
00:08:51,050 --> 00:08:51,470
OK.
138
00:08:52,490 --> 00:08:59,360
So in this video, we talked about this operation of assigning once tracked variables to another as
139
00:08:59,360 --> 00:09:01,520
long as they are of the same type.
140
00:09:01,880 --> 00:09:02,270
OK.
141
00:09:02,690 --> 00:09:04,000
Don't mix it up, too.
142
00:09:04,010 --> 00:09:08,030
I don't know to assign employee to some struct date.
143
00:09:08,480 --> 00:09:08,760
OK.
144
00:09:08,800 --> 00:09:10,940
That simply won't make any sense.
145
00:09:11,540 --> 00:09:11,900
OK.
146
00:09:13,010 --> 00:09:14,020
Uh, yeah.
147
00:09:14,030 --> 00:09:16,100
So this is it for these video guys.
148
00:09:16,110 --> 00:09:19,820
Let me know if you have any questions and keep on practicing.
149
00:09:19,850 --> 00:09:21,120
Write down your notes.
150
00:09:21,140 --> 00:09:25,280
Keep on moving forward and you are bound to succeed.
151
00:09:25,850 --> 00:09:26,690
I'll see you next time.
152
00:09:27,050 --> 00:09:27,410
Bye.
12892
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.