I think one of the problems with learning about pointers is the fact that many people declare them in this "int *ptr" style. And by "many" I mean "most", unfortunately. This style makes you think "What's so special about this int variable? Why is there a star attached to its name? It's so random and confusing!". This also clashes with the dereference operator, where you also have to put an asterisk in front of the name. The same syntactic structure for two completely different things! Once I learned the pointers myself, I immediately started declaring them in the "int* ptr" style. This makes so much more sense. You can clearly see that "int*" is just a data type like any other and not some arcane magic int that behaves completely differently. The same goes for C++'s reference types. And yes, I'm well aware that declaring multiple pointer variables in one statement is problematic with this approach, because you have to put an asterisk in front of each name anyway, otherwise the unpreceded ones will just be variables of the base type, but I blame the design of C for that, and there's nothing we can do about it. You can declare each pointer in a new line if you like. Personally, I do it like this: "int* x, * y, * z". (yes, I'm using a weird * symbol, to prevent RUclips from bolding my text)
you are totally right, int* and int are separate types to begin with and i have always wondered why people put the asterisk on the variable name, i guess it allows them to know that it is a pointer to a another variable type but they should really just use a craftier name that highlights that information in the naming itself.
This is not for Gen Z, let me do it in fortnite terms, think of 1, 2, 3, 4, 5 as memory address, if you get the chug jug and put it in 1, then by pressing your 1 key, youre retrieving the value of memory address 1 which is the chug jug
Hmm // declaration String place = "HOUSE"; int *ptr = &place; // Output println("%d*, ptr); // Glossary int = data type name, ptr = identifiers * = pointer symbol & = get address value of variable %d = specifier format
Imagine you have an object (let's take a classic and overused example: a "person" struct). Now, imagine you also have two functions in your code, that both accept a "person" struct as an argument: one for displaying the person's full name & age, and another for asking the user to type those details and modifying the struct. Now, the important thing here is that both functions will receive a copy of the person's data. So, the first function will work perfectly fine, but the second one will only modify its own copy of the data (received as the argument), but not the original source. When you pass a pointer to the modifying function though, you tell it exactly where your original "person" struct is, allowing it to change it directly.
Actually, pointers are pretty easy, but I got confused once when I was working with an array and tried to get its sizeof. Then I passed it to a function (so into another scope), and when I got its sizeof there, it was already equal to the size of a pointer instead of the size of the array. This is because your array is actually just a pointer to its first element. Why was it working correctly in the main scope then? Compiler black-box magic 😅
When you declare an array, you set a size for it, so its scope knows its size. When you pass it to a function, the function only receives a pointer, and no information of the memory it has reserved
@@dawae5447 It's not actually the scope that knows the actual size. It's the compiler that replaces sizeof with this value at compile time. Correct me if I'm wrong
why pointers are so complicated? they are just a variable, that stores an address to something, and by derreferencing, you get the value at that memory location.... I used to use only high level languages before I maried with my current wife ( C ), and it was a really simple concept the whole pointers stuff lol
Yeah this subject is overcomplicated for no reason. Pointers are a bit confused but not so complicated or even complicated. Just a bit confusing at first.
tbh they like Rust and other things more. They don't quite get the charm of being able to shoot yourself in the foot if you want or even on accident. C isn't just the mother language, it's mother nature itself.
@@ismotheis i think alot of the love is mostly the idea it it is "memory safe". but writing memory safe code isnt that hard if you have a rough idea of how the underlying hardware works
I think one of the problems with learning about pointers is the fact that many people declare them in this "int *ptr" style. And by "many" I mean "most", unfortunately. This style makes you think "What's so special about this int variable? Why is there a star attached to its name? It's so random and confusing!". This also clashes with the dereference operator, where you also have to put an asterisk in front of the name. The same syntactic structure for two completely different things! Once I learned the pointers myself, I immediately started declaring them in the "int* ptr" style. This makes so much more sense. You can clearly see that "int*" is just a data type like any other and not some arcane magic int that behaves completely differently. The same goes for C++'s reference types.
And yes, I'm well aware that declaring multiple pointer variables in one statement is problematic with this approach, because you have to put an asterisk in front of each name anyway, otherwise the unpreceded ones will just be variables of the base type, but I blame the design of C for that, and there's nothing we can do about it. You can declare each pointer in a new line if you like. Personally, I do it like this: "int* x, * y, * z".
(yes, I'm using a weird * symbol, to prevent RUclips from bolding my text)
There are a lot of small details in the C language that can be totally convoluted. I agree with your approach, and I get where you're coming from
you are totally right, int* and int are separate types to begin with and i have always wondered why people put the asterisk on the variable name, i guess it allows them to know that it is a pointer to a another variable type but they should really just use a craftier name that highlights that information in the naming itself.
This is not for Gen Z, let me do it in fortnite terms, think of 1, 2, 3, 4, 5 as memory address, if you get the chug jug and put it in 1, then by pressing your 1 key, youre retrieving the value of memory address 1 which is the chug jug
I'm gen z and never played or watched fortnite, no hate to those who do it's just not my thing (I think the art style is ugly).
@@GameDevGeeksrelax bro no one is judging you lol
@@JorgePires7-7-7 no one is chug-jugging you 😅
on skibidi that was a dub slime
Please talk about recursion, variadic function, linked list ...
Variadic functions? Like those: myprintf(const char *str, ...); kinda thing?
That's a must have on this channel
Bruh this aint for Gen Z, a minute is unbearable, I could be playing Fortnite right now or doomscrolling 💀
This had me cracking up😅
People exaggerate it so much. Its easy
Dang this was such a clean explanation 🙏🔥
Para las personas que no hablan Inglés se entiende! Gracias bro
@@DerekitoCorpcito me alegra compa, fíjate hablo español y tal vez hago una seria pa mis amigos latinos
"for Gen Z" 😅
this is great, i dont even need to learn this, but it was quick so i couldnt miss this haha.
thank you, now i can reverse engineer gtavi 🗿
We need the subway surfers gameplay 😂
Excellent video! Keep it up ^_^
the "for genz" bought me
Already knew this but just clicked on it because why not, can you do qwords and dwords
Understandable, thanks
Hmm
// declaration
String place = "HOUSE";
int *ptr = &place;
// Output
println("%d*, ptr);
// Glossary
int = data type
name, ptr = identifiers
* = pointer symbol
& = get address value of variable
%d = specifier format
Errors:
A lot (+9)
When used in a declaration, the * symbol is not an operator at all. It doesn’t “act on” anything.
FYI, 'A' is an int, not a char in C (yeah, it's confusing).
its more helpful to explain the benefits of pointers (aka the "why") before explaining how to use them.....
Yeah, and perhaps even, maybe especially the dangers of misusing them.
Imagine you have an object (let's take a classic and overused example: a "person" struct). Now, imagine you also have two functions in your code, that both accept a "person" struct as an argument: one for displaying the person's full name & age, and another for asking the user to type those details and modifying the struct.
Now, the important thing here is that both functions will receive a copy of the person's data. So, the first function will work perfectly fine, but the second one will only modify its own copy of the data (received as the argument), but not the original source.
When you pass a pointer to the modifying function though, you tell it exactly where your original "person" struct is, allowing it to change it directly.
First ❤️ keep going
pointers is just to not copy a variable and change it value from a function
From anywhere acctually
what about double pointers?
you point to a pointer, i think it's that simple
Spiderman pointing meme
Actually, pointers are pretty easy, but I got confused once when I was working with an array and tried to get its sizeof. Then I passed it to a function (so into another scope), and when I got its sizeof there, it was already equal to the size of a pointer instead of the size of the array. This is because your array is actually just a pointer to its first element.
Why was it working correctly in the main scope then? Compiler black-box magic 😅
When you declare an array, you set a size for it, so its scope knows its size. When you pass it to a function, the function only receives a pointer, and no information of the memory it has reserved
@@dawae5447 It's not actually the scope that knows the actual size. It's the compiler that replaces sizeof with this value at compile time. Correct me if I'm wrong
I really like such short and informative videos.keep making them bro🫡
I feel offended by the thumbnail , but thank you
why pointers are so complicated? they are just a variable, that stores an address to something, and by derreferencing, you get the value at that memory location.... I used to use only high level languages before I maried with my current wife ( C ), and it was a really simple concept the whole pointers stuff lol
Yeah this subject is overcomplicated for no reason. Pointers are a bit confused but not so complicated or even complicated. Just a bit confusing at first.
Array to pointer decay and pointer arithmetic not covered.
I am disappointed.
Wheres the subway surfers second video in the corner?
Imagine using a text editor instead of IDE
well I knew before video how to use pointers... But actually I dont know why would I wanna do that... and dont tell me to have more effective code
I bet 96 percent are not gen Z
I never understood why should a pointer exist
I love gen Z 😂
I not understand, send in TikTok format
I clicked only to see if he used any funny language
"you see when the address and desired content of a pointer becomes desynced, that's not very skibidi"
Be honest with yourself, most Gen Z people can't code.
You do realize gen Z stretches pretty far right? There are plenty of great gen Z coders
speak for yourself buddy
@@alwayslg considering I'm part of gen Z and I'm an embedded developer I think I'm doing pretty good
tbh they like Rust and other things more. They don't quite get the charm of being able to shoot yourself in the foot if you want or even on accident. C isn't just the mother language, it's mother nature itself.
@@ismotheis i think alot of the love is mostly the idea it it is "memory safe". but writing memory safe code isnt that hard if you have a rough idea of how the underlying hardware works
Do you have a discord? If not create one i will help you and your community.