Don't stop being this deep with your explanations (strings in the stack vs read-only segment, heap, etc) for students like me this is the first "top to bottom" example that lets me integrate all the theoretical concepts in a single video explanation. You are a top class teacher (and programmer 😄) that allows me to connect all the dots
Cherno I just wanted to say that thank you so much for this series. I recently got into professional training for RealTime Embedded, and since we program mainly in C, all of this knowledge of the backside of C/C++ has come in incredibly useful since we work at a very low-level environment. You have no idea how grateful I am, I would have had a much harder time if it weren't for you!
these are definately the best C++ serie i've seen. easily understood and it is very nice to get what is happening behind the scenes; makes it easier to grasp ^^
I've been a subscriber for years man, I remember doing your old Java game engine series! Now that I am doing C++ at uni, these series is what I've been looking for! So glad you are still doing them :D
You are really amazing!!!!!please don't stop making videos. I truly think your series of these c++ tutorials are on of the most useful ones on the internet
a video on working with different string encoding like utf8 utf16 utf32 in a gui based applications in c++ along with different factors like compiler flags or settings that should be enabled or some other stuff need to work with these encodings would be great.
I'm not sure if this was the same back when he made the video, but there's actually a different wat to spread a string out over multiple lines, a method which actually applies to all types of statements, not just those that contain strings. To spread a statement over multiple lines, you simply use the backslash at the end of the line. So for example: const char* helloWorld = "Hello \ World !"; // This compiles to a string that would print out as simply "Hello World !" and is considered a (const char[14]). And this method applies to any statement like I said, so you could also write a statement like this one: int a = 1 + \ 2; // And this would also compile just fine and print out int a as 3.
Cherno mentioned that const char array can be modified in previous video. In this video, he told that it was by mistake. This c++ series is one of the best c++ tutorials. Even paid tutorials are not this professional or shares such knowledge.
I think you're wrong about this 11:16. I just tested it and the string gets modified in place both in release and debug mode. Even the assembly I got is different than the one you got. In my case it was 3 lines of assembly where the index was loaded into eax and the string was modified at eax! @The Cherno
Oh god imagine learning string s 2nd time here lol I know what string does but im still watching this video charno explains what they actually r and I'd rather know what I'm typing instead of just typing it and expect it to work just to end up with bunch of bugs the charno cpp tutorials r the best
7 лет назад+1
use move void PrintStr(std::string&& string) { string += 'h'; std::cout
quick question for anyone willing to answer/have the answer: const char* name = "Cherno"; does that mean you don't actually have to provide the char pointer with an address when it comes to string? and when he later tries to modify the string, he also did not dereference it.
Wow, that string literal s is interesting. Do you know if it would be somehow possible to code this yourself or is this a pure compiler/language feature which would not have been possible to implement ourselves?
Its possible. If you're interested, google "operator overloading c++". You can do really cool stuff. Thats what the class does, you can see that when he hovers over the string. foo::operator ""s(...) You can overwrite pretty much everything and create really weird and amazing stuff.
I can't seem to run any of this with char* name = "cherno"; I get "initializing: cannot convert from const char [7] to char*" I also can't run this if I insert the backslash 0 into the string. "che\0rno". I get "name array bound overflow" for that one. I'm in MSVC 2019.
Using Visual Studio 2017 Enterprise the non-const char* name = "String"; does return an error. Maybe they heard you or maybe enterprise operates differently. I got enterprise from my school so I decided why not use it. error C2440: 'initializing': cannot convert from 'const char [8]' to 'char *'
I have 2 questions. If you could answer any of them, I'd be grateful! 1. If you define the same string literal twice, for ex. const char* name1 = "Cherno"; const char* name2 = "Cherno";, does the compiler notice it and create only one instance of "Cherno" into the read-only part of the executable in order to save space? Therefore making name1 and name2 point to the same memory location where "Cherno" is. 2. If I call a function with the prototype void test(char* arg); and pass in a string, for ex. calling test("Cherno is good");, is the string literal "Cherno is good" put into the read-only memory during compilation? So when you call that function, a char array is created on the stack and is initialized with the string literal "Cherno is good" which ion its own is in RO, and then that array is passed as the argument to the function. The function handles it as a char pointer, therefore allowing us to modify the contents of the array.
@Lightslinger Deadeye 2. Nah I don't think so, the string literal is constant, and passing it as a pointer to a function doesn't change that. The pointer just points to the constant part of the memory.
#include int main(int argc, char const* argv[]) { char* a = "Cherno"; char* b = "Cherno"; char* c = "Charno"; printf("%p ", a); printf("%p ", b); printf("%p ", c); return 0; } Try run this code. I got: 0x55fbf81f1004 0x55fbf81f1004 0x55fbf81f100f Hope this should answer your first question.
Okay, so I didn't understand the last part. When I tried to do it with memory open, we can see that the value changes exactly where it was so is it like it makes a copy changes the value and re-assigns the literal in the same location? I didn't get it
So... a string is an object of type std::string (which basically a char* bundled up with helper functions), while a string literal is a read only value that can be assigned to string objects? So string literals are not strings, and strings are not necessarily string literals?
Hi Cherno, I am using Visual Studio Community 2022. Can you tell me where I can find the "Memory Mode" that you use to check how memery allocates bytes for different variables ? Could not find it at all !! 😔thank you
I dont get it with const char*. If * only pointer which holds address in memory, why when I'm printing * pointer to console it looks like "001DFB58" but when we printing in console "const char*" it shows like normal string and not the address of first char in the array.
I had a bit of problem using the "strlen" function. For some reason stdlib.h did not include it. If someone else has the same problem, the solution that worked for me was to include cstring instead of stdlib.h. That should make the function work.
Charno talking about char related stuff.
Cherno: 6:00 "Please never spell it like that ever"
The top five comments: "Charno"
Those are the ones that are willing to learn hahahaha
Haha, Nailed it!
XD
😅
The Charno is making one of the best c++ tutorials
Thanks Charno! A very informative video on string literals
after 5years top comment does not even have a single reply lol
In this video he said the correct is Cherno not Charno
@@VortexInfoTech-gw8hp he was joking 🤣 you should understand what joke is lol
I'd swear he said Chaarno. @@VortexInfoTech-gw8hp
Thanks again for the great series, Charno
TheCharnoProject back at it again with great vids!
Cherno: please never spell it like that ever.
99% comments: The CHARNO!
Great tutorial Charno! Keep it up, Charno!!
Don't stop being this deep with your explanations (strings in the stack vs read-only segment, heap, etc) for students like me this is the first "top to bottom" example that lets me integrate all the theoretical concepts in a single video explanation. You are a top class teacher (and programmer 😄) that allows me to connect all the dots
Charno
Lesson Learned: Never ask the internet not to do something
I would make that joke!
Charno
I like how the subtitles said 'White Cabbage' instead of 'Wide Character' at 6:55 xD Thanks Charno for the great vid!
The hardest on the playlist so far.
Great video!
I understood better than reading the books I bought.
The auto generated subtitles be like : "Hey What's up guys my name is Archana and welcome back to my figure of blood theory"
Yeap we admit, youtube subtitle still sucks a lot 😖
AHAHAH true, I've noticed some similar examples in his other videos
Extremely helpful tutorial Charno! Keep it up!
Charno:)
Ye hav bin bannishhhheeedd.
Charno
10:15 That R thing was pretty useful. Specially for somebody who does GUI apps with a lot of error/warning dialogs.
Cherno: "Confused about strings ? Aren't we all !!!"
Cherno I just wanted to say that thank you so much for this series. I recently got into professional training for RealTime Embedded, and since we program mainly in C, all of this knowledge of the backside of C/C++ has come in incredibly useful since we work at a very low-level environment. You have no idea how grateful I am, I would have had a much harder time if it weren't for you!
You spelt charno right.
amazing! this is one of the best channels about c++
these are definately the best C++ serie i've seen.
easily understood and it is very nice to get what is happening behind the scenes; makes it easier to grasp ^^
The moment you said Charno I preemptively laughed becaused I knew the comments would be nothing but Charno
I like internet
thanks Charno !
great vids
I've been a subscriber for years man, I remember doing your old Java game engine series! Now that I am doing C++ at uni, these series is what I've been looking for! So glad you are still doing them :D
I was looking for how to make games in Java and I saw his videos, then I had a look around and found these
awesome thank you Chreno
we need more like that in detail explanations
Nice video Charno! ♥
Hey Charno, I saw a very informative session on "String Literals". And It is explained well too. Hats off you Man. I am from INDIA.
Yes! Finally caught up
You are really amazing!!!!!please don't stop making videos. I truly think your series of these c++ tutorials are on of the most useful ones on the internet
Thanks a ton Charno, nice vid!
Loving the videos and frequency. Thank you so much. It gets more and more exciting the more advanced you go.
a video on working with different string encoding like utf8 utf16 utf32 in a gui based applications in c++ along with different factors like compiler flags or settings that should be enabled or some other stuff need to work with these encodings would be great.
10:36 Here you have just shown that it's possible to append strings by simple not using the + sign and separate them with a blank space!
I'm not sure if this was the same back when he made the video, but there's actually a different wat to spread a string out over multiple lines, a method which actually applies to all types of statements, not just those that contain strings. To spread a statement over multiple lines, you simply use the backslash at the end of the line. So for example:
const char* helloWorld = "Hello \
World !"; // This compiles to a string that would print out as simply "Hello World !" and is considered a (const char[14]).
And this method applies to any statement like I said, so you could also write a statement like this one:
int a = 1 + \
2; // And this would also compile just fine and print out int a as 3.
So many thanks to you Charno , hh , A super excellent video I've ever seen on string literals, awesome ! you are my super hero !
Cherno mentioned that const char array can be modified in previous video.
In this video, he told that it was by mistake. This c++ series is one of the best c++ tutorials. Even paid tutorials are not this professional or shares such knowledge.
Q: What would be Charno's next vacation spot?
A: Charno-bill.
I see what you did here
Things get more interesting from time to time... Awesome work Cherno :)
That's gonna be useful, thanks Charno
char[] s = "Love your series, Cherno!"; s[20] = 'a'; std::cout
At 6:35, MSVC now seems to care as of VS2019: It now requires me to make it a const char*...
Yes they change it.
But it still will give an warning not.
An error so it is okay
Thanks The Charno!
I think you're wrong about this 11:16. I just tested it and the string gets modified in place both in release and debug mode.
Even the assembly I got is different than the one you got. In my case it was 3 lines of assembly where the index was loaded into eax and the string was modified at eax!
@The Cherno
"ohh look a nice string quirky stuff that i didn't know"
"OH MY LORD IS THIS THE ASSEMBLY FILE"
thats pretty much sums my reaction.
great video
Thanks Che\0! Great tutorial!
I am amazed by how much I learned today! Thanks @TheChernoProject.
thanks charno
Hey i just notice that if you go ,
std::wstring name0 = L"Cherno" s + L"cherno";
when printing you should also include, std::wcout
Thank you Charno !
wow Charno, this course is amazing.
here i am 5 years later, joining the charno hype
6 🙋
You're "literal"ly the best.
Another great video by The Charno!
ALL LIES!!!! THE REAL REASON COMPUTERS WORK IS DAEMONS MAKE THEM WORK CUZ BILL GATES PRAYED TO SATAN!!!!! OPEN YOUR EYES!!!!
Oh god imagine learning string s 2nd time here lol I know what string does but im still watching this video charno explains what they actually r and I'd rather know what I'm typing instead of just typing it and expect it to work just to end up with bunch of bugs the charno cpp tutorials r the best
use move
void PrintStr(std::string&& string)
{
string += 'h';
std::cout
Thanks Charno
nice video charno
this really helped,thanks
String literals are a series of characters between two double quotes
Charno!
Thanks charno
thanks charno :)
quick question for anyone willing to answer/have the answer:
const char* name = "Cherno";
does that mean you don't actually have to provide the char pointer with an address when it comes to string?
and when he later tries to modify the string, he also did not dereference it.
@Peterolen Thank you kind sir for your quick and helpful reply.
@Peterolen since name is a pointer variable, shouldn't it print a integer?
my doubt is how cout
@Peterolen thank you this helped a lot, always had this doubt. CHEERS!
Really awesome. Thanks for effort
Thank you
Damn, your hair is PERFECT!
U sure about that?
Wow, that string literal s is interesting. Do you know if it would be somehow possible to code this yourself or is this a pure compiler/language feature which would not have been possible to implement ourselves?
Its possible. If you're interested, google "operator overloading c++". You can do really cool stuff. Thats what the class does, you can see that when he hovers over the string. foo::operator ""s(...)
You can overwrite pretty much everything and create really weird and amazing stuff.
Oh my! I thought only the basic operators could be overloaded. That's cool!
It's also used in "chrono" module for time literals
Thanks for this! This is extremely helpful! Charno ;)
I can't seem to run any of this with char* name = "cherno"; I get "initializing: cannot convert from const char [7] to char*"
I also can't run this if I insert the backslash 0 into the string. "che\0rno". I get "name array bound overflow" for that one.
I'm in MSVC 2019.
thanks Charno!
Using Visual Studio 2017 Enterprise the non-const char* name = "String"; does return an error. Maybe they heard you or maybe enterprise operates differently. I got enterprise from my school so I decided why not use it.
error C2440: 'initializing': cannot convert from 'const char [8]' to 'char *'
The knee... sweep it.
im using visual studio 2019 community and i cant make non cost char* name = "string"; too. so its not caused by enterprise version of VS
I have 2 questions. If you could answer any of them, I'd be grateful!
1. If you define the same string literal twice, for ex. const char* name1 = "Cherno"; const char* name2 = "Cherno";, does the compiler notice it and create only one instance of "Cherno" into the read-only part of the executable in order to save space? Therefore making name1 and name2 point to the same memory location where "Cherno" is.
2. If I call a function with the prototype void test(char* arg); and pass in a string, for ex. calling test("Cherno is good");, is the string literal "Cherno is good" put into the read-only memory during compilation? So when you call that function, a char array is created on the stack and is initialized with the string literal "Cherno is good" which ion its own is in RO, and then that array is passed as the argument to the function. The function handles it as a char pointer, therefore allowing us to modify the contents of the array.
@Lightslinger Deadeye
2. Nah I don't think so, the string literal is constant, and passing it as a pointer to a function doesn't change that. The pointer just points to the constant part of the memory.
#include
int main(int argc, char const* argv[]) {
char* a = "Cherno";
char* b = "Cherno";
char* c = "Charno";
printf("%p
", a);
printf("%p
", b);
printf("%p
", c);
return 0;
}
Try run this code. I got:
0x55fbf81f1004
0x55fbf81f1004
0x55fbf81f100f
Hope this should answer your first question.
Thanks !
mind fucking blowing
very useful info in this one!
Fantastic stuff!
Okay, so I didn't understand the last part. When I tried to do it with memory open, we can see that the value changes exactly where it was so is it like it makes a copy changes the value and re-assigns the literal in the same location? I didn't get it
Good episode Charno.
Which IDE are you using? Most IDEs don't let you see the things happening behind the scene other than the compilation error log.
Visual studio
Can you export your visual studio settings. That would be great. Because I love it!!
Check his first video's in this series
Thanks mate.
6:05 Ch97no is testing reverse psychology!
You can malloc the char* if you want to modefy it
thanks
ohh 7:40
const HWND name = L"Sigmo";
const wchar_t** ptr = &name;
std::cout
So... a string is an object of type std::string (which basically a char* bundled up with helper functions), while a string literal is a read only value that can be assigned to string objects? So string literals are not strings, and strings are not necessarily string literals?
string cherno; is an array of char, no?
Will Terry internally it is (if u talking about std::string)
i see what u did there
Haha, I also had this joke in mind.
_Sorry not sorry!_ (For him if he feels bad :(
)
thanks a lot . if you could make videos on graph that'd be awesome :D
And if we add the code page how it will be added in a string with more than one type of code page?
why i can't use
char* name = "Che\0rno";
name[2] = 'A';
on new versions of visual studio? i get this expression must be a modifiable lvalue
next episode: how to write a bot in C++ to ban people on youtube xddd
Yes, ~for people who spell it incorrectly for fun.~
great video
Python user detect!
2:24
THIS IS EXACTLY WHAT I NEEDED!! THIS GUY IS A FUCKIN GOD!!!
Hi Cherno, I am using Visual Studio Community 2022. Can you tell me where I can find the "Memory Mode" that you use to check how memery allocates bytes for different variables ? Could not find it at all !! 😔thank you
In the c++ bideo 32 How strings work, I get an error on the
Never mind forgot #include
I dont get it with const char*.
If * only pointer which holds address in memory, why when I'm printing * pointer to console it looks like "001DFB58" but when we printing in console "const char*" it shows like normal string and not the address of first char in the array.
Love your videos! super useful and informative, Thanks mister* Charno :)
Nice video
I had a bit of problem using the "strlen" function. For some reason stdlib.h did not include it.
If someone else has the same problem, the solution that worked for me was to include cstring instead of stdlib.h. That should make the function work.
But char is signed integer why you give it a unsigned prefix?