WTF? Wouldn't ((char*)(&arr[1]))+8 bring him to &arr[3]? If the char is 1 byte, then you're moving 8 bytes from &char[1], which is two ints, which are each 4 bytes...
Чёто я недопонял. На 29:30 от arr[1] нужно 8 раз сместиться на размер char, т.е 8 байт. Размер сигмента int т.е. 4 байта, а он смещается на 4 сегмента, т.е. 16 байт. Ошибся? Или я чё-то не вкурил...
I have i little misunderstanding...On 29:30 we need to jump from arr[1] position 8 times on size of char (8*1=8bytes). Segment size is int (4bytes), but he jumps on 4 segments (4*4=16bytes). Mistake? Or its just me...
We move 8 chars forward first, then we change to using short (4bytes) as the segment size and move to the fourth segment because he is writing the value 100 to arr[3], the fourth entity in the arr array.
@AesmaDiv I was thinking the same thing.... He was traversing the array of integers as if each box were containing 2 bytes instead of 4 bytes (probably confusing them as shorts). After the (char *) type cast, he would end up with a pointer to the 4th "box", or arr[3].
Something I found quite interesting. Stanfords german motto at the beginning of each video reads "Die Luft der Freiheit weht" which relates to Stanfords german heritage and translates as "The air of freedom is waving" or "The wind of freedom blows"
I mean the first bit is 2 not each bit. I think the 2 is on or off because 2 to the 0 is 0 so you either have a 0 or a 2 to a power. These are Int's. so when you say int num1
you store the char 1 in the int array. there are diff types of array. ones for numbers ones for signs, and so on. Yeah so it's kinda crazy.
You can take classes online. But yeah you need your Gen Ed first.
This is Comp SCI 106 so they took like 4-5 computer classes before this one. Seems Linux is the OS people want to hire in. So this is useless in the real world. Java Scripting and Linux OS is a must. This guy is looking to program a chip or see what is on a chip. That is all this is. Knowing code and operations is the most important.
@keylazy In an array, each bit is 2 to the first, then the next bit is 2 to the second and so on from left to right on the array. Array is a microprocessor. So when he wrote 2 in the array, he defined the array as a short, That basically doubled the size of the processor by dividing the bits in half. so when you count over 4 it is really 8. so its 2 to the 8th not 2 to the 4th// Now its 2 to the 8th and since 125 sits in the same space , the processor will multiply them.
I love Mr. Cain. Yeah I am kinda keeping up. It's great to review on video like this. You won't miss parts of the lectures. Wish I have more background and knew some codes and so on. I know a little HTML but this is pretty advance, you got to start someplace I guess.
I don't think he added the chars up correctly. The boxes represent integers which are four bytes each, a char is 1 byte so from the second box he adds 8 char sizes onto it which takes him to the start of the fourth box ( the one with the 2 and 128 in it ). He then casts that as a short pointer and jumps three shorts in which is one short away from the end of the array ( halfway through the last box ) .
always amazes me how a computer works. each little pixel on the screen is referenced from a tiny little cell in a memory chip which is either On or Off.. i think.. (only know the basics)
This comment has received too many negative votesshow
are all these lectures just a bunch of examples thrown together almost spontaneously ? This is a very unusual style of teaching, in fact, for the first time in my life I feel like I'd be better off just reading a book rather than watching this b/s - quite an achievement, stanford!!
He's forgetting that he wrote character data, not numeric data, so the 3 in the first byte of numUnits is chracter '3' (value 51) not the number 3. He's also interpreting it as big endian when the computer's they're using are little endian.
It is because in memory of PC values are represented in such a way, so high byte is located as high address.
For example value 5 of type int will be represented as 0x05 00 00 00 and value 5 of type short will be 0x05 00.
So when you reference this ((short*)intArray)[7] , you actually reference to high byte of 3rd element, which is 00 00. To correct this, you must refer to 6th element of short: ((short*)intArray)[6].
I think at 29:41 he is making a mistake by thinking of the array as an array of 5 short's (2 bytes each) but really he declared an array of 5 int's(4 bytes each).
I think the 100 would be placed in the last two bytes of arr[4].
I totally agree. he would end up in the middle of the last box. He takes the size of the boxes to be 2 bytes, while they in fact are ints, so 4 bytes. Well noticed. I didn't notice it the first time I saw it. Thanks for pointing it out.
I agree. Where he went wrong was accidentally adding 16 onto the casted char* instead of 8 for the reason you said (mistaking the array for an array shorts).
It's easy to make a mistake like this when trying to explain something with lots of numbers and multiple typecasting.
I am studding CS during last 5-6 years, but this video is a very informative for me, and I just only now understand how represent array, structures in the memory...
Hey..maybe stanford university should give education for free so everyone else can learn through the computers...no? yes?..anyone?..does that make sense?
yes i saw that movie more times than anyone should, and i dont get how funding the education system and universities connects with it. perhaps you could explain a little bit more?
can't believe I gotta explain myself. The Joker at some point in the movie burns the money and cares for the message he want to send to the people of gotham. It connects in my sense that Stanford can be the Joker, and send a message of not caring about the money but about sending a message of altruism by sharing their fine education programs so others can follow. It doesn't have to be all programs, but some (like this one) could be enough..got me?? get out of my face..
ooo see thats why i didnt get it-because it doesnt make any sense. the joker represents chaos and anarchy, and thats why he burns the money, because he has no use for it., where as stanford university has plenty use for money, and yes, they could give some education freely, like they are in this youtube video and thats exactly what their doing. i dont have a problem with that point, its your stupid analogy which confused me
Sort of. A few people I know have used free education from MIT and Stanford to skip through a lot of undergraduate courses in areas such as math and computer science, and are now doing a combined BS/MS while taking a mix of undergraduate and graduate classes. So it kind of helps you get an undergraduate degree. But you still need to be in the school and paying for your education.
I'm just learning about C pointers and arrays right now and this is really making me understand. Great lectures. These and the old MIT "structure and interpretation of computer programs" lectures from 1986 (done in LISP) will make anyone a great programmer. You can download the MIT lectures somewhere as well, just Google them.
Thank you for posting these lectures, they are very clear and great for revising the basics from my uni days.
Lately I work mainly with C# and I'm grateful to have a garbage collector cleaning up after me, but it's good to remember not to abuse it and write bloated code!
Realmente todo lo explicado por el profesor Jerry Cain es fundamental ! si conoces esto es probable que no tengas muchos problemas incluso al implementar tu propio compilador o interprete! Excelente lecture.
He could have given a fuller response to the student who asked, why specify the size of an array if C is going to ignore it anyway? (at 19:30, array discussion at 15:45)
The answer is that if you didn't then the memory locations you access in the array would be memory conflicts just as locations outside the array range.
But that wouldn't really be a problem because the program wouldn't know where the array was anyway if it wasn't specified to begin with.
Also, the array declaration tells the compiler what data type the elements are, so it can do the pointer arithmetic for each indexed element. &chararray[1] == &chararray[0] + 1 byte, &intarray[1] == &intarray[0] + 4 bytes
Brilliant teaching here, wish my school was as good(or my family rich enough for stanford).
Also, does he sound like Nicolas Cage to anyone else?
Vote4Drizzt 3 weeks ago
WTF? Wouldn't ((char*)(&arr[1]))+8 bring him to &arr[3]? If the char is 1 byte, then you're moving 8 bytes from &char[1], which is two ints, which are each 4 bytes...
walkerneo 1 month ago
"does that make sence to people" not me -.-
jamesAboy19 2 months ago 3
It's just awesome.
salaschen 3 months ago
Will this teach me to program C or C++ ?? Someone Please Answer
KenmoreTownKillaz 4 months ago
@KenmoreTownKillaz right now, C. later perhaps C++.
jamebozo 3 months ago
@KenmoreTownKillaz it will give you a lot, but to learn to program it isn't only learning programming language...
vonlubcke 3 months ago
Respond to this video... i guess to answer more precise to your question, this is not the place to start
vonlubcke 3 months ago
what a great teacher! Way better than my comp science teachers in Eindhoven almost 20 years ago.
jjjdeste 4 months ago
I've been trying to learn programming/scripting languages for a while.
And because of my over-analytical mindset, I just couldn't 'get' half of it, so a good friend told me to look into programming principles.
And finally, although I'm going to do CompSci at University, I am finally getting it. Thank you Stanford and Prof Cain.
cbspace 4 months ago in playlist Course | Programming Paradigms
I've learn all of this in my college, but he make it perfectly clear here :D I'm glad I find this course :D
Alexhoanghtd 6 months ago
Чёто я недопонял. На 29:30 от arr[1] нужно 8 раз сместиться на размер char, т.е 8 байт. Размер сигмента int т.е. 4 байта, а он смещается на 4 сегмента, т.е. 16 байт. Ошибся? Или я чё-то не вкурил...
I have i little misunderstanding...On 29:30 we need to jump from arr[1] position 8 times on size of char (8*1=8bytes). Segment size is int (4bytes), but he jumps on 4 segments (4*4=16bytes). Mistake? Or its just me...
AesmaDiv 6 months ago in playlist Course | Programming Paradigms
@AesmaDiv
I think you just missed the arr[3].
We move 8 chars forward first, then we change to using short (4bytes) as the segment size and move to the fourth segment because he is writing the value 100 to arr[3], the fourth entity in the arr array.
Libervurto 5 months ago
@AesmaDiv I was thinking the same thing.... He was traversing the array of integers as if each box were containing 2 bytes instead of 4 bytes (probably confusing them as shorts). After the (char *) type cast, he would end up with a pointer to the 4th "box", or arr[3].
Ghouly89 4 months ago in playlist Ghouly89's Favorited Videos
@Ghouly89
i agree, it should be &arr[3] or arr + 3
glub0t 2 months ago
Yeah, it's a test. Everyone who commented on that is getting a scholarship to Stanford. Good job, you're in.
walkerneo 1 month ago
"double d" I see what you did there.
BacklTrack 8 months ago 4
sure....makes sense, but let me rewind that anyway
0000001100000 8 months ago in playlist Programming Paradigms
"Don't write code like this, just understand it ! " 30:18
ArturoDezaPeru 9 months ago 2
@ArturoDezaPeru
Nice one! Mind sharing how?
autonify 9 months ago
Thumbs up when he said "x box", your first thought jumps to xBox.
alex58765 9 months ago
"Does that make sense to people ?"
selfdealloc 9 months ago 6
@selfdealloc , Yh He Always Say that, It's Was Funny To Me, Specially That He Emphasizes on it, HaHaHa
evanescentdevil 9 months ago
1:55, self note
CSryoh 10 months ago
Degree is just one piece of paper, but knowledge that you have, is a real degree.
devidsimon 11 months ago 11
@devidsimon Yeah but you can't put 'I meet the requirements of such and such degree with knowledge' on your CV.
licriss 10 months ago
Comment removed
Blobblogger 11 months ago
Something I found quite interesting. Stanfords german motto at the beginning of each video reads "Die Luft der Freiheit weht" which relates to Stanfords german heritage and translates as "The air of freedom is waving" or "The wind of freedom blows"
mdinka 1 year ago
everything is Blue
userisdosser 1 year ago
How much does it cost to study @ Stanford per semester ?
selfdealloc 1 year ago
he is a good teacher ... thanks uploader for sharing this video on the internet ....
karmiclaw316 1 year ago
Those are some huge chalks he's using
imdando 1 year ago
@imdando I saw one guy using one the size of a can of soda. They don't f**k around with their chalk selection.
blehblah22 1 year ago
I mean the first bit is 2 not each bit. I think the 2 is on or off because 2 to the 0 is 0 so you either have a 0 or a 2 to a power. These are Int's. so when you say int num1
you store the char 1 in the int array. there are diff types of array. ones for numbers ones for signs, and so on. Yeah so it's kinda crazy.
silverpizza100 1 year ago
You can take classes online. But yeah you need your Gen Ed first.
This is Comp SCI 106 so they took like 4-5 computer classes before this one. Seems Linux is the OS people want to hire in. So this is useless in the real world. Java Scripting and Linux OS is a must. This guy is looking to program a chip or see what is on a chip. That is all this is. Knowing code and operations is the most important.
silverpizza100 1 year ago
This has been flagged as spam show
Oh I get it now.
keylazy 1 year ago
Any one know how he goes from 2 | 125 to 512+125 at 28:11? Thanks in advance.
keylazy 1 year ago
@keylazy In an array, each bit is 2 to the first, then the next bit is 2 to the second and so on from left to right on the array. Array is a microprocessor. So when he wrote 2 in the array, he defined the array as a short, That basically doubled the size of the processor by dividing the bits in half. so when you count over 4 it is really 8. so its 2 to the 8th not 2 to the 4th// Now its 2 to the 8th and since 125 sits in the same space , the processor will multiply them.
silverpizza100 1 year ago
@keylazy 125 is stored in the lower 8 bits and the 2 is stored in the higher 8 bits.
So the 2 is actually 2^9=512. This is just the way he represents it on the blackboard. The | is there to show the separation between two bytes.
LagnoleYT 1 year ago
Guys, does this make sense?
Alternativerealm 1 year ago 2
Yeah Stanford is way better than MIT! Video and audio that is.
silverpizza100 1 year ago
I love Mr. Cain. Yeah I am kinda keeping up. It's great to review on video like this. You won't miss parts of the lectures. Wish I have more background and knew some codes and so on. I know a little HTML but this is pretty advance, you got to start someplace I guess.
silverpizza100 1 year ago
I should just erase with the chalk...
devansthedude91 1 year ago
Does that make sense to people? OMG how many times does he have to say that. Maybe 100 times in just 3 videos. Jeez!
ThExChAmP1 1 year ago
@ThExChAmP1 As many times as he needs to make sense to people. Make sense?
hardstyle905 8 months ago
I loved it.
andrenyc 1 year ago
Comment removed
Impresentation 1 year ago
@29.28
I don't think he added the chars up correctly. The boxes represent integers which are four bytes each, a char is 1 byte so from the second box he adds 8 char sizes onto it which takes him to the start of the fourth box ( the one with the 2 and 128 in it ). He then casts that as a short pointer and jumps three shorts in which is one short away from the end of the array ( halfway through the last box ) .
Impresentation 1 year ago
@Impresentation I think you're right. At 29:39, as he starts adding up the char offset of 8 he mistakes the boxes in his original array as shorts.
imanelem 1 year ago 3
always amazes me how a computer works. each little pixel on the screen is referenced from a tiny little cell in a memory chip which is either On or Off.. i think.. (only know the basics)
BINLASH123 1 year ago
@BINLASH123 Actually every pixel is always turned on. You just modify it's color.
christy2drag 1 year ago
This comment has received too many negative votes show
are all these lectures just a bunch of examples thrown together almost spontaneously ? This is a very unusual style of teaching, in fact, for the first time in my life I feel like I'd be better off just reading a book rather than watching this b/s - quite an achievement, stanford!!
pinochet222 2 years ago
Actually this is extremely structured. This entire lecture is about one single concept.
31:00 was when my head exploded.
MrHateworker 2 years ago 3
@ 41:31
He's forgetting that he wrote character data, not numeric data, so the 3 in the first byte of numUnits is chracter '3' (value 51) not the number 3. He's also interpreting it as big endian when the computer's they're using are little endian.
iamacyborg 2 years ago
Comment removed
ILoveDogsandHarleys 2 years ago 3
You learned how to write generic vectors in C at community college?
MrHateworker 2 years ago
Comment removed
omfgfacts 1 year ago
@ILoveDogsandHarleys ILoveDogsandHarleysandCommunityCollege
omfgfacts 1 year ago
Can someone help me figure out why this code doesn't do what I expect? It should display 5, right?
int intArray[5];
intArray[3] = 5;
cout << ((short*)intArray)[7] << endl;
For some reason, it doesn't. I used this line to check if these addresses were the same:
cout << &((short*)intArray)[6] << " " << &intArray[3] << endl;
And they are. I even used sizeof to see if ints were 4 bytes and shorts were 2, and they are.
Any help would be appreciated.
Rickys706 2 years ago
Use subscript 6 instead of subscript 7 in your cout statement.
If you want to know why, it's because Intel processors are "little endian" (Google it).
iamacyborg 2 years ago 2
Heh, that's the one thing that I didn't think to check. Thanks.
Rickys706 2 years ago
It is because in memory of PC values are represented in such a way, so high byte is located as high address.
For example value 5 of type int will be represented as 0x05 00 00 00 and value 5 of type short will be 0x05 00.
So when you reference this ((short*)intArray)[7] , you actually reference to high byte of 3rd element, which is 00 00. To correct this, you must refer to 6th element of short: ((short*)intArray)[6].
Vanuany 2 years ago
Comment removed
chelvan2 2 years ago
Comment removed
pmelendezu 1 year ago
I think at 29:41 he is making a mistake by thinking of the array as an array of 5 short's (2 bytes each) but really he declared an array of 5 int's(4 bytes each).
I think the 100 would be placed in the last two bytes of arr[4].
Anyone agree/disagree?
montrealgamedev 2 years ago 3
I totally agree. he would end up in the middle of the last box. He takes the size of the boxes to be 2 bytes, while they in fact are ints, so 4 bytes. Well noticed. I didn't notice it the first time I saw it. Thanks for pointing it out.
glashopper 2 years ago
I agree. Where he went wrong was accidentally adding 16 onto the casted char* instead of 8 for the reason you said (mistaking the array for an array shorts).
It's easy to make a mistake like this when trying to explain something with lots of numbers and multiple typecasting.
ajito123 2 years ago
I agree, I noticed the same thing while I was watching.
Rickys706 2 years ago
OMG this is awesome. This teacher is coool. I want to go to Stanford :(
ApolloPwnsYou 2 years ago 49
Comment removed
moofymoo 2 years ago
I am studding CS during last 5-6 years, but this video is a very informative for me, and I just only now understand how represent array, structures in the memory...
mcfalu 2 years ago
mcfalu. I'm having difficulty understanding function pointers. Can you tell me which of these videos covers this?
elpresidio 2 years ago
This comment has received too many negative votes show
this videos are way to dry for my taste, i suggest learning from books for more action.
eileenBrain 2 years ago
blue boards are way cooler than green.
tobigforyou 2 years ago
Hey..maybe stanford university should give education for free so everyone else can learn through the computers...no? yes?..anyone?..does that make sense?
CamiloSanchez1979 2 years ago
how would they make money if it was free
PianoForteAndrew 2 years ago
is not about the money, is about a message to the world, didn't you watch batman the dark knight??..
CamiloSanchez1979 2 years ago
yes i saw that movie more times than anyone should, and i dont get how funding the education system and universities connects with it. perhaps you could explain a little bit more?
PianoForteAndrew 2 years ago
can't believe I gotta explain myself. The Joker at some point in the movie burns the money and cares for the message he want to send to the people of gotham. It connects in my sense that Stanford can be the Joker, and send a message of not caring about the money but about sending a message of altruism by sharing their fine education programs so others can follow. It doesn't have to be all programs, but some (like this one) could be enough..got me?? get out of my face..
CamiloSanchez1979 2 years ago
if Stanford puts most of it's lectures on the internet for free, who's going to pay the teachers to keep teaching??
BSREA5 2 years ago
ooo see thats why i didnt get it-because it doesnt make any sense. the joker represents chaos and anarchy, and thats why he burns the money, because he has no use for it., where as stanford university has plenty use for money, and yes, they could give some education freely, like they are in this youtube video and thats exactly what their doing. i dont have a problem with that point, its your stupid analogy which confused me
PianoForteAndrew 2 years ago
Lol, you can't get a degree on youtube can you?
c0lkowalski 2 years ago 34
Sort of. A few people I know have used free education from MIT and Stanford to skip through a lot of undergraduate courses in areas such as math and computer science, and are now doing a combined BS/MS while taking a mix of undergraduate and graduate classes. So it kind of helps you get an undergraduate degree. But you still need to be in the school and paying for your education.
bobthesmiley 2 years ago
@c0lkowalski You should be able to :). The future of education perhaps? We can dream.
ez910503 1 year ago
Comment removed
guitarfox 2 years ago
This is very good, but you should give him a better eraser :P
ismetteren 2 years ago 2
I'm more worried about giving him a dust mask...
he's inhaling a lot of that crap..
but he's really really good. he does not employ much jokes, but still makes the lecture interesting..
guitarfox 2 years ago 2
I'm just learning about C pointers and arrays right now and this is really making me understand. Great lectures. These and the old MIT "structure and interpretation of computer programs" lectures from 1986 (done in LISP) will make anyone a great programmer. You can download the MIT lectures somewhere as well, just Google them.
NameNotaNumber 2 years ago 3
SICP is the bible.
fasteez 2 years ago
"Does that make sense to people?"
That's my new catchphrase. People are going to be SO SICK of me pretty soon.
NameNotaNumber 2 years ago 5
thank you for sharing, but why are the high quality vids removed?
theegg89 2 years ago
This is very informative and useful as a supplement to anyone's CS education.
Hookstra 2 years ago
Aren't the students at Stanford pissed about all these lectures being available for anyone?
grablifebytheballs 3 years ago
better them pissed than every body else dumber.
someguyyoudontcare 2 years ago
thank you for sharing it
YeahNing 3 years ago
Thank you for posting these lectures, they are very clear and great for revising the basics from my uni days.
Lately I work mainly with C# and I'm grateful to have a garbage collector cleaning up after me, but it's good to remember not to abuse it and write bloated code!
Thanks Jerry.
qooopuk 3 years ago 2
Jerry is Excelent !!!!!!!!!!
Chandboy2008 3 years ago 3
Realmente todo lo explicado por el profesor Jerry Cain es fundamental ! si conoces esto es probable que no tengas muchos problemas incluso al implementar tu propio compilador o interprete! Excelente lecture.
kbradero 3 years ago 2
this deserves a 10 star rating! really! how come i didn't see this earlier? Thanks for posting these, great lecturer :)
aledel19 3 years ago 3
This is awesome. That's all there is to say.
dannypoofer 3 years ago 2
yay free college on youtube!
lschraiber 3 years ago 3
Indeed, not too many views.
I'm a Delphi programmer myself, but these kind of videos are helpfull even for a non-C programmer to be honest. Thank you Stanford!
Malevol3nt 3 years ago 2
He could have given a fuller response to the student who asked, why specify the size of an array if C is going to ignore it anyway? (at 19:30, array discussion at 15:45)
The answer is that if you didn't then the memory locations you access in the array would be memory conflicts just as locations outside the array range.
But that wouldn't really be a problem because the program wouldn't know where the array was anyway if it wasn't specified to begin with.
MoreApathy 3 years ago 2
Yep, that would have been useful to mention.
Also, the array declaration tells the compiler what data type the elements are, so it can do the pointer arithmetic for each indexed element. &chararray[1] == &chararray[0] + 1 byte, &intarray[1] == &intarray[0] + 4 bytes
mfnickster 1 year ago
does that make sense??
hehe, the new running gag :)
holya22 3 years ago 2
These are great!
.
.
.
"Does that make sense to people?" ... lol
tiffanto 3 years ago
dam, the view counts for stanford are low!!
it sucks that no one wants to learn!
frvfilms 3 years ago 2
It does suck. But if you want to be optimistic you can see that as less competition for us programmers.
marsrendezvous 3 years ago 2
yeah, your right!! let them learn their myspace, that going to get them far!!
frvfilms 3 years ago 2
Very good interpretation!!
menonfire12 3 years ago