Тёмный

CS50x 2024 - Lecture 4 - Memory 

CS50
Подписаться 1,9 млн
Просмотров 149 тыс.
50% 1

***
This is CS50, Harvard University's introduction to the intellectual enterprises of computer science and the art of programming.
***
TABLE OF CONTENTS
00:00:00 - Introduction
00:01:01 - Pixel Art
00:06:57 - Hexadecimal
00:14:23 - Memory
00:21:43 - Pointers
00:30:43 - Strings
00:48:27 - Pointer Arithmetic
00:52:05 - String Comparison
01:04:52 - Copying
01:16:49 - malloc and Valgrind
01:24:11 - Garbage Values
01:29:10 - Pointer Fun with Blinky
01:32:00 - Swapping
01:46:27 - Overflow
01:49:36 - scanf
02:02:11 - File I/O
***
HOW TO SUBSCRIBE
ru-vid.com_c...
HOW TO TAKE CS50
edX: cs50.edx.org/
Harvard Extension School: cs50.harvard.edu/extension
Harvard Summer School: cs50.harvard.edu/summer
OpenCourseWare: cs50.harvard.edu/x
HOW TO JOIN CS50 COMMUNITIES
Discord: / discord
Ed: cs50.harvard.edu/x/ed
Facebook Group: / cs50
Faceboook Page: / cs50
GitHub: github.com/cs50
Gitter: gitter.im/cs50/x
Instagram: / cs50
LinkedIn Group: / 7437240
LinkedIn Page: / cs50
Medium: / cs50
Quora: www.quora.com/topic/CS50
Reddit: / cs50
Slack: cs50.edx.org/slack
Snapchat: / cs50
SoundCloud: / cs50
Stack Exchange: cs50.stackexchange.com/
TikTok: / cs50
Twitter: / cs50
RU-vid: / cs50
HOW TO FOLLOW DAVID J. MALAN
Facebook: / dmalan
GitHub: github.com/dmalan
Instagram: / davidjmalan
LinkedIn: / malan
Quora: www.quora.com/profile/David-J...
TikTok: / davidjmalan
Twitter: / davidjmalan
***
CS50 SHOP
cs50.harvardshop.com/
***
LICENSE
CC BY-NC-SA 4.0
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License
creativecommons.org/licenses/...
David J. Malan
cs.harvard.edu/malan
malan@harvard.edu

Опубликовано:

 

