you will never ask about pointer arithmetic after watching this video

you will never ask about pointer arithmetic after watching this video

Low Level Learning

2 года назад

224,463 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

CoolKoon
CoolKoon - 11.11.2023 23:57

Okay, that does make sense, although it's somewhat counterintuitive. BTW the program crashed at the end probably because with the for loop you've tried to access values outside of the "people" array after the i counter got to 19 or so.

Ответить
Adsan
Adsan - 05.11.2023 03:15

For me the hardest thing about C (and C++ too) is that it has a tendency to explode. It will casually allow you to do some really dumb shit, like overwriting some random part of memory

Ответить
Raphaël Ambrosius 'fingerguns' Costeau
Raphaël Ambrosius 'fingerguns' Costeau - 04.11.2023 18:24

pointer math is an anti-pattern

Ответить
Gamefreak612 :)
Gamefreak612 :) - 25.10.2023 22:20

I hate pointers but I really want to learn c

Ответить
betapacket
betapacket - 20.10.2023 16:20

What is pointer arithmetic?

Ответить
Das_Unterstrich
Das_Unterstrich - 20.10.2023 06:21

I directly learned to "move" pointers with just using p_Person++;, surprised to find out it isn't the default case.

Ответить
Dani
Dani - 20.10.2023 05:21

so actually, there's no arithmetics at all!! 🤯

Ответить
calral
calral - 17.10.2023 12:43

i admit it, i just use pointers when they fix a bug in my code...

Ответить
Wouter Grond
Wouter Grond - 16.10.2023 21:03

All you need to do is remove the '&' at line 13.

Ответить
Sloppy Puppy
Sloppy Puppy - 05.10.2023 17:04

It all makes sense, you are not trying to access the next byte, you are accessing the next element in the array, p_Person stores the address of the first people element, by incrementing it by 1, you are now accessing the next element in the array, meanwhile the way you access the struct itself is again de referencing that specific Person element by doing p_Person->age.

Ответить
Technical Concepts
Technical Concepts - 30.09.2023 14:54

Do you have a video where you talk about void pointers and pointers to pointers?

Ответить
Maname IsJeffie
Maname IsJeffie - 24.09.2023 03:19

wait isn't p_Person that's an integer so then increasing it by 1 will mean that it's gonna go to the next element of the array (if let's say p_Person is equal to 0x100 in the first iteration where were in element zero in the array, then when we increment p_Person by 1, it's gonna be equal to 0x101 or the next address which is the next element of the array since they are one line of memory (so like a sequence of addresses will reference a sequence of elements in the array in the same order) ) am pretty new to C so what i might be saying could be wrong

Ответить
Knuckles #2761
Knuckles #2761 - 21.09.2023 15:20

First rule of pointer arithmetic - don't ask about pointer arithmetic.

Ответить
KoreanClown
KoreanClown - 15.09.2023 23:00

i dont get it why ppl would try to add the size of struct person
if previously *p_person is already struct of person
any way i dont understand why it would multiply instead neither

Ответить
Paula Raafat
Paula Raafat - 11.09.2023 04:40

What is the name of this text editor or compiler?!

Ответить
Refonia
Refonia - 07.09.2023 12:32

Didn't know the compiler did this but I also never did += sizeof() stuff because I genuinely thought that when you do *struct = &struct what you have is a pointer to a pointer array which secretly point to the struct array, I would never think that the compiler would just multiply the value because that for me looked unintuitive and like a bigger secret thing for the compiler to do that the user wouldn't even think about and so did I, really enjoyed the explanation in the video.

Ответить
Michael Abramo
Michael Abramo - 30.08.2023 06:02

Thanks for the refresher. I haven't looked at C in almost 10 years.

Ответить
Darkflame
Darkflame - 27.08.2023 02:41

i have a question for you guys, especially the guy who designed the malloc function, why do malloc doesn't set all the allocated memory values to 0, it's so annoying.

Ответить
a m
a m - 13.08.2023 01:15

I do like this video but at the same time I even hate...

Ответить
Erick Daniel Toyo Marin
Erick Daniel Toyo Marin - 21.07.2023 01:44

First of all, thank you for teaching me. Isn't "p_Person += 1";" supposed to be the last line in the for loop? So that the names get assigned on pace with the ages I guess.

Ответить
sai prasath
sai prasath - 11.07.2023 02:27

