CONST in C++

CONST in C++

The Cherno

6 лет назад

396,300 Просмотров

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


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

@user-gh2ys6jb3u
@user-gh2ys6jb3u - 19.12.2023 15:30

Why the opperator , built like that. Bruh

Ответить
@laurin__
@laurin__ - 21.11.2023 11:15

mutable const int

Ответить
@saturn7_dev
@saturn7_dev - 18.11.2023 20:59

what about const const int const * a - I'm constantly getting problems with C--

Ответить
@hearthat1334
@hearthat1334 - 17.11.2023 18:22

🦷

Ответить
@leshommesdupilly
@leshommesdupilly - 29.10.2023 23:50

volatile const int wat = 6969;

Ответить
@ziadomran5914
@ziadomran5914 - 05.10.2023 11:20

When I use mutable .. do I have to put the const as well when I call the function as a reference ?

Ответить
@davidthwaites4825
@davidthwaites4825 - 30.09.2023 18:14

Absolutely the clearest explanation of const out there!

Ответить
@MoolsDogTwoOfficial
@MoolsDogTwoOfficial - 22.09.2023 06:34

Note for people using C++20 or greater: There is also 'constexpr' for explicit compile time constants.

Ответить
@iisthphir
@iisthphir - 06.09.2023 20:10

I don't even put that keyword in front of things until I'm pretty sure I'm not going to change it.
Otherwise it's MEANINGLESS
🖖🏻

Ответить
@yoyoyo1321
@yoyoyo1321 - 28.08.2023 07:45

too confusing

Ответить
@ManishSharma-fi2vr
@ManishSharma-fi2vr - 13.07.2023 08:48

love you!

Ответить
@mikedoeren5960
@mikedoeren5960 - 28.06.2023 07:57

The best video on the const keyword, and it's not even close. Good stuff!

Ответить
@nikhilrajbhar
@nikhilrajbhar - 26.06.2023 22:19

When we gonna get a video on assembly.

Ответить
@robertmoats1890
@robertmoats1890 - 26.06.2023 02:27

"If you want both members to be pointers, you have to put the asterisk before every member" - this is why every programmer should immediately adopt my style of placing pointer asterisks on the name side instead of the type side! Then it works perfectly when you define multiple pointers on one line. Well, until you try to define a function that returns a pointer, then your asterisk doesn't know where it wants to be.

"We still need to mark the method as const, but we just want to touch this variable" - a good example of when this pops up a lot is in "on demand" situations, such as load-on-demand, where an object loads its data in the background the first time it is required. In such a case, it is usually necessary to modify the object from a const situation, even though the method itself is not really the purpose of the modification, just the reason it is needed.

Ответить
@utr-gaming5958
@utr-gaming5958 - 27.05.2023 17:58

My head hurts :D I think I've done too many of these videos today. Great job though.

Ответить
@1Dr490n
@1Dr490n - 24.05.2023 20:32

So... "const int a" creates a constant a of type int, but "const int* a" creates a variable a of type constant int*??? Whyyyyy c++? Whyyyy?

Ответить
@qidex
@qidex - 19.04.2023 00:46

I've been programming for years, but these details are things I largely didn't know. Now I hope I can improve my coding patterns accordingly, but still need to figure if I'm understanding everything correctly.

Ответить
@chadgregory9037
@chadgregory9037 - 02.04.2023 17:07

this made me think of those late nite 'incontinence' commercials

Ответить
@ekhet5070
@ekhet5070 - 29.03.2023 07:53

these videos sadly are not for newbies like me :(
are more like for intermediate ppl.

Ответить
@mkhadka123
@mkhadka123 - 21.03.2023 01:29

you are a reason I fell in love with c++ language again, your c++ videos are simply awesome :)

Ответить
@mkhadka123
@mkhadka123 - 21.03.2023 01:23

my head spinning -> const ;)

Ответить
@asliddintursunov7356
@asliddintursunov7356 - 02.03.2023 16:13

3 times const made me not to watch the video till the end 😫

Ответить
@vtgordo
@vtgordo - 31.01.2023 22:26

Need help - using VS2019 - when Cherno enters code that will not compile, he gets a 'squiggly' under the error right away - how do I set that up?

Ответить
@sangdilbiswal30
@sangdilbiswal30 - 08.01.2023 20:57

