String Literals in C++

  Рет қаралды 200,597

The Cherno

The Cherno

Күн бұрын

Пікірлер: 242
@ahumanzr
@ahumanzr 4 жыл бұрын
Cherno: 6:00 "Please never spell it like that ever" The top five comments: "Charno"
@thedeliverguy879
@thedeliverguy879 4 жыл бұрын
Those are the ones that are willing to learn hahahaha
@southparkclips221
@southparkclips221 3 жыл бұрын
Haha, Nailed it!
@user-ic5nv8lj9d
@user-ic5nv8lj9d 3 жыл бұрын
XD
@humbledcomposer
@humbledcomposer 11 ай бұрын
😅
@danielc4267
@danielc4267 6 жыл бұрын
Charno talking about char related stuff.
@dimitri929
@dimitri929 4 жыл бұрын
The Charno is making one of the best c++ tutorials
@h.hristov
@h.hristov 7 жыл бұрын
Thanks Charno! A very informative video on string literals
@strange1702
@strange1702 Жыл бұрын
after 5years top comment does not even have a single reply lol
@VortexInfoTech-gw8hp
@VortexInfoTech-gw8hp Жыл бұрын
In this video he said the correct is Cherno not Charno
@strange1702
@strange1702 Жыл бұрын
@@VortexInfoTech-gw8hp he was joking 🤣 you should understand what joke is lol
@brandx5443
@brandx5443 Жыл бұрын
I'd swear he said Chaarno. @@VortexInfoTech-gw8hp
@LucidStew
@LucidStew 7 жыл бұрын
Thanks again for the great series, Charno
@tiancilliers
@tiancilliers 7 жыл бұрын
TheCharnoProject back at it again with great vids!
@blank-vw2sb
@blank-vw2sb 4 жыл бұрын
Cherno: please never spell it like that ever. 99% comments: The CHARNO!
@prayagparikh8020
@prayagparikh8020 3 жыл бұрын
Great tutorial Charno! Keep it up, Charno!!
@DainYanuka
@DainYanuka 6 жыл бұрын
I like how the subtitles said 'White Cabbage' instead of 'Wide Character' at 6:55 xD Thanks Charno for the great vid!
@teachyourselfcs
@teachyourselfcs Жыл бұрын
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
@kanishk9490
@kanishk9490 4 жыл бұрын
The auto generated subtitles be like : "Hey What's up guys my name is Archana and welcome back to my figure of blood theory"
@forhadrh
@forhadrh 3 жыл бұрын
Yeap we admit, youtube subtitle still sucks a lot 😖
@helpfulsquid2502
@helpfulsquid2502 3 жыл бұрын
AHAHAH true, I've noticed some similar examples in his other videos
@KPkiller1671
@KPkiller1671 7 жыл бұрын
Charno
@zyansheep
@zyansheep 4 жыл бұрын
Lesson Learned: Never ask the internet not to do something
@UA441
@UA441 4 жыл бұрын
I would make that joke!
@woosix7735
@woosix7735 4 жыл бұрын
Charno
@AdonaiDio
@AdonaiDio Жыл бұрын
The hardest on the playlist so far. Great video! I understood better than reading the books I bought.
@davitgoderdzishvili9187
@davitgoderdzishvili9187 7 жыл бұрын
amazing! this is one of the best channels about c++
@poonikarthu4988
@poonikarthu4988 2 жыл бұрын
Extremely helpful tutorial Charno! Keep it up!
@cajogos
@cajogos 5 жыл бұрын
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
@ezshroom
@ezshroom 4 жыл бұрын
I was looking for how to make games in Java and I saw his videos, then I had a look around and found these
@92309858
@92309858 7 жыл бұрын
Charno:)
@domthehypocrite
@domthehypocrite 7 жыл бұрын
Ye hav bin bannishhhheeedd.
@woosix7735
@woosix7735 4 жыл бұрын
Charno
@XaviosAedifica
@XaviosAedifica 4 жыл бұрын
The moment you said Charno I preemptively laughed becaused I knew the comments would be nothing but Charno
@vzxdarkangel1999ful
@vzxdarkangel1999ful 2 жыл бұрын
I like internet
@exnaruto1
@exnaruto1 7 жыл бұрын
Yes! Finally caught up
@daniyelzhumankulov7733
@daniyelzhumankulov7733 4 жыл бұрын
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
@OFaruk58
@OFaruk58 7 жыл бұрын
thanks Charno ! great vids
@muhammadtaimourafzal5285
@muhammadtaimourafzal5285 3 жыл бұрын
Cherno: "Confused about strings ? Aren't we all !!!"
@Erebus2075
@Erebus2075 5 жыл бұрын
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 ^^
@TalisBarbalho
@TalisBarbalho 7 жыл бұрын
Loving the videos and frequency. Thank you so much. It gets more and more exciting the more advanced you go.
@master138
@master138 2 жыл бұрын
10:15 That R thing was pretty useful. Specially for somebody who does GUI apps with a lot of error/warning dialogs.
@hanzofactory
@hanzofactory 2 жыл бұрын
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!
@josiahb.8611
@josiahb.8611 2 жыл бұрын
You spelt charno right.
@sallaklamhayyen9876
@sallaklamhayyen9876 3 жыл бұрын
awesome thank you Chreno we need more like that in detail explanations
@stathisstathopoulos9007
@stathisstathopoulos9007 6 жыл бұрын
Thanks a ton Charno, nice vid!
@krec348
@krec348 7 жыл бұрын
Things get more interesting from time to time... Awesome work Cherno :)
@yogurtbee7050
@yogurtbee7050 Жыл бұрын
So many thanks to you Charno , hh , A super excellent video I've ever seen on string literals, awesome ! you are my super hero !
@ImmortalSoulOfIndia
@ImmortalSoulOfIndia 2 жыл бұрын
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.
@francobarrera5327
@francobarrera5327 Жыл бұрын
Nice video Charno! ♥
@raashidansari
@raashidansari 7 жыл бұрын
I am amazed by how much I learned today! Thanks @TheChernoProject.
@shakedmigdal6364
@shakedmigdal6364 2 жыл бұрын
"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
@youcefbouda6856
@youcefbouda6856 Жыл бұрын
That's gonna be useful, thanks Charno
@shushens
@shushens 3 жыл бұрын
Q: What would be Charno's next vacation spot? A: Charno-bill.
@suntzu1409
@suntzu1409 3 жыл бұрын
I see what you did here
@bluehornet6752
@bluehornet6752 4 жыл бұрын
At 6:35, MSVC now seems to care as of VS2019: It now requires me to make it a const char*...
@xrafter
@xrafter 4 жыл бұрын
Yes they change it. But it still will give an warning not. An error so it is okay
@kavindaravishan7351
@kavindaravishan7351 3 жыл бұрын
wow Charno, this course is amazing.
@_blank86a
@_blank86a 3 ай бұрын
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.
@yamgabby8715
@yamgabby8715 4 жыл бұрын
Thank you Charno !
@kishorekurapati9172
@kishorekurapati9172 2 жыл бұрын
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.
@StevenMartinGuitar
@StevenMartinGuitar 2 жыл бұрын
Thanks The Charno!
@dabodyx
@dabodyx 2 жыл бұрын
here i am 5 years later, joining the charno hype
@Simple_OG
@Simple_OG 9 ай бұрын
6 🙋
@iwolfman37
@iwolfman37 2 жыл бұрын
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.
@Popart-xh2fd
@Popart-xh2fd 2 жыл бұрын
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!
@bitmobile5587
@bitmobile5587 Жыл бұрын
Thanks Che\0! Great tutorial!
@LS-cb7lg
@LS-cb7lg 4 жыл бұрын
char[] s = "Love your series, Cherno!"; s[20] = 'a'; std::cout
@henriquebussi
@henriquebussi 2 ай бұрын
thanks charno
@entity5209
@entity5209 4 жыл бұрын
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
@martiananomaly
@martiananomaly 3 жыл бұрын
Another great video by The Charno!
@mikicerise6250
@mikicerise6250 3 жыл бұрын
ALL LIES!!!! THE REAL REASON COMPUTERS WORK IS DAEMONS MAKE THEM WORK CUZ BILL GATES PRAYED TO SATAN!!!!! OPEN YOUR EYES!!!!
@FreeDomSy-nk9ue
@FreeDomSy-nk9ue 2 жыл бұрын
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
@batman_1st
@batman_1st 5 жыл бұрын
Thanks charno
@shishirjais
@shishirjais 4 жыл бұрын
You're "literal"ly the best.
@myriadtechrepair1191
@myriadtechrepair1191 6 жыл бұрын
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 *'
@vertigo6982
@vertigo6982 6 жыл бұрын
The knee... sweep it.
@Lmao-ke9lq
@Lmao-ke9lq 5 жыл бұрын
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
@marlonbrade9004
@marlonbrade9004 4 жыл бұрын
Hey i just notice that if you go , std::wstring name0 = L"Cherno" s + L"cherno"; when printing you should also include, std::wcout
@soumyakantigiri
@soumyakantigiri 4 жыл бұрын
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
7 жыл бұрын
use move void PrintStr(std::string&& string) { string += 'h'; std::cout
@Durgasivakumaran
@Durgasivakumaran 5 жыл бұрын
Really awesome. Thanks for effort
@murtazahussain6301
@murtazahussain6301 4 жыл бұрын
Thanks Charno
@sree4448
@sree4448 3 жыл бұрын
this really helped,thanks
@colorlord98
@colorlord98 7 жыл бұрын
Charno!
@sfafsashfdh6589
@sfafsashfdh6589 2 жыл бұрын
nice video charno
@higiniofuentes2551
@higiniofuentes2551 Жыл бұрын
And if we add the code page how it will be added in a string with more than one type of code page?
@LameDuckStudios
@LameDuckStudios 3 жыл бұрын
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.
@Brotcrunsher
@Brotcrunsher 7 жыл бұрын
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?
@TeeDawl
@TeeDawl 7 жыл бұрын
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.
@Brotcrunsher
@Brotcrunsher 7 жыл бұрын
Oh my! I thought only the basic operators could be overloaded. That's cool!
@dekrain
@dekrain 6 жыл бұрын
It's also used in "chrono" module for time literals
@Gunslinger962
@Gunslinger962 6 жыл бұрын
thanks Charno!
@VictorOrdu
@VictorOrdu 5 жыл бұрын
Fantastic stuff!
@GenericPhantom1
@GenericPhantom1 2 жыл бұрын
String literals are a series of characters between two double quotes
@Steven-tw7iz
@Steven-tw7iz 7 жыл бұрын
very useful info in this one!
@majedalshaikhi
@majedalshaikhi Жыл бұрын
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
@JoCS11152
@JoCS11152 2 жыл бұрын
mind fucking blowing
@LuxeonIII
@LuxeonIII 6 жыл бұрын
In the c++ bideo 32 How strings work, I get an error on the
@LuxeonIII
@LuxeonIII 6 жыл бұрын
Never mind forgot #include
@chainonsmanquants1630
@chainonsmanquants1630 4 жыл бұрын
Thanks !
@onurucar1112
@onurucar1112 4 жыл бұрын
thanks charno :)
@SuzukaTheBest
@SuzukaTheBest 4 жыл бұрын
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.
@tanweerashif
@tanweerashif 6 жыл бұрын
Which IDE are you using? Most IDEs don't let you see the things happening behind the scene other than the compilation error log.
@suntzu1409
@suntzu1409 3 жыл бұрын
Visual studio
@nickey0207
@nickey0207 3 жыл бұрын
Damn, your hair is PERFECT!
@iBlaze1232
@iBlaze1232 3 жыл бұрын
U sure about that?
@ibrahimg.4469
@ibrahimg.4469 3 жыл бұрын
Thank you
@uoweme5grand
@uoweme5grand 6 жыл бұрын
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.
@uoweme5grand
@uoweme5grand 6 жыл бұрын
@Peterolen Thank you kind sir for your quick and helpful reply.
@ContentConsumer90
@ContentConsumer90 5 жыл бұрын
@Peterolen since name is a pointer variable, shouldn't it print a integer? my doubt is how cout
@ContentConsumer90
@ContentConsumer90 5 жыл бұрын
@Peterolen thank you this helped a lot, always had this doubt. CHEERS!
@ali-4096
@ali-4096 7 жыл бұрын
Can you export your visual studio settings. That would be great. Because I love it!!
@johannes1464
@johannes1464 7 жыл бұрын
Check his first video's in this series
@spacetime_wanderer
@spacetime_wanderer 5 жыл бұрын
It beats me - why am I getting :A value of type "const char * " cannot be used to initialize an entity of type "char *", when doing 'char* var1 = "Hello"; ' I am using Visual Studio 2017. According to Cherno, VS allows this, and he isn't getting error. But I am. What could be wrong?
@mayurkulkarni755
@mayurkulkarni755 4 жыл бұрын
Thanks for this! This is extremely helpful! Charno ;)
@CacheTaFace
@CacheTaFace 4 жыл бұрын
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?
@MrRiceKrispyNotTaken
@MrRiceKrispyNotTaken Жыл бұрын
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
@feraudyh
@feraudyh 7 жыл бұрын
I thought there could be strings in which some characters take one byte, and some take more. As in UTF8 encoding. Is this just true for strings stored in files or in streams?
@ammgnero
@ammgnero 4 жыл бұрын
Thanks mate.
@xrafter
@xrafter 4 жыл бұрын
But char is signed integer why you give it a unsigned prefix?
@felipevillamil8454
@felipevillamil8454 5 жыл бұрын
why if I do sizeof(wchar_t) i get 4? shouldn't I get 2 instead?
@orocimarosay1447
@orocimarosay1447 7 жыл бұрын
hot to read a string with a space like if i use system("c:/documents and settings") it will only take c:/documents and how do i convert int to a string
@killakill8731
@killakill8731 7 жыл бұрын
the first i don't know what you wanted to say but about convert int to string: #include int main() { int num = 10; std::string intToString = std::to_string(num); }
@thang4671
@thang4671 3 жыл бұрын
Isn't char* a pointer type, which take something like &name as a value? How are you assigning a string to that?
@user-dh8oi2mk4f
@user-dh8oi2mk4f 3 жыл бұрын
A string literal is an array. Arrays implicitly decay to pointers during assignment.
@h.hristov
@h.hristov 7 жыл бұрын
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.
@julien-scholz
@julien-scholz 7 жыл бұрын
@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.
@elgs1980
@elgs1980 6 жыл бұрын
#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.
@f.r.i.e.n.d.s2368
@f.r.i.e.n.d.s2368 7 жыл бұрын
thanks a lot . if you could make videos on graph that'd be awesome :D
@sachof
@sachof 7 жыл бұрын
Could you explain the purpose of QStringLiteral ?
@ultimatedragon4281
@ultimatedragon4281 2 жыл бұрын
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.
@mohammedamer8075
@mohammedamer8075 Жыл бұрын
thanks
@mych5713
@mych5713 2 жыл бұрын
So when I write char name[] = "Cherno"; the compiler always makes a copy of the string literal "Cherno" at a non-read-only memory, right?
@minyeongjeong
@minyeongjeong 7 жыл бұрын
great video
@lysdexic9129
@lysdexic9129 7 жыл бұрын
Hi, I've noticed you endian swap addresses when you look into memory is this related to how data is stored in arrays?
@mytech6779
@mytech6779 7 жыл бұрын
It does effect 16bit storage units like ucs-2 and utf-16 when moving data between little endian and big endian machines, it does not effect single byte code units like latin-1 and UTF-8.
@user-dh8oi2mk4f
@user-dh8oi2mk4f 3 жыл бұрын
No, it’s related to how data is stored in integers. Most human languages store numbers in big endian. The first digit in a number has the most value(i.e. in the number 123, the 1 is worth the most). On the other hand, most CPUs store the digit with the least value in the first bit because it’s easier to operate on. This means when you want to peek at memory, you have to swap the bytes because the CPU stores them differently from how you read them. It has nothing to do with arrays.
@greob
@greob 7 жыл бұрын
Nice! You're churning out videos these days, we should call you TheChurno now. ;-)
@pradyumnkejriwal3007
@pradyumnkejriwal3007 7 жыл бұрын
Njul it would be pronounced the same
@kofer99
@kofer99 7 жыл бұрын
that's the point i think
@mrbee8336
@mrbee8336 5 жыл бұрын
Your profile pic tho
@LxAU
@LxAU 4 жыл бұрын
Love it! Way more witty than all the predictable Charno comments…
@tacodiva7729
@tacodiva7729 3 жыл бұрын
TheCharno*
@ibiixie
@ibiixie 7 жыл бұрын
Why are string literals stored in read only memory? Why are they not just stored like any other pointer?
CONST in C++
12:54
The Cherno
Рет қаралды 417 М.
The NEW Keyword in C++
10:53
The Cherno
Рет қаралды 253 М.
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН
1% vs 100% #beatbox #tiktok
01:10
BeatboxJCOP
Рет қаралды 67 МЛН
Copying and Copy Constructors in C++
20:52
The Cherno
Рет қаралды 443 М.
AI Is Making You An Illiterate Programmer
27:22
ThePrimeTime
Рет қаралды 117 М.
BEST WAY to read and understand code
17:24
The Cherno
Рет қаралды 169 М.
Why I don't "using namespace std"
14:35
The Cherno
Рет қаралды 400 М.
How Strings Work in C++ (and how to use them)
19:26
The Cherno
Рет қаралды 476 М.
Stack vs Heap Memory in C++
19:31
The Cherno
Рет қаралды 590 М.
Namespaces in C++
13:17
The Cherno
Рет қаралды 203 М.
OPERATORS and OPERATOR OVERLOADING in C++
12:44
The Cherno
Рет қаралды 388 М.
Templates in C++
17:58
The Cherno
Рет қаралды 611 М.