16 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 99   
@MasterOfYourself
@MasterOfYourself 2 месяца назад
I love how David is really trying to hear people's questions, and he encourages them with cookies, or jokes.
@kent1k359
@kent1k359 7 дней назад
Best educator imho
@meegel
@meegel 5 месяцев назад
Theres a lot of "A-HA" moments for me this week, it is incredibly motivational for me to keep on learning CS. Thank you Professor Malan and the CS50 team!
@worrystone
@worrystone 5 месяцев назад
Feeling honored to experience buffer overflow during the overflow section.
@BerkGoknil
@BerkGoknil 2 месяца назад
Even if you have been writing programmes for 20 years, it is an excellent series that must be completed to the end. Thank you David and Harvard.
@kurrizzle
@kurrizzle 2 месяца назад
that little disappearing magic trick at 1:28:20 was subtle but nice
@Aprokind
@Aprokind 4 дня назад
If you are reading this, I hope you finish cs50 and go on to do well in whatever endeavor you choose.
@DanielHermeticoh
@DanielHermeticoh 4 месяца назад
Thank you, David, for your amazing teaching skills! I can't believe I'm being able to understand aaaaall this information having started learning computer science this year
@amirabdelli2295
@amirabdelli2295 5 месяцев назад
Starting 2024x here as this is where I was in the 2023x series (and I could definitely benefit from rewatching this one)
@yannicbrose
@yannicbrose 5 месяцев назад
same... :)
@realJaeyongLim
@realJaeyongLim 4 месяца назад
I started CS50 since 2021 but did not make it to the endpoint. Now I have decided to resume it while serving at the military. I really love watching Professor Malan's lectures:)
@Senko1800
@Senko1800 4 месяца назад
YES , keep it up champ🏆
@randomforest_dev
@randomforest_dev 3 месяца назад
CS50 2024 lectures are really awesome!
@oanhtuan2408
@oanhtuan2408 Месяц назад
Love it again ❤ Thank you, David! This lesson teaches me how we can efficiently open a file by using just its first address.
@codewithsajid
@codewithsajid 5 месяцев назад
for those scratching your head at 49:20, perhaps this will help. what is the relationship between arrays and pointers/addresses? --- In C, arrays and pointers are closely related. Here's a breakdown of their relationship: 1. Array Name as a Pointer: When you define an array in C, the array name acts as a pointer to the first element of the array. For instance, if you have int arr[10];, arr can be thought of as a pointer to arr[0]. 2. Pointer Arithmetic: You can perform arithmetic on pointers just as you can with arrays. When you increment a pointer that points to an array, it points to the next element of the array. This is because the size of the type the pointer points to is considered in the arithmetic. 3. Indexing: You can access elements of an array using the subscript notation []. Under the hood, this is converted to pointer arithmetic. The expression arr[i] is equivalent to *(arr + i). This means "get the value at the address arr plus i times the size of the array's element type". --- Thanks chatgpt
@user-uj6yj9jf1t
@user-uj6yj9jf1t 16 дней назад
can't wait to solve the assignment with these new tools. thank you david and whole cs50 team
@user-wm1ix4ej4h
@user-wm1ix4ej4h 16 дней назад
what an energetic teacher. Thanks David
@harizhakim5983
@harizhakim5983 4 дня назад
the toughest lecture and problems for me so far!
@illillillill
@illillillill 4 месяца назад
how wonderful teaching skill
@hmmmzaDev
@hmmmzaDev 5 месяцев назад
I was just watching the lecture 4 of CS50-2023x and during the break, I have stumbled onto this video. Not sure now if I should continue watching that one or start from here again.
@harpsprince7576
@harpsprince7576 5 месяцев назад
Same thing with me. That’s exactly what I am thinking
@user-yk1cw8im4h
@user-yk1cw8im4h 5 месяцев назад
u r just into lecture 4… of course continue with this
@Kampouse
@Kampouse 5 месяцев назад
its same content only a news "version"
@andoryu14
@andoryu14 3 месяца назад
the 2024 versions are almost exactly the same and the course itself now asks you to do the 2024 version, and carries over progress from 2023
@ridabrahim7604
@ridabrahim7604 5 месяцев назад
there is something guys about changing the string s to char *s, if you do this without the cs50.h you can't change the value of a char in a string, i was going back and forth with chatgpt until i tested it myself, even if professor david changed string s to char *s the actual string which is "Hi!" cannot be changed by trying to change char H like this : s[0] = 'h'; , you're probably asking yourself why and it's because the get_string function is returning an actual array that we store it's address in char *s and not the same thing when creating a string on the fly with the pointer, two different things, if you're creating a string on the fly without using [ ] to tell C it's an array you won't be able to change the characters in the string, I'm telling this to anyone got stuck with this asking himself this question, professor david probably didn't reveal this so things doesn't escalate quickly and I'm only 55min in so probably he's gonna reveal it later.
@ethylmusic
@ethylmusic 3 месяца назад
string literal vs string in array is the reason for this. the former is immutable
@ridabrahim7604
@ridabrahim7604 3 месяца назад
@@ethylmusic yeah, at the time it took me a while to get this while the compiler kept giving me errors then i found out it's read only and can't change it until i copy the string to an actual allocated memory and it seems that the get_string function actually does that.
@davidestadilla8271
@davidestadilla8271 5 месяцев назад
Just want to add something on pointer arithmetic. If you had a pointer to an integer (which consists of 4 bytes) and allocate memory for two integers and for some reason, you want to put values in it using the dereference (*) symbol, you should not do the following: int *n = malloc(sizeof(int) * 2) *n = 1 *(n + 4) = 2 or *(n + sizeof(int)) = 2 Instead, you should do this: int *n = malloc(sizeof(int) * 2) *n = 1 *(n + 1) = 2 No need to type in the quantity of bytes for the specific data type (in this case, it's 4 since it's an integer). C already knows that.
@a23oj28
@a23oj28 3 месяца назад
Is this the same as an array of ints but just dynamically allocated? Does C know because of the type (int) that n points to or does it infer from the argument of malloc()?
@williamsmith9948
@williamsmith9948 3 месяца назад
@@a23oj28 It’s the block size of the memory allocation that the pointer is pointing to.
@kenlow4048
@kenlow4048 2 месяца назад
mind blowing
@thezaytunpeach
@thezaytunpeach 4 месяца назад
That was a PHENOMENAL lecture but brother did it escalate...
@sibusisomakema7718
@sibusisomakema7718 4 месяца назад
glad to see that the training wheel joke landed this year😂
@brownie2006
@brownie2006 Месяц назад
I LOVE CS50
@BonnieByte
@BonnieByte 4 месяца назад
Very interesting
@nicholasvandremo5867
@nicholasvandremo5867 Месяц назад
@42:32 David says that *s is the address, but isn`t it actually a pointer to the first character in the character array?
@gamerdenver7811
@gamerdenver7811 5 месяцев назад
thx
@fundef
@fundef Месяц назад
Week 4 Let's goooooo
@mr_riyajath
@mr_riyajath 4 месяца назад
I lost my streak of watching one lecture per day, but I convinced myself to resume watching from where I left off. Today, I finished watching lecture 4 and I am determined to complete CS50 by the first week of February. After that, I plan to solve the problem sets and then I am thinking of learning JavaScript next.
@urosuros2072
@urosuros2072 4 месяца назад
no one cares
@davidoffonly
@davidoffonly 4 месяца назад
​@@urosuros2072 hahahaha don't be that harsh man lol
@williamsmith9948
@williamsmith9948 3 месяца назад
Good job my friend. Keep going!
@mr_riyajath
@mr_riyajath 2 месяца назад
@@urosuros2072 did I ever mentioned your name and said that, if you don't like it just leave dude
@user-mm8ml1ku4g
@user-mm8ml1ku4g 5 месяцев назад
best week of C i bet
@shrutisinghal2490
@shrutisinghal2490 Месяц назад
Thank you Sir, for amazing teaching😃 will be always thankful for giving us CS50
@berkaycirak
@berkaycirak 2 месяца назад
56:12, I have a question about comparison. While we comparing two string, we compare its first char's addresses. Also, while we comparing two integer, why didn't we compare its addresses? I thought, while comparing two equal integer, their addresses will be different. For example, int n = 5; int x=5; . There will be two different addresses for n and x, and if we compare addresses they must be different
@sagarpanwar2845
@sagarpanwar2845 Месяц назад
because in int we compare their values not their address, because in string your variable contain a address of the first char and in int your variable contain a integer not their address.
@shockmethodx
@shockmethodx 3 месяца назад
Is it convention or preference to say "oh" when encountering a zero?
@not_amanullah
@not_amanullah 4 месяца назад
Understood++
@sinajps378
@sinajps378 2 месяца назад
i have a doubt . Why dont we use *s instead of s to print out the string
@virendxr
@virendxr 5 месяцев назад
21:17 so a pointer is simpy a varible which stores the memeory address of some other variable inside the variable called pointer . So do pointer variables* also have their own address? and can the adrees of pointer variables can be stored in another pointer variable?
@andrewpolakaus
@andrewpolakaus 5 месяцев назад
Yes. Examples: // x is a char char x; // y is a pointer to a char that stores the address of x char *y = &x // z is a pointer to a pointer to a char that stores the address of y. char **z = &y
@virendxr
@virendxr 5 месяцев назад
@@andrewpolakaus woh that's nice, thanks!
@williamsmith9948
@williamsmith9948 3 месяца назад
Points to a memory address in general. Usually (but doesn’t have to be) a variable.
@ZerubbabelT.
@ZerubbabelT. Месяц назад
@@andrewpolakaus Why double astrex on z?
@andrewpolakaus
@andrewpolakaus Месяц назад
​@@ZerubbabelT. that's a great question! If we declare "char x" then x is of type "char" i.e. x can store a char. Now iff we declare "char *y" then y is of type "pointer to a char" i.e. y can store the address of a char. And finally, if we declare "char **z" then z is of type "pointer to a pointer to a char" i.e. z can store the address of something that stores the address of a char. Each star add a level of indirection.
@TheNothing93
@TheNothing93 5 месяцев назад
DONE
@ares1647
@ares1647 5 дней назад
At 38:45, why put & before s[0] when it was not necessary in a line above and it still worked ? Also, printf format specified we're looking for an address with "%p".
@shubhamshetty3918
@shubhamshetty3918 4 дня назад
Correct, Both are the same & points to the same address, the first one just points to the first address as a whole while the other points out to the address of the first char in that array. Hope it gives more clarity.
@aopen130
@aopen130 2 месяца назад
36:18 oh 32 bit max out at 2 billion addreses. So that's why the FAT32 doesn't go very high in partition like exFAT. Makes sense.
@nbtwall7287
@nbtwall7287 Месяц назад
27:19 Professor Malan said the memory address 'p' is storing an integer. Are memory addresses signed? does the computer track negative spaces in memory?
@shiny5176
@shiny5176 Месяц назад
addresses are unsigned integers
@ZerubbabelT.
@ZerubbabelT. Месяц назад
21:02 Why am I not getting hexadecimal number?Instead its decimal number
@kmlime
@kmlime 5 месяцев назад
I miss the old intro 😢 but the course is amazing regardless
@regularnick
@regularnick 3 дня назад
it's kinda sad that he didn't explain with the code how the CS50 get_string actually works. Unfortunately, for now this is the only training wheel I can't take off
@The.Oh1183
@The.Oh1183 15 дней назад
Please tell me I'm not the only one whose brain collapsed...
@mohammadsuhaanhaq3590
@mohammadsuhaanhaq3590 15 дней назад
you are not my brain also got fried
@proudathiest
@proudathiest 11 дней назад
If the computer needs a pointer (s) to go to the address of the first char, how does it find s in memory to get to the char?
@mosstah
@mosstah 8 дней назад
It stores and accesses the pointer in the same way it accesses any other variable, such as storing a char without bothering with any pointers. However, if the pointer was replaced with a simple char variable, the computer would only return that character and wouldn't know to look for the rest of the values in the string which is why the pointer is necessary.
@proudathiest
@proudathiest 8 дней назад
@@mosstah But how does it access any variable? If I write int x = 10, and then use x later in the code, how does it find that x is 10?
@yunleung2631
@yunleung2631 20 дней назад
Must review notes. I barely understood the lecture
@Naoty_san
@Naoty_san 5 месяцев назад
30:43
@davidc8413
@davidc8413 2 месяца назад
Professor Malin is an actual robot
@wecode007
@wecode007 5 месяцев назад
wanted to study at harvard; but failed; dont worry we have david
@abdulmelik8337
@abdulmelik8337 10 дней назад
Questions?
@_allegra
@_allegra 5 месяцев назад
1:34:17 Caleb missing the opportunity to down one of the glasses and demonstrate clearing the memory allocation
@muhammadmx
@muhammadmx 5 месяцев назад
that would have not kept the original glasses swaped
@georgimmitev
@georgimmitev 11 дней назад
1:32:26
@nicholasvandremo5867
@nicholasvandremo5867 Месяц назад
How is p an integer when it contains alphabetical values? Like 0x123 has 'x' in it`s value?
@ninjamar_
@ninjamar_ Месяц назад
0x123 is hexadecimal, which is a type of notation for numbers
@mosstah
@mosstah 7 дней назад
@@ninjamar_while this is true for the “123” part, the 0x isn’t a part of the value and is just standard convention for indicating that the following number is hexadecimal
@ninjamar_
@ninjamar_ 6 дней назад
@@mosstah yeah, it helps distinguish between decimal
@quangluu79
@quangluu79 2 дня назад
👍👍👍
@murrigo
@murrigo 19 дней назад
1:43 "or a jif or a ping"... David... my stars I almost stopped watching
@bordercut1
@bordercut1 Месяц назад
wow.
@georgimmitev
@georgimmitev 12 дней назад
9:57
@WizeChoice
@WizeChoice 2 месяца назад
👉🏾✨✨✨
@stormbringer6255
@stormbringer6255 Месяц назад
int a = 9; int b = 0; printf("%i ", a); //Printing the value of a printf("%i ", b); //Printing the value of b printf("%p ", &a); //Printing the address of a printf("%p ", &b); //Printing the address of b printf("%d ", *(&a)); //Printing the value of a using the address of a printf("%d ", *(&b)); //Printing the value of b using the address of b int *c = &a; int *d = &b; printf("%p ", c); //Printing the value of c printf("%p ", d); //Printing the value of d printf("%d ", *c); //Printing the value of the address in c as a pointer value printf("%d ", *d); //Printing the value of the address in d as a pointer value
@user-lu7ts8hj2i
@user-lu7ts8hj2i 2 месяца назад
😎😎😍🥰🥰
@bonjourmonsieur8221
@bonjourmonsieur8221 3 месяца назад
42 42 42 42 42
@hankhan5629
@hankhan5629 2 месяца назад
please save our videos memories and do intermittent fasting for our longevity.
@syedzainulabideen4455
@syedzainulabideen4455 5 месяцев назад
1like = 5pushups in 2024
@yashsond3675
@yashsond3675 5 месяцев назад
Khao maa kasam😂
@Mubashar783
@Mubashar783 Месяц назад
​@@yashsond3675 Jhoot nhi bol kafi mehnat k bad mera avergae push up rate 40+ he 60+ tk gaya tha jin ko dikhanna tha wo majak bnane lg gae😢
@govindbahadur8334
@govindbahadur8334 4 месяца назад
like who is watching in feb 😅
@hankhan5629
@hankhan5629 2 месяца назад
“贫穷限制了我的想象力。”
@sathishp3180
@sathishp3180 4 месяца назад
30:36
Далее
CS50x 2024 - Lecture 5 - Data Structures
2:02:49
Просмотров 235 тыс.
Пранк над Катей 🤣🤣🤣
01:00
Просмотров 172 тыс.
Just try to use a cool gadget 😍
00:33
Просмотров 63 млн
i wrote my own memory allocator in C to prove a point
5:23
Why do Most New Developers Quit Early?
4:45
Просмотров 1,1 тыс.
CS50x 2024 - Lecture 3 - Algorithms
2:02:12
Просмотров 182 тыс.
Пранк над Катей 🤣🤣🤣
01:00
Просмотров 172 тыс.