this is a complete video I was looking for thanks sir.

Ответить
@phantomstriker7996
@phantomstriker7996 - 26.12.2022 00:50

Const is a promise. You tell something that it's gonna be constant and it's not going to change.

Ответить
@daniil9263
@daniil9263 - 20.12.2022 02:07

since people are still watching/commenting. A great example why const on member functions should be used.
map[ ] operator (as in dict["key"] = value. it's sometimes (depending on the implementation of map) not const. So this dict["kye"] = value would compile and work, until it doesn't because you just inserted >value< at "kye".

If you don't know the framework in&out, be const correct. This particular thing was taken from the yt-video: c++ bugs at facebook.

Ответить
@LunaFlahy
@LunaFlahy - 18.12.2022 09:12

awesome! thank you!

Ответить
@hamzahix4860
@hamzahix4860 - 17.12.2022 16:41

love it

Ответить
@rjle2446
@rjle2446 - 01.12.2022 17:04

Super helpful. Thank you!

Ответить
@alecmather
@alecmather - 17.11.2022 07:07

Literally amazing video, just answered all my questions about const (and more) in 12 minutes, you're a GANGSTER

Ответить
@man_do
@man_do - 03.11.2022 12:55

const std::string cmmt = "Great video!";

Ответить
@OM-et1bp
@OM-et1bp - 28.10.2022 06:23

Awesome!

Ответить
@leviwillrich2637
@leviwillrich2637 - 27.10.2022 07:51

Undefined behavior

Ответить
@theOmKumar
@theOmKumar - 07.10.2022 12:49

**EASY MENTAL MODEL TO PERMANENTLY REMEMBER THESE**
think of '*' as boundary, whatever is in contact with const is meant to be constant
eg1: int const *ptr -> int const |*| ptr
eg2: const int *ptr -> const int |*| ptr

-> const is in contact with int only, and ptr is separated thanks to boundry '*', this means:

1. we can't modify int values
2. we can modify pointer

eg3: int * const ptr; -> int |*| const ptr
-> const is in contact with ptr while int is separated, this means:

1. we can't modify pointer.
2. we can modify int values.

Also You can read backwards as suggested by @Jean-Nay Mar

Ответить
@faysalarab
@faysalarab - 28.09.2022 03:27

Your videos are good but you talk pretty fast.

Ответить
@serkanozturk4217
@serkanozturk4217 - 20.09.2022 22:59

Personal notes:
- reading backwards helps understanding what is constant
- making a class method constant says that that method will not change any of the class member
- defining a function outside of the class and passing class instance as a constant reference makes sure that the instance won’t change. Thus, any method in that function must be const, otherwise you get error

Ответить
@hpeterh
@hpeterh - 18.09.2022 15:17

Pretty clear, thank you.
It should be noted, if a global variable is declared as "const" or a variable is declared "static const", then it is placed by the linker into a non writable CODE or CONST segment. When it is written to by some pointer trickery, an access violation exception will probably happen.

Ответить
@celestialmaat9462
@celestialmaat9462 - 12.09.2022 06:33

I spent like 20 minutes and then looked you up🤯🤯🤯! Thanks

Ответить
@can3792
@can3792 - 05.09.2022 23:31

i am on the patreon and donated . i cant thank you enough. please carry on taking video in c++ :)😀 keep up the good work

Ответить
@SonuKhan-mp2yn
@SonuKhan-mp2yn - 08.08.2022 23:20

legendary

Ответить
@pedrodeazeredonogueira9661
@pedrodeazeredonogueira9661 - 02.08.2022 10:52

you are a LEGEND legend

Ответить
@adygombos4469
@adygombos4469 - 31.07.2022 02:28

me watching the last videos: mhm, mhm, yeah kinda makes sense, yup, i get that.
me watching this video: fuck it i'm going back to javascript.

Ответить
@AmCanTech
@AmCanTech - 22.07.2022 10:33

int *myX;
const int * const getX() const{return myX;}
1 - return (pointer cant be modified)
2 – contents of pointer cannot be modified
3 – getX not modify actual class

Ответить
@danielketcheson1965
@danielketcheson1965 - 20.07.2022 22:22

Before video:🙄🤕
During video:🤔🤯🥰
After video:🧐

Ответить
@dickheadrecs
@dickheadrecs - 13.07.2022 17:50

const++

Ответить