How Strings Work in C++ (and how to use them)

  Рет қаралды 471,991

The Cherno

The Cherno

Күн бұрын

Пікірлер: 438
@Brotcrunsher
@Brotcrunsher 7 жыл бұрын
You've made a mistake at 7:03 "[...] otherwise you can just leave it as a char pointer that is totally fine.", implying that it is okay to change a char in that array. No it is not! That is undefined behavior and leaving a pointer to a String literal non const it deprecated since C++11. You must not change any value of the C-String-Literal!
@TheCherno
@TheCherno 7 жыл бұрын
Yes, you're right. I should have defined it as *char name[] = "Cherno";* in that example.
@forest_grow
@forest_grow 6 жыл бұрын
Please what is the difference between: char* a = "Cherno"; a[2] = 'a'; output is:error and char* a = "Cherno"; a = "Charno"; std::cout
@forest_grow
@forest_grow 6 жыл бұрын
Yeah, I saw that the address is changing sorry
@mariogalindoq
@mariogalindoq 6 жыл бұрын
Стефан Рибак In the second alternative, you aren't changing the memory the pointer "a" points to. You are changing the value of the pointer "a" to point to other place that contains other char string (with the same letters). I think this could seems difficult, so I'll try to explain better: char *a = "Cherno"; creates a pointer "a" that points to a memory that contains the letters "Cherno". a = "Cherno"; change the value of the pointer "a" to point to other memory that also contains the letters "Cherno". So, later you can also do a = "A big string like this"; and it will work too, because "a" will point now to a new memory. The old memories with "Cherno" will remain unchanged somewhere in memory.
@forest_grow
@forest_grow 6 жыл бұрын
Mario Galindo oh thank you for explaination) it helps me a lot in the future)
@danilivanov6262
@danilivanov6262 4 жыл бұрын
Replacing my Netflix binging with TheCherno binging. Loving these videos!
@BobrLovr
@BobrLovr Жыл бұрын
​@haru02w89 it's not useful if you don't actually go and code a lot
@whoeverofhowevermany
@whoeverofhowevermany Жыл бұрын
bing bing. bing ing.
@zanagi
@zanagi Жыл бұрын
C++ is addicting af when I watch this guy
@Steven-tw7iz
@Steven-tw7iz 7 жыл бұрын
This is hands down the best c++ series on youtube. Very professional and informational, amazing job once again Yan! Your videos are fantastic!
@nighma
@nighma 7 жыл бұрын
Do you sell his videos? :D (joke)
@ruf1o2o
@ruf1o2o 7 жыл бұрын
damn right!
@rcookie5128
@rcookie5128 7 жыл бұрын
Agreed!
@jorgejarai
@jorgejarai 4 жыл бұрын
It definitely is. Yan is the kind of programmer I'm aspiring to become. He's such knowledgeable and proficient (he's also pretty handsome 😳)
@bringiton2100
@bringiton2100 4 жыл бұрын
I would you said "eres un bebe precioso" (You are a precious baby Cherno) hahaha
@Gilpow
@Gilpow 6 жыл бұрын
10:13 Note that in the console output, there are 25 garbage characters after "Cherno". Exactly the number of bytes in memory, after that strings, before a "00" byte is reached ^^
@equinox-h9v
@equinox-h9v Ай бұрын
I was actually wondering why there's a set amount of characters printing after Cherno and why the whole console isn't getting filled up with gibberish. This actually cleared that up, thanks.
@TalisBarbalho
@TalisBarbalho 7 жыл бұрын
Even when you say that you were just "mumbling", you still share so much knowledge with us. Thank you for that. Just keep releasing the videos that are easier for you to produce and leave the others for when you have time. Looking forward for the really deep engine programming. Many thanks for the video
@Usammityduzntafraidofanythin
@Usammityduzntafraidofanythin 2 жыл бұрын
The number of asides are BRUTAL in this video
@leixun
@leixun 4 жыл бұрын
*My takeaways:* 1. C style string 5:30, and why he uses char* 9:00, because *"anything inside a double quote is a char array"* 14:10 2. C++ style string 11:04 3. Passing a string to function 16:13, it is better to pass by reference to avoid copy
@takitachibana7717
@takitachibana7717 4 жыл бұрын
it doesn't work if my code is like - { char* name = "cherno"; std::cout
@MrCoder-xj9yi
@MrCoder-xj9yi 3 жыл бұрын
@@takitachibana7717 See the pinned comment
@takitachibana7717
@takitachibana7717 3 жыл бұрын
@@MrCoder-xj9yii already know.Thanks anyway man.
@danielketcheson1965
@danielketcheson1965 2 жыл бұрын
Your explanation on how you learn best; being taught what works vs how it works makes my inquisitive mind tingle with joy. Even makes me trust your content all the more. I feel this style is empowering to the individual who is seeking to utilize and transfer knowledge to any persons interested.
@hemangmathur2823
@hemangmathur2823 20 күн бұрын
I love how his eyes match his hoodie.
@Krokoklemmee
@Krokoklemmee 7 жыл бұрын
neat video, I just want to point out a few things that weren't *entirely* correct: 1.) UTF-16 is not a 16-bit fixed-width encoding. It simply works in *blocks* of 16-bit code units, where a character can be made up of one or two code units. 2.) wchar_t is not guaranteed to be 2 bytes wide, that's only the case on Windows (on most unix-like OS's for example, a wchar_t is 4 bytes long). That's why we got std::u16string :P 3.) Modifying a value previously declared "const" is not "totally fine", it's undefined behavior
@TheCherno
@TheCherno 7 жыл бұрын
I addressed most of these in my video on string literals. :)
@jmac217x
@jmac217x 2 жыл бұрын
Every time I think I know a little about something I find out how little I know! Thanks Cherno 5 years later your knowledge is still invaluable. The Discord is a great resource
@ahumanzr
@ahumanzr 4 жыл бұрын
I got a nice warning at 5:54 (removing "const") "Conversion from string literal to 'char *' is deprecated [-Wc++11-compat-deprecated-writable-strings]" Essentially, non-const char pointers are deprecated in c++ 11
@ahumanzr
@ahumanzr 4 жыл бұрын
(Warnings don't break your code. In fact, they have absolutely no effect in your program. It's only a little message that says something is a little off with your code, but it will still run)
@kacperozieblowski3809
@kacperozieblowski3809 7 жыл бұрын
This series is sooo well made, keep making it please
@GenericPhantom1
@GenericPhantom1 2 жыл бұрын
A string is basically an array of characters, a collection of characters and each of them can be changed.. You type const char* if you don't want to change the value of the string but only char* if you do.
@RandomGuyyy
@RandomGuyyy 7 жыл бұрын
I love this style of video where the speaker has a loose conversational style. They naturally wander into tangential subject matter because many things are related. So they feel like they are rambling but I reckon it's just a natural traversal of the subject. Excited to hear mention of a new series!
@obong5241
@obong5241 4 жыл бұрын
The best C++ series on KZbin.
@CRBarchager
@CRBarchager 7 жыл бұрын
I haven't played around with c++ since the last 90's (Borland) and use C# these days in my day to day work. This series of c++ gives a great insight how far the language have progressed since then and is a real joy to watch and learn. You clearly know your way around the language and you do it way better than anyone else I've seen through the years on youtube. If you want to make 1, 2, 3 or more videos a week is up to you but I don't mind more with the quality you put out.
@mytech6779
@mytech6779 7 жыл бұрын
I had heard similar from many folks, but as I recently started to look into learning a systems capable language comparing various advantages of each(both direct features and meta stuff like maturity, guide books, and employment) I found I kept coming back to C++. C++ was ISO standardized in 1998, then a major update in 2011, with minor additions in 14 a few in 17 and several predicted for 2020. I also discovered that "C/C++" is an incorrect term as the ISO C standard is not synchronized with the C++ standard; C++ is an independent fork from before C89. Many negative C++ opinions seem to be based on experience [or for younger folk repetition of urban legends] from the early 1990s. (partly exaggerated by articles and postings created by Sun's heavy Java marketing efforts and stubborn old timer C devs) Certainly not helped by education curricula that frequently uses 20 year old books and compilers, and a teacher that has been out of the commercial game for so long their "best practices" have been deprecated.
@Destrio_Fury
@Destrio_Fury 2 жыл бұрын
That transparancy is the reason I prefer C++ above Java, of course it's easy to do in Java. But u will forget after some time why u did it, but C++ code will make sure u understand everything before anything works 🤣🤣
@kristinaraciukaityte3451
@kristinaraciukaityte3451 6 жыл бұрын
I usually dont curse, but this..... this is fcking amazing.
@j4n0w5k1
@j4n0w5k1 4 жыл бұрын
Love your stuff, I am a student learning C++, and your channel is my go to when I need help
@alltheway99
@alltheway99 4 жыл бұрын
when passing an object as argument, copy is made on stack, 17:18
@murtazahussain6301
@murtazahussain6301 4 жыл бұрын
EXACTLY I WAS THINKING THE SAME XD
@justicefor4ll
@justicefor4ll 5 жыл бұрын
Missed my lecture today on strings, thanks for this! :)
@zhaadd
@zhaadd 2 жыл бұрын
me casually switching tabs each time his face pops up. i luve the code ohk. keep the great content coming its better than uni omg
@sanyi_derda
@sanyi_derda 4 жыл бұрын
4:06 Slight mistake: UTF doesn't work like that. UTF-16 doesn't mean we have 2^16 different characters. UTF is variable length. There are way more possibilities than 2^16.
@IsaacAsante17
@IsaacAsante17 5 жыл бұрын
Cherno, I'm your new fan. Your C++ videos are gems.
@rcookie5128
@rcookie5128 7 жыл бұрын
and again expanded my knowledge on such basic concepts like string. I feel enlightened!
@rcookie5128
@rcookie5128 7 жыл бұрын
so excited for our own data structures!!
@ananthteja6357
@ananthteja6357 Жыл бұрын
kk bro
@KandMe1
@KandMe1 4 жыл бұрын
Well just to say my thoughts are your doing this really well by laying out this ground work for reference once you drop something of a really meaty project. Thanks for this it will help a lot knowing I can go back and go through these at any time. Well done.
@tigershav
@tigershav Ай бұрын
the more I learn about C++ the more I like it. Coming from Java -> Python -> Js -> C++ I really appreciate being back with a language that is so... "structured"?/strict
@diribad
@diribad 4 жыл бұрын
The Cherno is a god sent gift lol
@tarik9563
@tarik9563 4 жыл бұрын
I actually very much like the way you write your code. I mean: when you write the idea then make affectations and nominations. thank you.
@mkdeviphone
@mkdeviphone 2 жыл бұрын
Like your style explaining stuff down to memory level! And you do it so direct! Genius!
@advitiayanand5974
@advitiayanand5974 5 жыл бұрын
I wanna say you're videos have been the most helpful and informative. Seriously man. Keep at it!
@sypherus.luxiferr5042
@sypherus.luxiferr5042 4 жыл бұрын
Advitiay Anand your*
@zakesters
@zakesters 2 жыл бұрын
You can output strings with just now, though I think you still need to get all the nifty methods.
@RoshanPradhan2
@RoshanPradhan2 4 жыл бұрын
Your eyes radiate light!
@1st_ProCactus
@1st_ProCactus 7 жыл бұрын
These videos are definitely improving my skills. And it will help to understand more of what Bisqwit code(a little). Cheers Dude :)
@matteusberg9091
@matteusberg9091 6 жыл бұрын
String is a type of char array. You should pass a string by reference into a function. When declaring a string and you want to use the + operator in order to add two const char arrays togehter, use std::string() on the first char array. declaring a variable as const is simply a promise that could be broken, but shouldn't. Got it!
@nick60444
@nick60444 3 ай бұрын
Been watching/referencing your videos for years, especially my college days. So thanks Cherno. I had a quick question though, around 17:03, you mentioned that copying a string will have you allocate space on the heap. Did you actually mean the stack? If I remember from C, then everything is pass by value, so you're essentially creating copies of your arguments when calling a function. Space on the stack is allocated for your arguments, so this is where the copy will live.
@krec348
@krec348 7 жыл бұрын
Keep that style of videos, they have are awesome! Magnific
@akielsteewart8577
@akielsteewart8577 2 ай бұрын
13:30 it's nice that it works nowadays without including
@刘嘉政-d6l
@刘嘉政-d6l Жыл бұрын
Hi Cherno, in 13:22 you mentioned that you would get error with "std::cout
@heavymetalmixer91
@heavymetalmixer91 Жыл бұрын
Same for me, how weird.
@mattjohnson9453
@mattjohnson9453 7 жыл бұрын
I think it's also important to note that characters themselves are just numbers; putting single quotes around a character makes it evaluate to a number, the only reason it prints to form text is that single byte numbers are (mostly) interpreted as such. There isn't a whole lot of difference between char txt = 'a'; and int8_t num = 97;
@mytech6779
@mytech6779 7 жыл бұрын
A traditional terminal screen or printer interprets all bytes as part of a character set. Actual numeric values such as integers must be converted to the corresponding characters before being sent to the screen. Thus the need for cout or printf formatting functions.
@justind6983
@justind6983 7 жыл бұрын
hey says this in a previous video :)
@Im10105656
@Im10105656 7 жыл бұрын
When you do char* name = "Cherno" don't you create a string literal that's read-only? Is name[2] = 'a' is undefined behavior or not?
@TheCherno
@TheCherno 7 жыл бұрын
Yes, you're right. I should have defined it as *char name[] = "Cherno";* in that example.
@1vor12dokus8
@1vor12dokus8 2 жыл бұрын
thanks for the vid and all of them, still invaluable years later. One little remark to 13:36 and the overload of the "
@jiaxiin2769
@jiaxiin2769 10 ай бұрын
Yes, no need to add header in 2022
@abderezakabidi4510
@abderezakabidi4510 3 жыл бұрын
when i write char* name="alex" it return an error that says " a value of type "const char*" cannot used to initialize an entity of type "char*" why
@sso1328
@sso1328 3 жыл бұрын
The string (in this case, "alex") is a const char*, and you're trying to make it equal to a char* (name), which are not the same. The correct way would be: const char* name = "alex";
@pattech3960
@pattech3960 3 жыл бұрын
@@sso1328 Well the thing is, he was trying to do void main() { char* name = "Alex"; name[2] = 'a'; } like in the video, but it created the error ' a value of type "const char*" cannot used to initialize an entity of type "char*" ' I had the same problem, but I'm just ignoring it now that I am not sure what kind of solution there is to do it. I'll definitely learn it later on for sure.
@pattech3960
@pattech3960 3 жыл бұрын
std::string name = "BAUHAUS"; name[2] = 'S'; std::cout
@sallaklamhayyen9876
@sallaklamhayyen9876 2 жыл бұрын
Brilliant explanation thank you so much and please continue we need content about C++ Data Structure STL and more about critical parts in C++
@OFaruk58
@OFaruk58 6 жыл бұрын
Amazing video's Just noticed the "Gear I use" All off them are freaking expensive lol
@Josifer4GAppFire
@Josifer4GAppFire 7 жыл бұрын
I still don't understand how a char* can be a string.. I thought a pointer is just a memory address
@vitorkiguchi4670
@vitorkiguchi4670 7 жыл бұрын
the way the char* and char[] strings work in C/C++ is so: the text inside the double quotes is broken up into individual characters, and those characters are stored in a char array, with a '\0' as the last element of the array. The pointer itself points to the adress of the first element of the array, the beggining of the string, while the end of it is marked with the '\0' char.
@aryesegal1988
@aryesegal1988 7 жыл бұрын
the type of a quoted string literal, such as "Cherno", is actually char*. That is, a quoted string literal IS actually an address. An address of what? It is the address of the first character in the string. That means that the entire construct "Cherno" - including the double quotes - actually equals to the address of the first character, 'C' in this case. The reason for this is that the compiler stores the string literal ("Cherno") in memory, and it only remembers the address of the strings' beginning character ('C' in our case.) All the program needs to actually use this string is use the address of its first character. The terminating null character '\0' takes care of marking the end of the string literal.
@ArachnosMusic
@ArachnosMusic 4 жыл бұрын
@@vitorkiguchi4670 I know this is an old comment, however you say the following: 'The pointer itself points to the address of the first element of the array.' Shouldn't it be the case that this pointer IS the memory address for that first element? And if so, why then does cout
@piaIy
@piaIy 4 жыл бұрын
@@ArachnosMusic operator
@abderezakabidi4510
@abderezakabidi4510 4 жыл бұрын
@@vitorkiguchi4670 I read your answer and i think you can help me to solve this error. So, I got an error when I run the code below . //// char* name="learn"; std::cout
@rylanjohnson9049
@rylanjohnson9049 Жыл бұрын
Might be confusing at first just understand that the reason std::cout prints the string instead of the memory address is just because it interprets it as a C-style string instead of printing the address
@Trainfan1055Janathan
@Trainfan1055Janathan 3 жыл бұрын
What does it mean when there are double quotes with no text in them? For example, in this one script for a tram in a train simulator I play, there's a line of text that reads: string destination = ""; (I'm trying to learn how trains are scripted in this game, so I can make my own scripts.)
@sacripudding4586
@sacripudding4586 3 жыл бұрын
its just making an empty string with nothing in it but also making sure it isn't null so if something tried to get that destination it wouldn't just crash the program when it doesn't get a string out of it.
@jukit3906
@jukit3906 3 жыл бұрын
well it would just put the '\0' at the memory location
@jukit3906
@jukit3906 3 жыл бұрын
to be more precise the const char pointer would point at a char of value 0
@salazangar
@salazangar Жыл бұрын
is it some new feature or why does my VS not allow me to compile char* name = "sid"; it tells me only const char* is allowed
@suntianrun1653
@suntianrun1653 Жыл бұрын
Please check the pinned comment.
@murtazahussain6301
@murtazahussain6301 4 жыл бұрын
when passing an object as argument, copy is made on stack not on the heap @ 17:18
@CacheTaFace
@CacheTaFace 4 жыл бұрын
These videos are so helpful, you are the MAN!
@v-for-victory
@v-for-victory 2 жыл бұрын
Very good explaining and a great series.
@eliasabdulbaaki6090
@eliasabdulbaaki6090 3 жыл бұрын
This dude is very good.
@jerfersonmatos28
@jerfersonmatos28 4 жыл бұрын
Wow, very clear explanation
@Idlecodex
@Idlecodex 5 жыл бұрын
Oh Man.... This is like Game Of Thrones! a Marathon I can only leave if I fall asleep...! Damn it!
@serkanozturk4217
@serkanozturk4217 2 жыл бұрын
Personal notes: C style string: Char* name = “john” or const char* string. The reason some prefer const declaration is that once you allocate that memory for string, you cannot extend it and say name = “john wick” -Use std::string for C++
@gabeastone8793
@gabeastone8793 6 жыл бұрын
This is more to pointers, but how come when you print name you got Cherno? Why isn't the address printed since you didn't deference it?
@igorthelight
@igorthelight 6 жыл бұрын
Probably, that's how std::cout works with strings.
@DainYanuka
@DainYanuka 5 жыл бұрын
That is exactly what I wanna know too
@zoriiginalx7544
@zoriiginalx7544 4 жыл бұрын
@@DainYanuka std::cout assumes your intention. If you pass in a const char* data type in the argument, it will interpret your intention as wanting to print out a C-Style string instead of a memory address.
@xristosbart8217
@xristosbart8217 7 жыл бұрын
What was that about? I mean the thing about the new series. I guess heap allocation, polymorphism and constructor initialization is what's left untill we can get to data stractures, right?
@UTRG-UnderTheRain
@UTRG-UnderTheRain Жыл бұрын
This is what I love about watching program videos online if I type char * name = "Cherno"; I get a red underline under Cherno with and error saying type const char can not be used to i.... using vs2022C why don't you have it? why do I have it? I've typed exactly the same code in?
@painfullyhuman
@painfullyhuman Жыл бұрын
c++11 change; look at pinned comment. equivalent would be char name[] = "Cherno";
@DJ-jy5mu
@DJ-jy5mu 7 ай бұрын
string too big, trailing characters how to fixed it because I am trying to put 64-bit of a .exe on to a c++ script
@majesticmack
@majesticmack 7 жыл бұрын
I already know c++. I just watch these vids just to see Yan haha
@SouravChakraborty-y3w
@SouravChakraborty-y3w 3 күн бұрын
Thank you so much for this information!
@ashishmathewabraham7278
@ashishmathewabraham7278 5 жыл бұрын
I really like the fact that you show how the memory view in Visual studio works , which it makes so much clear . I wanted to see this memory view in Xcode . Do you happen to know if the memory view is available in Xcode?
@anuglybug4473
@anuglybug4473 4 жыл бұрын
while using a breakpoint: in the ‘debug window pane’ right mouse click on the variable of interest -> in the drop down menu that opens, left mouse click on ‘ view memory of “...variable...” ‘ ( as is demonstrated in ‘visual studio’ ) does anyone know how to get a ‘tool tip’ to display of the address of a variable while the mouse cursor is over the variable ??? & is there a way to enter the variable name into a text box that then displays the variable’s values in the memory window pane ? [as an alternative to the solution provided above]
@codewithfelix3940
@codewithfelix3940 2 жыл бұрын
this is some fresh breath of c++ here ...
@mm1979dk
@mm1979dk 7 жыл бұрын
15:00 you could write it even simpler using literals (C++14), like this: auto hello = "Hello"s + " world!";
@ArachnosMusic
@ArachnosMusic 4 жыл бұрын
Shouldn't it be the case that the pointer 'name' is the memory address for the first element of the const char[] array which is "Cherno"? And if so, why then does cout
@DineshGowda24
@DineshGowda24 6 жыл бұрын
I like how u explain c++ and enjoy it. C++ is one the best lovely languages if we understood it properly. Keep up the good work. Just saw ur playlist on c++ gonna watch it all today. Hope u upload more c++ videos.👌👌👌👌👌 Top notch stuff
@ilyosbeknajmiddinov6754
@ilyosbeknajmiddinov6754 2 жыл бұрын
Hello, I have error initializing can't convert from const char[9] to char* could you help me !?
@remak6342
@remak6342 4 жыл бұрын
another EXCELLENT video!
@Murderface666
@Murderface666 7 жыл бұрын
Just a random, unrelated fact: From the beginning of this series to this date, I've lost 30lbs from dieting and exercise
@TheCherno
@TheCherno 7 жыл бұрын
Is that because you had to make room for all the C++ knowledge? ;)
@Murderface666
@Murderface666 7 жыл бұрын
yup! Now myself and my code is a lot more lean lol
@utkarshgupta3
@utkarshgupta3 6 жыл бұрын
@@TheCherno ha
@Quaggabagel
@Quaggabagel 6 жыл бұрын
How you doing know?
@Djzaamir
@Djzaamir 7 жыл бұрын
great video as always @Cherno
@keshavjha9835
@keshavjha9835 4 жыл бұрын
char* is a mutable pointer to a mutable character/string. const char* is a mutable pointer to an immutable character/string. You cannot change the contents of the location(s) this pointer points to. Also, compilers are required to give error messages when you try to do so. For the same reason, conversion from const char * to char* is deprecated. char* const is an immutable pointer (it cannot point to any other location) but the contents of location at which it points are mutable. const char* const is an immutable pointer to an immutable character/string.
@xrafter
@xrafter 4 жыл бұрын
Happy i am. Thanks
@brakpseudonimu236
@brakpseudonimu236 2 жыл бұрын
So what's the difference between char* and other pointers? As I understand, it's just a pointer like any other pointer, and the memory allocation and writing is done by the double quotes function that returns the pointer, right?
@ContentConsumer90
@ContentConsumer90 5 жыл бұрын
8:37 name in char* name is a pointer variable and pointer variable is an integer(address value) then how cout
@ОсипПоддерегин
@ОсипПоддерегин 4 жыл бұрын
std::cout works differently with different operands You can think of it, basically, as function overloading: you can have functions with identical names but with different input types. Compiler decides what version of the function should be called based on types of the arguments you pass in Pretty much same here, (although I'm not sure that is exactly how standard library is implemented): There is a version of this 'cout function' (technicaly, it's ostream& operator
@xrafter
@xrafter 4 жыл бұрын
Will you can type cast if wanted it to print a integer
@tachiibou
@tachiibou 7 жыл бұрын
I believe that in the book "Effective c++, 55 specific ways to improve your code" they say that most types from the std library is somehow as effective to copy as it is to just send a reference. Is this wrong? Or maybe I am just remembering wrong.
@jamesmnguyen
@jamesmnguyen 7 жыл бұрын
What's faster? Copying a pointer, or allocating memory and copying data?
@pradyumnkejriwal3007
@pradyumnkejriwal3007 7 жыл бұрын
James Nguyen depends on the size of the data
@БаракОбама-ь8р
@БаракОбама-ь8р 11 ай бұрын
Hello Cherno! I am from Russia thank you! You helps me
@gurnoorchahal9224
@gurnoorchahal9224 3 жыл бұрын
How does he see the memory at 7:22 ? what program is he using?
@nathancwatkins
@nathancwatkins 4 жыл бұрын
at 13:10, when he says you can change the string (a const char array) by doing "an implicit cast to a char pointer" if we wanted to manipulate the array. Could someone clarify what he means here. I really appreciate it. p.s Love the series! Sorry if im a noob, learing c++ at a cc -
@pavanrameshghate5416
@pavanrameshghate5416 4 жыл бұрын
apart from the study did you pick your channel name from the Pacific Rim movie(cause one of the yager names in that one is cherno Alpha)
@PsyberSenpai
@PsyberSenpai 3 жыл бұрын
Do you have a camera setup video, this video has a distinct look to it
@1234feng
@1234feng Жыл бұрын
Thank you ! Can you talk about c++ std::wstring performance slow and how to improve performance ?
@killakill8731
@killakill8731 6 жыл бұрын
why do not use 'using namespace std; ' does it has something to do with performance ? I already researched but I didn't quite understand.
@alexhorejsi6287
@alexhorejsi6287 6 жыл бұрын
From what I have heard, 'using namespace std' is often considered bad practice. Apparently there is so many classes and functions in that namespace that it is not unlikely that you will accidentally name a function or class the same as something in the std namespace. I have heard from several developers that they have spent a lot of time debugging code that used 'using namespace std' due to name conflicts
@mathewmccloskey8242
@mathewmccloskey8242 7 жыл бұрын
Great video, as always :)
@Gaurav_techi
@Gaurav_techi 2 жыл бұрын
Hello Dear, I need help . I want to write a function which will accept two char pointer and perform concatenation and then return char pointer back. Also we do not have to use any library function. I tried but not able to get the result. Kindly help. Thank you
@yasoda1
@yasoda1 5 жыл бұрын
Yan, you are a Godsend!
@nighma
@nighma 7 жыл бұрын
Thanks! That's great! Hope to see more next. There are already a bunch of "that will be explained in another video" reference in this serie. I can't wait! Thank you
@ppoplawski
@ppoplawski 6 жыл бұрын
In the example at 15:00 i've also found a way that you can just explicitly cast the " hello!" const char* to std::string (like "Cherno" + (std::string)" hello!";). Is it also a way you would recommend to do concatenation in C++? In other words - are there any disadvantages 'under the hood' while using this method?
@touchdepp4507
@touchdepp4507 2 жыл бұрын
Don't use C-style casts in C++ programming. C-style casts are the most dangerous ones.
@borovikmotion
@borovikmotion Жыл бұрын
Hey, I've noticed that conversion from int to string in python works 3 times faster than in C++ somehow. Any Idea why? I'm talking about str() and to_string() methods. thank you!
@petarsmilajkov9431
@petarsmilajkov9431 6 жыл бұрын
Great videos man. Needed to brush up on C++ as I haven't used it in years, and I've been 2X-ing your videos all day. Now on 32! Matrix upload-style. What app do you use for screen recording if I may ask? Thanks and keep the videos coming!
@hahashreyaspp
@hahashreyaspp 4 жыл бұрын
I was able to use 'cout' to print the string to the console without including the string.h header file. But you said it will be an error. How come?
@hahashreyaspp
@hahashreyaspp 4 жыл бұрын
Peterolen yes I meant,
@xrafter
@xrafter 4 жыл бұрын
@@hahashreyaspp Iostream will include the string header file
@tokyoanimeseven
@tokyoanimeseven 6 жыл бұрын
Bro Your Explanation Is Just Awesome.
@monishkumardurairaj3038
@monishkumardurairaj3038 5 жыл бұрын
@13:07 if you need to manipulate the contents of const char* try type caseting to char * . i tried converting const char* name="chernno"; *((char*)name+2)='a'; it throws segmentation fault error arises....why?
@monishkumardurairaj3038
@monishkumardurairaj3038 5 жыл бұрын
HI@Peterolen, so there is no way, we could change the contents of a string literal?or is there any. another doubt is strings are immutable... but where this memory is allocated.... stack or heap or const/global memory? so char* name="cherno"; here name is a constant char* type by default...? is my understanding correct? thanks in advance
@monishkumardurairaj3038
@monishkumardurairaj3038 5 жыл бұрын
Thanks@Peterolen.......
@rohitkumarshrivastava9693
@rohitkumarshrivastava9693 5 ай бұрын
Does string declaration and initialization without `const` keyword make it mutable?
@TheSpartan989
@TheSpartan989 6 жыл бұрын
When you were talking about ways to add onto strings, could you use the .append method as another way to add onto the string?
@xrafter
@xrafter 4 жыл бұрын
Append is just a heap thing
@Florian-rp1jg
@Florian-rp1jg 4 жыл бұрын
why does printing a char array return the letters and not the memory adress
@sepro5135
@sepro5135 5 ай бұрын
Probably because the operator for cout is overloaded for char arrays, I think you could cast the char* to another pointer and print out the memory adress
@youmaster4331
@youmaster4331 6 жыл бұрын
Hello I have a problem with using code blocks. It do not give an autocompletion of all the declarations in string header file because they are in __cxx11 namespace how to fix this
@arpitaingermany
@arpitaingermany Жыл бұрын
there is nothing called append here? for adding extra string?
@TheStapleZ
@TheStapleZ 7 жыл бұрын
Please keep making these videos!! :)
@wsk3184
@wsk3184 7 жыл бұрын
17:04 You said that passing string by value will use heap? Is this really true? I thought that in such case stack is used.
@TheCherno
@TheCherno 7 жыл бұрын
+wsk3184 the string object itself will be on the stack, however it will allocate on the heap to store the char array.
@wsk3184
@wsk3184 7 жыл бұрын
Ok. Thanks.
String Literals in C++
14:07
The Cherno
Рет қаралды 198 М.
Templates in C++
17:58
The Cherno
Рет қаралды 606 М.
Enceinte et en Bazard: Les Chroniques du Nettoyage ! 🚽✨
00:21
Two More French
Рет қаралды 42 МЛН
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
Arrays in C++
18:31
The Cherno
Рет қаралды 435 М.
Copying and Copy Constructors in C++
20:52
The Cherno
Рет қаралды 440 М.
Stack vs Heap Memory in C++
19:31
The Cherno
Рет қаралды 584 М.
Macros in C++
19:36
The Cherno
Рет қаралды 243 М.
Object Oriented Programming (OOP) in C++ Course
1:30:26
freeCodeCamp.org
Рет қаралды 2,6 МЛН
CONST in C++
12:54
The Cherno
Рет қаралды 414 М.
How to make your STRINGS FASTER in C++!
15:02
The Cherno
Рет қаралды 121 М.
you will never ask about pointers again after watching this video
8:03
Enceinte et en Bazard: Les Chroniques du Nettoyage ! 🚽✨
00:21
Two More French
Рет қаралды 42 МЛН