CS50x 2024 - Lecture 4 - Memory

preview_player
Показать описание
***

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

HOW TO TAKE CS50

HOW TO JOIN CS50 COMMUNITIES

HOW TO FOLLOW DAVID J. MALAN

***

CS50 SHOP

***

LICENSE

CC BY-NC-SA 4.0
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License

David J. Malan
Рекомендации по теме
Комментарии
Автор

If you are reading this, I hope you finish cs50 and go on to do well in whatever endeavor you choose.

Aprokind
Автор

I love how David is really trying to hear people's questions, and he encourages them with cookies, or jokes.

MasterOfYourself
Автор

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!

meegel
Автор

Feeling honored to experience buffer overflow during the overflow section.

worrystone
Автор

that little disappearing magic trick at 1:28:20 was subtle but nice

kurrizzle
Автор

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.

BerkGoknil
Автор

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:)

realJaeyongLim
Автор

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

codewithsajid
Автор

Starting 2024x here as this is where I was in the 2023x series (and I could definitely benefit from rewatching this one)

amirabdelli
Автор

Please tell me I'm not the only one whose brain collapsed...

The.Oh
Автор

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.

hmmmzaDev
Автор

CS50 2024 lectures are really awesome!

randomforest_dev
Автор

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

FigueMonk
Автор

Thank you, David, for your amazing teaching skills! I can't believe I'm being able to understand this information having started learning computer science this year

DanielHermeticoh
Автор

Must finish before the end of summer…. Must finish before the end of summer….. keep going …

jonathanconnelly
Автор

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.

davidestadilla
Автор

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.

ridabrahim
Автор

I love you David. You are such a wonderful teacher.

kaunglin
Автор

can't wait to solve the assignment with these new tools. thank you david and whole cs50 team

ujyjjft
Автор

I am overwhelmed by the info introduced and very glad to know it and move with my C computing and programming. Thank you David

naboulsikhalid
join shbcf.ru