100 in hex 0x64, and i know you wrote for loop comparison as i < 100 only, but compiler compared it against 99 and uses jump when less or equal. How did that happen, and isn't there a assembly equivalent of just jump when less?

Ответить
Kevin Vélez
Kevin Vélez - 04.07.2023 17:38

Good one.

Ответить
I Eat Garbage
I Eat Garbage - 15.06.2023 10:31

Would you be able to say
person[i]->age = 0;
Or would that cause an error?

Ответить
Hoefkens J.
Hoefkens J. - 15.05.2023 06:58

(with sarcasm in voice: ) right... now i know why i should use pointers ... but 1sec : is writing '
for (int i =0 ; i <100 ; i++){
people[i].age=0;
}'
not exactly the same result as :'
for (int i =0 ; i <100 ; i++){
p_Person->age=0;
p_Person+=1; // ++?

}'
if so not still sure what a good reason is to use them (other thand passing big stuff as parameters to functions)

Ответить
Daniel Yoffie
Daniel Yoffie - 11.05.2023 19:11

Would p_Person++ do the same as p_Person += 1?

Ответить
Manash .B
Manash .B - 11.04.2023 04:45

Wow. 🔥

Ответить
President Elmo
President Elmo - 04.04.2023 01:32

why do you put argc and argv in the main?

Ответить
The only way is forward
The only way is forward - 02.04.2023 12:10

How to understand pointers. Eat pizza, there's a pointer for you!

Ответить
Dani 13
Dani 13 - 27.03.2023 14:10

.

Ответить
krazyman 50
krazyman 50 - 10.03.2023 15:11

ok but why cant w just do people[i].age = 0; in the for loop lol

Ответить
Firstname Lastname
Firstname Lastname - 05.03.2023 06:24

Very very good explanation

Ответить
B's PC
B's PC - 28.02.2023 20:35

thankyou I was really struggling trying to use structs like objects, now I know how to use pointers :)

Ответить
Mnogojazyk
Mnogojazyk - 11.02.2023 17:50

I accept the premise that the C/C++ compiler already knows you are coding a struct and calculates the memory position of the array people. if you change the value of p_Person anywhere in the code, does that mean p_Person points to that Person in the sequence? Example:

p_Person = 3 ;
p_Person -> name[0] = 0 ;
p_Person -> age = 0 ;

Does this mean that p_Person points to Person[3] in other language's notation? In essence, which array element in Person does p_Person point to?

Many thanks.

Ответить
Abu Chuuqi
Abu Chuuqi - 04.02.2023 00:53

Bull Shit We can not understand you

Ответить
TheTooginator
TheTooginator - 26.01.2023 13:40

Great explanation! Subscribed! I even understood your explanation/demonstration in assembly!!

Ответить
Piere LeNigus
Piere LeNigus - 14.01.2023 06:50

Yeah not as advertised. This kid may think he understands pointers but his words show otherwise.

Ответить
Digger D
Digger D - 09.01.2023 10:07

A pointer is memory location that points to another memory location. Done. Easy

Ответить
Saumya Cow
Saumya Cow - 22.12.2022 20:08

Pointer arithmetic is plain evil and should be banned, forever.

Ответить
CheesyBread
CheesyBread - 21.12.2022 17:51

I assume that for a void pointer the compiler will not multiply.
But also this is a great example of bad implicit behavior. It's bad and the devs of the C compiler should feel bad.

Ответить
Rafael Margarido Sabe
Rafael Margarido Sabe - 07.12.2022 14:26

I usually use an alternative method to do that:

struct Person people[100];
struct Person *p = NULL;
for(int i = 0; i < 100; i++)
{
p = &people[i];
p->age = 0;
p->name = "someone";
}

Ответить
KannaDesu
KannaDesu - 24.11.2022 16:00

i love you thank you so much.

Ответить
Nick Morton
Nick Morton - 13.11.2022 08:56

Awesome video!

Ответить
ʌzvkʌ
ʌzvkʌ - 12.11.2022 14:14

Jajjajajajajaja went to the assembly to explain the inner workings
Starts to read it like it's the alphabet
That was impressive

Ответить
Liberal Wrecker
Liberal Wrecker - 30.10.2022 12:41

Why not just use the index i. people[i] would return a pointer to the person at that index in the array

Ответить
thi chuyen
thi chuyen - 18.10.2022 00:19

Wow! it's Amazing I did it well ! Perfect work !

Ответить