No video

CS50x 2024 - Lecture 4 - Memory

  Рет қаралды 224,179

CS50

CS50

Күн бұрын

Пікірлер: 143
@Aprokind
@Aprokind 2 ай бұрын
If you are reading this, I hope you finish cs50 and go on to do well in whatever endeavor you choose.
@thebrightchannel6898
@thebrightchannel6898 28 күн бұрын
I will and i hope you will to, good luck!
@MasterOfYourself
@MasterOfYourself 4 ай бұрын
I love how David is really trying to hear people's questions, and he encourages them with cookies, or jokes.
@kent1k359
@kent1k359 2 ай бұрын
Best educator imho
@meegel
@meegel 7 ай бұрын
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 7 ай бұрын
Feeling honored to experience buffer overflow during the overflow section.
@BerkGoknil
@BerkGoknil 4 ай бұрын
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 5 ай бұрын
that little disappearing magic trick at 1:28:20 was subtle but nice
@realJaeyongLim
@realJaeyongLim 7 ай бұрын
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 7 ай бұрын
YES , keep it up champ🏆
@brandoncarris9015
@brandoncarris9015 Ай бұрын
thank you for your service !!!
@codewithsajid
@codewithsajid 8 ай бұрын
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
@xavier2586
@xavier2586 13 күн бұрын
Thank you so much Professor Malan.
@amirabdelli2295
@amirabdelli2295 7 ай бұрын
Starting 2024x here as this is where I was in the 2023x series (and I could definitely benefit from rewatching this one)
@yannicbrose
@yannicbrose 7 ай бұрын
same... :)
@randomforest_dev
@randomforest_dev 5 ай бұрын
CS50 2024 lectures are really awesome!
@The.Oh1183
@The.Oh1183 2 ай бұрын
Please tell me I'm not the only one whose brain collapsed...
@mohammadsuhaanhaq3590
@mohammadsuhaanhaq3590 2 ай бұрын
you are not my brain also got fried
@MeowMuscleTv
@MeowMuscleTv Ай бұрын
you not alone it diffucult for me too but don't give up !!
@DizzyBusy
@DizzyBusy Ай бұрын
No, I had to distract myself with the Euro Cup for a bit before coming back to this week's PSET
@AdityaWilson
@AdityaWilson Ай бұрын
Welcome to the gang
@FigueMonk
@FigueMonk 2 ай бұрын
I am here after trying to understand lecture 5. Probably is good idea to refresh these lecture's concepts. Keep learning folks, one day at time, step by step
@DanielHermeticoh
@DanielHermeticoh 6 ай бұрын
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
@hmmmzaDev
@hmmmzaDev 8 ай бұрын
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 8 ай бұрын
Same thing with me. That’s exactly what I am thinking
@user-yk1cw8im4h
@user-yk1cw8im4h 8 ай бұрын
u r just into lecture 4… of course continue with this
@Kampouse
@Kampouse 7 ай бұрын
its same content only a news "version"
@andoryu14
@andoryu14 6 ай бұрын
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
@kaunglin8447
@kaunglin8447 2 ай бұрын
I love you David. You are such a wonderful teacher.
@jonathanconnelly6993
@jonathanconnelly6993 Ай бұрын
Must finish before the end of summer…. Must finish before the end of summer….. keep going …
@victorbadia6709
@victorbadia6709 Ай бұрын
same bro we can do it!
@naboulsikhalid7763
@naboulsikhalid7763 2 ай бұрын
I am overwhelmed by the info introduced and very glad to know it and move with my C computing and programming. Thank you David
@user-uj6yj9jf1t
@user-uj6yj9jf1t 2 ай бұрын
can't wait to solve the assignment with these new tools. thank you david and whole cs50 team
@hawamigil4291
@hawamigil4291 Ай бұрын
What about tideman
@TheIonizator
@TheIonizator Ай бұрын
@@hawamigil4291 pls no
@davidestadilla8271
@davidestadilla8271 7 ай бұрын
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 5 ай бұрын
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()?
@thezaytunpeach
@thezaytunpeach 6 ай бұрын
That was a PHENOMENAL lecture but brother did it escalate...
@user-wm1ix4ej4h
@user-wm1ix4ej4h 2 ай бұрын
what an energetic teacher. Thanks David
@oanhtuan2408
@oanhtuan2408 4 ай бұрын
Love it again ❤ Thank you, David! This lesson teaches me how we can efficiently open a file by using just its first address.
@ridabrahim7604
@ridabrahim7604 7 ай бұрын
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 6 ай бұрын
string literal vs string in array is the reason for this. the former is immutable
@ridabrahim7604
@ridabrahim7604 5 ай бұрын
@@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.
@illillillill
@illillillill 6 ай бұрын
how wonderful teaching skill
@mr_riyajath
@mr_riyajath 6 ай бұрын
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 6 ай бұрын
no one cares
@davidoffonly
@davidoffonly 6 ай бұрын
​@@urosuros2072 hahahaha don't be that harsh man lol
@mr_riyajath
@mr_riyajath 5 ай бұрын
@@urosuros2072 did I ever mentioned your name and said that, if you don't like it just leave dude
@lovesickem3
@lovesickem3 Ай бұрын
That's also what I'm doing! I try hard not to fall asleep lol
@ayek707
@ayek707 Ай бұрын
Doing the problem sets right after the lectures would be a better idea because your brain is still fresh with knowledge from the lecture.
@harizhakim5983
@harizhakim5983 2 ай бұрын
the toughest lecture and problems for me so far!
@bpopphixo9627
@bpopphixo9627 22 күн бұрын
each video introduction: All right . This is CS50 LECTURE 3: ALGORITHMS
@brownie2006
@brownie2006 4 ай бұрын
I LOVE CS50
@sulikns4152
@sulikns4152 Ай бұрын
Yeah David you are great man! thanx a lot🙏🏻
@GenZ_01_
@GenZ_01_ Ай бұрын
Pure gold. Thank you Cs50 team
@ilove0908
@ilove0908 Ай бұрын
Very useful lecture. Thanks a lot !!
@sibusisomakema7718
@sibusisomakema7718 6 ай бұрын
glad to see that the training wheel joke landed this year😂
@kenlow4048
@kenlow4048 4 ай бұрын
mind blowing
@virendxr
@virendxr 7 ай бұрын
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 7 ай бұрын
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 7 ай бұрын
@@andrewpolakaus woh that's nice, thanks!
@ZerubbabelT.
@ZerubbabelT. 3 ай бұрын
@@andrewpolakaus Why double astrex on z?
@andrewpolakaus
@andrewpolakaus 3 ай бұрын
​@@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.
@ZerubbabelT.
@ZerubbabelT. 3 ай бұрын
@@andrewpolakaus Got it. Thanks
@berkaycirak
@berkaycirak 4 ай бұрын
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 4 ай бұрын
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.
@kmlime
@kmlime 7 ай бұрын
I miss the old intro 😢 but the course is amazing regardless
@user-mm8ml1ku4g
@user-mm8ml1ku4g 7 ай бұрын
best week of C i bet
@_allegra
@_allegra 7 ай бұрын
1:34:17 Caleb missing the opportunity to down one of the glasses and demonstrate clearing the memory allocation
@muhammadmx
@muhammadmx 7 ай бұрын
that would have not kept the original glasses swaped
@not_amanullah
@not_amanullah 2 ай бұрын
Thanks ❤
@adnancodesweb
@adnancodesweb 27 күн бұрын
I listen to this to go to sleep.. This is where I go to when I drift away and start day dreaming 😆
@yunleung2631
@yunleung2631 3 ай бұрын
Must review notes. I barely understood the lecture
@proudathiest
@proudathiest 2 ай бұрын
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 2 ай бұрын
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 2 ай бұрын
@@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?
@not_amanullah
@not_amanullah 6 ай бұрын
Understood++
@wecode007
@wecode007 7 ай бұрын
wanted to study at harvard; but failed; dont worry we have david
@davidc8413
@davidc8413 4 ай бұрын
Professor Malin is an actual robot
@BonnieByte
@BonnieByte 7 ай бұрын
Very interesting
@TheNothing93
@TheNothing93 7 ай бұрын
DONE
@gamerdenver7811
@gamerdenver7811 8 ай бұрын
thx
@shrutisinghal2490
@shrutisinghal2490 3 ай бұрын
Thank you Sir, for amazing teaching😃 will be always thankful for giving us CS50
@OkuEfiong
@OkuEfiong Ай бұрын
Please what kind of VScode is David using, because my VScode terminal is not working?
@ares1647
@ares1647 2 ай бұрын
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 2 ай бұрын
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.
@ZerubbabelT.
@ZerubbabelT. 3 ай бұрын
21:02 Why am I not getting hexadecimal number?Instead its decimal number
@regularnick
@regularnick 2 ай бұрын
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
@clarerussell1
@clarerussell1 2 ай бұрын
It's explained in previous lectures. If you check out their library you will see how get_string works
@JAVPindia0
@JAVPindia0 Ай бұрын
Did you mean playlist? When you say library or that's something different from that?​@@clarerussell1
@DizzyBusy
@DizzyBusy Ай бұрын
I second the previous comment. Just go to the library to see what get_string actually is
@nbtwall7287
@nbtwall7287 3 ай бұрын
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 3 ай бұрын
addresses are unsigned integers
@shockmethodx
@shockmethodx 5 ай бұрын
Is it convention or preference to say "oh" when encountering a zero?
@aopen130
@aopen130 5 ай бұрын
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.
@nicholasvandremo5867
@nicholasvandremo5867 3 ай бұрын
How is p an integer when it contains alphabetical values? Like 0x123 has 'x' in it`s value?
@ninjamar_
@ninjamar_ 3 ай бұрын
0x123 is hexadecimal, which is a type of notation for numbers
@mosstah
@mosstah 2 ай бұрын
@@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_ 2 ай бұрын
@@mosstah yeah, it helps distinguish between decimal
@100drips
@100drips Ай бұрын
after 3 weeks of trying to solve tidemen, i can finally watch this lecture :D
@RameezRassel
@RameezRassel Ай бұрын
hey mah i spend like 16 hours on it and i gave up . i am not able to do the last 2 functions. i dont even have an idea on how to do it. You got any advise for me?
@100drips
@100drips Ай бұрын
@@RameezRassel 16 hours is nothing, haha 😅 Here was my idea, that finally worked: To detect a cycle, look, if the loser of the pair you are trying to lock is a winner of an already locked pair. If so, is the winner of the pair you are trying to lock the loser in the locked pair? When this is the case, you've detected a very simple cycle. For example, when A is winner over B in the first locked pair and you try to lock in B over A. This is obvious and fairly simple. But if the winner of the pair you are trying to lock is not the loser, you have to check the next pair down the line. So in this case, look if the loser of the first locked pair is the winner of another locked pair. If so, does the loser of this pair equal the winner of the pair you are initially trying to lock in? If yes, a cycle is detected. If not, look for the next locked pair. Hint: a recursive function is very useful for this. I actually did a few exercises with recursion beforehand to really wrap my head around the concept. Good luck, you can do it!
@RameezRassel
@RameezRassel Ай бұрын
@@100drips hey thanks a lot mahn. Really Appreciate it. I was doing my research and it turns out there is an algorithm for traversing throughout graphs. It's called DFS I tried learning it but couldn't wrap my head around it . I think I understand ur logic now I have to code it. We'll see
@thebrightchannel6898
@thebrightchannel6898 28 күн бұрын
@@RameezRassel Bro were you able to code it?
@nicholasvandremo5867
@nicholasvandremo5867 3 ай бұрын
@42:32 David says that *s is the address, but isn`t it actually a pointer to the first character in the character array?
@Marco-sm9bu
@Marco-sm9bu 2 ай бұрын
yes, &s is the address
@murrigo
@murrigo 3 ай бұрын
1:43 "or a jif or a ping"... David... my stars I almost stopped watching
@phellipecardoso8994
@phellipecardoso8994 Ай бұрын
1:04:00
@dxdx7961
@dxdx7961 23 күн бұрын
hello I have a question 43:00 char *s and char s[] is the same ?
@sein349
@sein349 15 күн бұрын
char *s points at the first (0th) location of the string. Which means the string will be read from that location till the null (\0) to highlight the whole string. Meanwhile char s[] highlights the whole string (list of chars) right away. hope this helped
@sinajps378
@sinajps378 4 ай бұрын
i have a doubt . Why dont we use *s instead of s to print out the string
@DizzyBusy
@DizzyBusy Ай бұрын
That was explained in the "Strings" chapter of the video
@codeandtech77
@codeandtech77 10 күн бұрын
I don't really get what the function "malloc ()" really does. Anyone who understands this concept please help me to understand it too.
@hritviksoni6080
@hritviksoni6080 10 күн бұрын
okay ! ill try to explain it, simply put , malloc is a function defined in header file , simply like printf is defined in and get_int defined in , its job is to allocate some space from your memory for you to do something on it for example store some data. Consider these statements 1. char *s = get_string("s: "); 2. char *t = malloc(string length (s) + 1); --> 1. gets string input from user and stores it in s --> 2. allocates memory of string length+1 (+1 to store \0 which signifies the end of a string ) for you to do something in the allocated memory from your storage.
@codeandtech77
@codeandtech77 3 күн бұрын
@@hritviksoni6080 Thanks a lot! Appreciate your kindness. I kind of didn't understand this line: " gets string input from user and stores it in s --> 2" .
@syedzainulabideen4455
@syedzainulabideen4455 8 ай бұрын
1like = 5pushups in 2024
@yashsond3675
@yashsond3675 7 ай бұрын
Khao maa kasam😂
@Mubashar783
@Mubashar783 3 ай бұрын
​@@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😢
@Naoty_san
@Naoty_san 7 ай бұрын
30:43
@abdulmelik8337
@abdulmelik8337 2 ай бұрын
Questions?
@stormbringer6255
@stormbringer6255 4 ай бұрын
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
@georgimmitev
@georgimmitev 2 ай бұрын
1:32:26
@prof-pras
@prof-pras 23 күн бұрын
29:31 haha!!
@bordercut1
@bordercut1 4 ай бұрын
wow.
@georgimmitev
@georgimmitev 2 ай бұрын
9:57
@quang.luu.179
@quang.luu.179 2 ай бұрын
👍👍👍
@duydangdroid
@duydangdroid 2 ай бұрын
29:24 lol
@exomk5319
@exomk5319 14 күн бұрын
19:05
@exomk5319
@exomk5319 14 күн бұрын
34:00
@exomk5319
@exomk5319 14 күн бұрын
string = char *
@exomk5319
@exomk5319 14 күн бұрын
42:10
@exomk5319
@exomk5319 14 күн бұрын
43:30 44:40
@bpopphixo9627
@bpopphixo9627 16 күн бұрын
Swappp too hard
@WizeChoice
@WizeChoice 5 ай бұрын
👉🏾✨✨✨
@bpopphixo9627
@bpopphixo9627 15 күн бұрын
hard vc
@hankhan5629
@hankhan5629 5 ай бұрын
please save our videos memories and do intermittent fasting for our longevity.
@user-lu7ts8hj2i
@user-lu7ts8hj2i 4 ай бұрын
😎😎😍🥰🥰
@bonjourmonsieur8221
@bonjourmonsieur8221 6 ай бұрын
42 42 42 42 42
@4olufade
@4olufade 2 ай бұрын
Conor should have made it to the press conference with a broken toe
@govindbahadur8334
@govindbahadur8334 6 ай бұрын
like who is watching in feb 😅
@hankhan5629
@hankhan5629 5 ай бұрын
“贫穷限制了我的想象力。”
@sathishp3180
@sathishp3180 6 ай бұрын
30:36
CS50x 2024 - Lecture 5 - Data Structures
2:02:49
CS50
Рет қаралды 316 М.
CS50x 2024 - Artificial Intelligence
55:57
CS50
Рет қаралды 144 М.
Bony Just Wants To Take A Shower #animation
00:10
GREEN MAX
Рет қаралды 7 МЛН
拉了好大一坨#斗罗大陆#唐三小舞#小丑
00:11
超凡蜘蛛
Рет қаралды 14 МЛН
Computer Scientist Answers Computer Questions From Twitter
14:27
Generative AI Legal Assistance from Thomson Reuters CoCounsel
1:07:10
AmericanBarTIPS
Рет қаралды 3,6 М.
CS50x 2024 - Lecture 6 - Python
2:09:03
CS50
Рет қаралды 335 М.
CS50x 2024 - Lecture 7 - SQL
2:14:05
CS50
Рет қаралды 440 М.
CS50x 2024 - Lecture 0 - Scratch
2:04:55
CS50
Рет қаралды 1,1 МЛН
God-Tier Developer Roadmap
16:42
Fireship
Рет қаралды 7 МЛН
CS50x 2024 - Lecture 3 - Algorithms
2:02:12
CS50
Рет қаралды 263 М.
you will never ask about pointers again after watching this video
8:03
Low Level Learning
Рет қаралды 2,1 МЛН
Bony Just Wants To Take A Shower #animation
00:10
GREEN MAX
Рет қаралды 7 МЛН