Finally understand Pointers! FULL GUIDE!

  Рет қаралды 12,760

Low Level Game Dev

Low Level Game Dev

3 ай бұрын

In this video, I will teach you all you need to know about pointers in C++.
This video is aimed both at beginner and advanced programmers 💪!
Beginner: 0:56
Intermediate: 5:54
Advanced: 10:46
#cpp #programming #learncpp #gamedev
Also, check out how I handle memory management in C++! 💪:
• How to deal with memor...
Join my Discord 🤖:
/ discord
My Steam Game: Midnight Arrow 🎮:
store.steampowered.com/app/23...
Join this channel if you want to support me 😻:
/ @lowlevelgamedev9330
Check out My Minecraft Clone 🌳:
• Minecraft clone
Full C++ Game Guide 🕹️:
• Make a C++ game FULL G...
Music:
Evan King - Booty Shake Robot
Evan King - Invisible Walls
/ contextsensitive
contextsensitive.bandcamp.com/
Minecraft soundtrack: C418 - Aria Math

Пікірлер: 84
@jorik170
@jorik170 3 ай бұрын
int* first;
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
let's goo first pointer of the video 💪
@lukasjetu9776
@lukasjetu9776 3 ай бұрын
struct Comment { //count int likeCount = 0; int dislikeCount = 0; short replyCount = 0; //date vars short day; short month; short year; //text char* text; char* user; //bools bool hearted = false; struct Reply { //count int likeCount = 0; int dislikeCount = 0; //date vars short day; short month; short year; //string info char* text; char* user; char* userReply; //only exists if you're replying to others //bools bool hasReplied = false; bool hearted = false; }; }; // i dont know if this would actually work but whatever
@BobChess
@BobChess 3 ай бұрын
unsigned int* first;
@King_sobb
@King_sobb 3 ай бұрын
Unsigned const short int* first;
@lukasjetu9776
@lukasjetu9776 3 ай бұрын
constexpr unsigned long long* first = 1;
@mahdijoharian2731
@mahdijoharian2731 3 ай бұрын
Your teaching style is batter than most c++ KZfaqrs for beginners. It is mostly accurate. This is what I seen that needed a bit of correction: Well technically arrays are not pointers and if you use them like pointers they decay So don't say that an array is a pointer . The size of it is not normally the size of pointer . They can be referenced like : T (&ref)[N] And this can not be a pointer reference so they are not the same. Additionaly : When you make a function with array arguments it is a pointer to the elements. unless the arguments is a reference . You can actually see this in msvc: auto p=""; auto&&a=""; The types are: const char *, const char(&)[1] and some parts about void* ers can led to undefined behavior if you use the wrong type. And Additionaly you may use new and delete on their own but the catch is that your code is not exception safe . make sure that at least the delete is in some kind of destructor to make it safer . In fact you can make a custom( template ) class to hold a lambda and run that on destruction . This will be handy I promise.
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
yes it is true tho I think that's probably too much for a beginner 😂 but good points 💪
@mahdijoharian2731
@mahdijoharian2731 3 ай бұрын
@@lowlevelgamedev9330 @lowlevelgamedev9330 yeah 😅 . And that's probably why the cherno has more subscribers that Cppcon and c++weekly combined . 😂😅
@thepaulcraft957
@thepaulcraft957 3 ай бұрын
aint the last one just std::unique_ptr ?
@mahdijoharian2731
@mahdijoharian2731 3 ай бұрын
@@thepaulcraft957 it's not a replacement for unique ptr , this patern is more useful ,unique ptr just hides this work .
@hexa3333
@hexa3333 3 ай бұрын
Beginner: 0:56 Intermediate: 5:54 Advanced: 10:46
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
thanks, I have to add it in the description 💪
@LBCreateSpace
@LBCreateSpace 3 ай бұрын
Learned a thing or two! Thank you for making this :D
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
glad to help 💪💪
@tsarman2182
@tsarman2182 Ай бұрын
Thank you so much, super informative!
@satyamraj2476
@satyamraj2476 3 ай бұрын
8:08 i always got confused at arrow operator now i understood it thanks for this video😊.
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
glad to help 💪💪
@Maiuna-yc2uk
@Maiuna-yc2uk 3 ай бұрын
Thanks for the video! This is a great video for an introduction to pointers! I would like to add something to it though, like best practices, especially for beginners. Here's my take on it: 1. First of all never use *pointers* 2. If you need a dynamic memory, use *std::unique_ptr* instead for single ownership 3. In need of shared ownership? then look around your code, you probably structure your program badly 4. You absolutely need a shared ownership? use *std::shared_ptr* then 5. If you need a view to a memory/resource that you don't own, use a *reference* (borrowing) 6. If you need a view to a contiguous area of memory that you don't own, use *std::span* (*std::string_view* if it's a string) 7. Only if all the above not apply then you are probably okay using a *pointer* Most of the time you want to use number 5 since dynamic memory allocation is not that common (always use the stack not the heap unless you need to).
@draken2037
@draken2037 3 ай бұрын
make a video on memory allocation and smart pointers
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
yes it is comming 💪
@GustavoPinho89
@GustavoPinho89 3 ай бұрын
​@@lowlevelgamedev9330 WHEN?!?!!!??!?! I know you're doing it for free, but that's not an excuse for stalling. 😂😂😂😂 Thanks for sharing your knowledge in a useful way.
@sekki2554
@sekki2554 3 ай бұрын
GREAT Video. Absolutly great.
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
thanks 💪
@rikkoo
@rikkoo 3 ай бұрын
nice, very cool Edit: i want the smart pointer video!
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
ok noted, 💪
@ChikenGaming_Offical
@ChikenGaming_Offical 3 ай бұрын
Great video, and i would love to see a tutorial on memory allocation : )
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
noted, third request already, I think I will make it 💪
@jneo_misc7378
@jneo_misc7378 3 ай бұрын
the minecraft song in the beginner :D
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
good stuff 😌
@ali_gd_0161
@ali_gd_0161 3 ай бұрын
Hey man, just asking whether you ever thought of making a video series teaching opengl, i really like the way you teach and think you're the perfect guy for this job
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
I might make some videos on the topic but I don't know if I'd do a full series, that takes a lot of time
@washynator
@washynator 3 ай бұрын
Let's goo! Next make a tutorial video about making an MmoRpgFpsPointAndClickAdventureMetroidVaniaZeldaInspiredMinecraftCloneRogueSoulsLike multiplayer c++ game, pretty please?
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
good idea, that was my plan actually 💪😎
@washynator
@washynator 3 ай бұрын
@@lowlevelgamedev9330 Yay!
@4F6D
@4F6D 3 ай бұрын
When you know how variables work, you know how pointers work. Don't be too afraid of pointers.
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
yes true 💪
@not_vinkami
@not_vinkami 3 ай бұрын
So one of my university courses this semester actually requires me to make a text-based game in c++. This is actually so useful
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
yo check out the first videos of my winapi series, they show exactly that 💪
@joshuacox3644
@joshuacox3644 3 ай бұрын
Simple way to abstract pointers is all they are literal pointers, you’re pointing to a value. Say if I’m pointing at a cat, the pointer isn’t the cat but my finger itself.
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
good point, I like it 💪
@zackwumpus9364
@zackwumpus9364 3 ай бұрын
Smart pointers..
@viper49626
@viper49626 3 ай бұрын
So i have a one question about pointers and references when should i use a pointers to pass some data to a function and when should i use references? void fun(int* ptr) void fun1(int& ref) This is confusing because they are very similar besides some sytax sugar.
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
good question, so they do the same thing but a refference can't be null. The language forces you to refference it to something. So I use pointers in function arguments when it is something optional, and refference when it isn't optional
@Brad_Script
@Brad_Script 3 ай бұрын
"I don't use smart pointer", that must have triggered a lot of C++ developers.
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
yes I know 😂😂
@FuIbion
@FuIbion 3 ай бұрын
I still don't get why people prefer using pointers when they do a bit of object-oriented... Maybe you'll tell us a bit more about this in your video about memory allocation 👍 I don't think I learnt something in this video, but it was explained very well, so congrats for "popularizing" this quite advanced concept, especially with these great metaphors!
@v01d_r34l1ty
@v01d_r34l1ty 3 ай бұрын
first thing that comes to mind is copy size. moving 8 bytes is much cheaper than moving a 24 byte or more object for instance.
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
again, that's not a reason to do it, you can always make a refference and a new pointer if you want, pluss 24 bytes still takes no time to copy
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
Well I don't know either, those are the facts and I think people do it just out of poor habit :((
@v01d_r34l1ty
@v01d_r34l1ty 3 ай бұрын
@@lowlevelgamedev9330 a reference is an underlying pointer :)
@v01d_r34l1ty
@v01d_r34l1ty 3 ай бұрын
@@lowlevelgamedev9330 24 bytes isn't that much but in my project i have a single context struct that is probably hundreds of bytes big for Vulkan and it's passed to every function
@m4rt_
@m4rt_ 3 ай бұрын
... I knew all of this already
@hamzahawash3063
@hamzahawash3063 3 ай бұрын
i demand a video to understand what is the difference between coding and programming and how to understand programming like i have no idea how the gui works and how to get into game development . and what the hell are algorithms and data structures and data bases dude 😭😭 my head is gonna explode with how much info i am having to deal with , for i in range(1000) : print("i need help")
@ali_gd_0161
@ali_gd_0161 3 ай бұрын
woomp woomp Edit: its not that hard actually, i recommend watching Harvard CS50x, its a great online course that explains everything you need to get started with programming (btw, its just the harvard computer science lectures recorded, but its magnificent)
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
this is the exact channel for this, check out my full game guide in c++, or my videos about how to start or continue learning cpp or how to learn cpp for gamedev, I have several
@hamzahawash3063
@hamzahawash3063 3 ай бұрын
@@lowlevelgamedev9330 thank you brother you have no idea how much im thankful
@Andy_B.
@Andy_B. 3 ай бұрын
its ok, but you def. should explain the syntax (very shortly), before beginning the intermediate explanation. I know the syntax, just saw that you already used syntax in your pics before explaining it.
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
fair point, I'll be more carefull next time
@Andy_B.
@Andy_B. 3 ай бұрын
@@lowlevelgamedev9330👍
@Gabezen101
@Gabezen101 3 ай бұрын
Is the information about the heap the same for C?
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
yes, that has to do with the os more than the programming language
@Gabezen101
@Gabezen101 3 ай бұрын
@@lowlevelgamedev9330 thank you very much! so if i design functions in C to call by reference, should I use void add(int *i, int *j) hypothetically or can i use void add(int &i, int &j) just the same with better performance?
@rz2374
@rz2374 3 ай бұрын
@@Gabezen101 c doesnt have references so you have to use pointers
@EStartive
@EStartive 3 ай бұрын
int *second = &first;
@jorik170
@jorik170 3 ай бұрын
haha
@simonhenriquez4590
@simonhenriquez4590 3 ай бұрын
int **third = &second;
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
😂😂 epic
@Dazed_04
@Dazed_04 3 ай бұрын
I came here expecting some beginner stuff. Although i knew all of these, it really was an in-depth video about pointers. Specially things like funtion pointers that most beginners don't even know exist. Another question that beginners ask is why arrays start from index 0, this could easily be added to when you talk about pointer arithmetic while accessing the array. Overall a great video and something I'd recommend to people already familiar with the language incase they want to refresh their memory.
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
thanks bro 💪 I'm glad you liked it
@rz2374
@rz2374 3 ай бұрын
why dont you use smart pointers
@Anmol_pp
@Anmol_pp 3 ай бұрын
Say hello
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
say amongus 🔫💀
@eagle32349
@eagle32349 3 ай бұрын
12 53 12 12
@bruhzzer
@bruhzzer 3 ай бұрын
5:51 negotiable*
@bruhzzer
@bruhzzer 3 ай бұрын
8:14 reference*
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
thanks 😭 I'm bad at spelling
@silloo2072
@silloo2072 3 ай бұрын
C is high level only assembly is low level
@mihaelasimerea9700
@mihaelasimerea9700 3 ай бұрын
What about binary?
@silloo2072
@silloo2072 3 ай бұрын
@@mihaelasimerea9700 also low😃
@lowlevelgamedev9330
@lowlevelgamedev9330 3 ай бұрын
fair enough but for some people even c is too low level for them 😂
@silloo2072
@silloo2072 3 ай бұрын
@@lowlevelgamedev9330 you replied to me 😳
@silloo2072
@silloo2072 3 ай бұрын
@@lowlevelgamedev9330 yep
@Brainwizard.2
@Brainwizard.2 Ай бұрын
The last part was messy. I still don’t understand it.
C++ tutorials be like
3:16
Low Level Game Dev
Рет қаралды 2,1 М.
why do void* pointers even exist?
8:17
Low Level Learning
Рет қаралды 335 М.
Can You Draw A PERFECTLY Dotted Line?
00:55
Stokes Twins
Рет қаралды 107 МЛН
Smart Sigma Kid #funny #sigma #comedy
00:25
CRAZY GREAPA
Рет қаралды 19 МЛН
Was ist im Eis versteckt? 🧊 Coole Winter-Gadgets von Amazon
00:37
SMOL German
Рет қаралды 37 МЛН
Use Arc Instead of Vec
15:21
Logan Smith
Рет қаралды 138 М.
WHY IS THE HEAP SO SLOW?
17:53
Core Dumped
Рет қаралды 208 М.
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 287 М.
31 nooby C++ habits you need to ditch
16:18
mCoding
Рет қаралды 741 М.
Why I focus on patterns instead of technologies
7:55
NeetCodeIO
Рет қаралды 205 М.
How principled coders outperform the competition
11:11
Coderized
Рет қаралды 1,6 МЛН
Every Programming Language Ever Explained in 15 Minutes
15:29
Flash Bytes
Рет қаралды 285 М.
How to deal with memory allocation for C++ GameDev
8:03
Low Level Game Dev
Рет қаралды 15 М.
If this ships, it will change javascript forever
25:54
Theo - t3․gg
Рет қаралды 194 М.
Should you learn C++?? | Prime Reacts
20:29
ThePrimeTime
Рет қаралды 329 М.