Labeling foundational memory architecture as a "nightmare" reflects a modern developer's discomfort with the transparency that makes C powerful. This is basic literacy, not a horror story.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
Strings in C Are a NightmareAdded:
Welcome back to a 33-year-old boomer teaches you stuff.
Strings in C are kind of a nightmare, but they don't have to be.
Let's have a little Let's have a little look at them. Let's create a little strings.c file.
Okay.
So, let's play around with some strings.
You see the funny thing is that C doesn't actually support strings.
Strings are kind of a high-level concept.
A CPU doesn't know what strings are.
So, in C, what a what a string actually is is a pointer to a an array of characters.
So, the type would be character pointer.
We'll pick a variable name Oh, I don't know. Something like this. And then, what string do we want? Let's say something random like this. I think that works pretty well.
Now, let's let's examine our little string, shall we?
So, we can do printf and we're going to specify a format.
This is a format specifier.
And I'll explain what it is in a second.
And we'll do it We're doing a new line as well cuz I Once we print to the terminal, I want to do a new line.
And we provided the variable femboy.
So, now we can run it and boom, it prints the string.
So, essentially, what's happening in memory right now is femboy points to an address in memory.
And then, we're saying, "Hey, we want a string." So, in other words, it looks in memory and it prints the string that it finds there.
So, why do we use these format specifiers here?
Well, as far as the computer is concerned, there is no such thing as a string, there's no such thing as an integer, there's no such thing as anything other than zeros and ones.
Let me show you.
So, if if we did let's say we do something else. So, let's say we print a number.
You do that with percent D.
Let's say you know, like let's say we want to give it a binary number such as this one.
Now, as far as the computer is concerned, when you ask it to print something, you're essentially just giving it some bytes.
Is what you're doing. You're just give You're just giving it zeros and ones.
When you ask to print something, the computer doesn't know what format you want that to be printed in because as far as the CPU is concerned, everything is zeros and ones.
And so, by giving it a format specifier, you're saying, "I want you to print whatever I give you in this format."
So, if we print this, you'll see that we get the number 69 because that this is the binary for 69.
Um but of course, 69 itself can mean different things.
What if you're you know, it could refer to a character. So, you can do C for character, and if you do this, bam, it's capital E.
And if you want proof of that, we can literally just replace it with 69.
Boom, capital E. So, that's why we're using these format specifiers. It's here's a bunch of binary interpreted in a certain way and printed for me.
Now, as I mentioned earlier, uh I mentioned this thing called pointers.
And if you've done C before, you may or may not know what they are.
Um a pointer is essentially just an integer. So, if you have a variable that contains a pointer, it's it's just an address for somewhere in the memory where something else is.
So, for example, if we want to see the address of the variable femboy, we do P for pointer.
Let's also do a new line.
And then we do the oops Oh, oopsie doopsie. Oh, oopsie doopsie.
We do the address of femboy.
So, if we print this, this is the add memory address in hexadecimal where this is stored. Now, bear in mind not not to get too autistic, but this isn't um this isn't the physical address. This is the virtual address because of course the kernel doesn't allow you access to the actual physical hardware. It acts as a as a a middleman between you and the hardware.
Specifically because it would be a disaster if some some bratty femboy [snorts] doing C would get their their hands on on actual hardware.
You could do all sorts of naughty things. And so you don't get direct access to memory. And so if I run it multiple times, uh if you look at the number, you'll notice that it's different every time.
This you know, you can look here. So, 16AE26 16D362, whatever. Because every single time you run the program, the kernel puts you somewhere else in memory.
Presumably there's a some sort of security measure because I assume that you could probably do some damage if you if you knew exactly where you would land in memory every time. Now, if you want some further proof of this, let's do let's declare another string variable.
Let's call it a furry. [snorts] And um let's do this. I think that I think this is fine. I think I don't think we're going to get sued, right?
I hope I hope >> [laughter] >> not.
So, if we do this, as you can see, they're stored in different addresses.
Femboy is stored here and furry is stored over here.
Is this making any sense? Am I Am I making sense? Do Do tell me if I'm if I'm not making any sense. Now, let me show you something interesting.
So, this asterisk thing means that it's a pointer.
But, what happens if we put the asterisk right here?
Well, let's find out.
So, let's Let's not do pointer. Let's do a digit number.
Huh.
That's interesting. We get 68.
Now, why is this?
So, what we're doing is we're dereferencing the variable. So, what we're actually doing So, doing pointer to Femboy is literally just like doing this.
That we're essentially pointing to the very first element in the Femboy array.
Whether we do Femboy of zero or whether we do pointer to Femboy, it's exactly the same thing.
Now, if you want proof of this, so we can do like a printf %c do n and then we just do 68.
So, if you do this, then you get D, which is which which 68 is the ASCII character for D.
Because here we're interpreting it as a number and here we're interpreting it as a character. If you want, we can literally interpret this as a character and as you can see, it's D, which is the first letter in the array.
Now, you might ask yourself, what if we go past the string? So, this right here is 0 1 2 3 4 5.
So, 0 1 2 3 4 5. So, if we do Femboy of five, we get I.
So, what happens if we do femboy of six?
Because if you try to do something like this in other languages, you might get You might get a little slap on the wrist. They might tell you, "Uh-uh-uh, you're not allowed to do this."
But in in C, you can do this, and it gives you this.
Now, you might ask, "Christian, what in the name of all all that is femboyish and good is this?"
>> [sighs and gasps] >> Well, that is a null terminator.
So, if you think about it, when you store stuff in memory, how is the computer supposed to know or how is the program supposed to know when a string ends?
Well, what actually happens is there is a null terminator that is added at the end of these strings. So, this is actually this actually exists at the end of it. And this tells the computer, "Hey, this string ends right here."
Now, if you want evidence of this, cuz I know you're very incredulous. I know you require loads of evidence for everything, which is good. It's fine.
It's very good. It's very good thing to do.
I'm going to show you. So, the um the character for the the character for ASCII zero is actually this.
There you go.
So, uh this is the character Many terminals use this to show control uh character.
So, if you if you've ever done control C to stop a program from running, you would have seen this. And this represents null.
Okay, so let's get back to this bit here, cuz I want to You see, I have a question. I'm very I'm a very curious individual.
You see, I'm very curious. What happens if we do this?
Because we've now gone past the null terminator.
So, what happens if we print this on the screen? What what are we going to get?
Cast your votes down below in the comments. Like and subscribe [laughter] Like and subscribe. Anyway, let's see.
Huh.
We get P. That's kind of weird. Why do Why are we getting P? What if we do eight? What happens then?
Hmm, we get a lowercase R. Now, you may have noticed already that this is a bit of a coincidence because we have P and R right here.
What What if we do nine?
Okay. So, clearly what's happening is these two strings are being stored contiguously in memory.
Because as you can see, if we just keep If we just keep incrementing femboy, we're obviously outside of femboy.
What we're actually doing is we're referencing virtual memory. So, we can keep incrementing this and we keep seeing more and more of the furry variable. And I think with a like 15, probably the last uh primogen. So, then 16 is the null terminator for primogen.
And then if we go past that, we're just going to get a bunch of like junk uh memory, essentially.
Um which is essentially what happens after that.
Okay. So, if we increase the index, then that's what happens. But, what if we print this as a string and we do this?
What happens now?
Because remember, what this variable does is it points to the very first character in the array of femboy.
Now, what happens if we do femboy plus one?
Let's check it out. And we're printing it as a string, remember.
We start the string from the second position because if we have uh if we have um so we have this is this is essentially what we have in memory, right?
So, if we if we're here, this is this is this is where femboy or femboy of zero leads to.
So, if we increment that by one, what we're doing is this.
So, now we start the string from here.
That's what that does.
Now, what if we do something else? What if we do this?
What does this do?
Let's Let's find out.
Oh, sorry. My bad.
Uh we don't we don't want to print a string. We want to print a character.
Now, this is interesting. Why did we get E? How did this happen? How How in the world did we get uh an E?
Well, let's think about this for a second.
So, if we were to just print femboy like this, we get D, which is the very first element in here. When I mentioned earlier that there are no strings, as far as the CPU is concerned, the only thing that exists is binary. It's on and off.
>> [snorts] >> Which means that strings are actually just binary, which means that strings are essentially just integers.
And as you Sorry, not strings, but characters are integers, as we've as I've shown you earlier.
And the beautiful thing about integers is that you can do mathematical operations with them.
And so, what's happening when you do this is if we print that as a number is what's happening is you is you're doing 68 plus one, which is 69. Very nice.
And of course, 69 is E.
Because D + 1 is actually capital E.
D + 2 is capital F.
I + 1 is um is lowercase J.
That's how it work. Isn't that the coolest thing ever?
>> [laughter] >> Like Like let me show you.
So if I if I do uh character I + 1 and we print it, that's 106.
As [snorts] ASCII or as a character, that's lowercase J. Isn't that the coolest thing in the world?
>> [laughter] >> Now, I don't know if you've ever asked yourself this question, but you might ask, what is the length of femboy?
Well, there is a simple way that we can find out.
So we can do something called strlen.
So we can do printf. We're looking for a digit, so we're going to do strlen of femboy.
Now, we also have to include another header file, which is strings.h.
So if I do this, um Oh, it wants uh long unsigned.
Femboy's long unsigned. Oh my god.
There you go. Six. D I I N K I, that's six. And of course, if we do this for I I didn't even think about the long unsigned thing. That's That's really funny. Of course, Primogen is nine.
Now, if you were like me, uh this is not sufficient.
Because what I'm now wondering is okay, how how does strlen even work?
Like how how does this thing even function?
Well, as it turns out, we can actually write our very own very simple function to calculate the length of any [snorts] any string. So you're going to learn quite a bunch right now. Let's let's have a look.
So first thing we're going to do is we're going to declare another function.
We're going to declare a int type function. Let's call it length of.
Uh we're going to feed it a string.
Uh and int here just means that we're going to return a value that is an integer because of course we're returning its length.
We're going to declare an iterator outside of uh the of of a loop that we're going to write because of course we want to retain the value of I after we exit the loop. If you don't know what I'm talking about, go check out the previous video where I talk about this.
So we're going to do a for loop.
We've already declared the iterator so we can ignore that part.
So we're going to run this loop as long as string of I, so the current value, isn't a null terminator.
Because if you think if you remember from earlier, every string ends in a null terminator.
And so if you if you point it to a place in memory where a string starts, which is what the string variable is going to be, then the for loop is going to keep doing um uh sort of uh what's it called like index arithmetic or something like that where essentially it will it will iterate through each for each address in memory and it will check its contents until it hits a null terminator. And that is the end of the string.
And we're going to, of course, increment.
So all we have to do is i plus plus. That's it.
So, i plus plus, this this is actually where the C plus plus joke comes from. Cuz get it? Cuz it's better than C.
So, what this does, this is the equivalent of this. It's just a faster way of writing this.
So, what happens here? So, let's let's say we feed it the femboy string.
So, iterator is zero. We enter the for loop.
So, we go string of zero, which is capital D.
Is that a null terminator?
Nope. Okay. Well, we go in here and we iterate one.
Then we go whoop. We go back here.
We look at I, which is the second element. Is it a null terminator? Nope.
Whoop. We go here. We iterate. Whoop. Go back here.
I n k i So, bear in mind that by the time we get to here, so this is zero, 1 2 3 4 5.
We then go through here one more time and we're now looking at the sixth uh, element in the at the sixth index in this array, which is a null terminator.
Is it a null terminator?
It is. Whoop. We exit the for loop and now we hold the length of the string in the uh, iterator.
So, all we do is we return I. So, 0 1, 1 2, 2 3, 3 4, 4 5, 5 6.
And that's how we get the value of I.
So, we return I. So, now all we have to do is we have to call uh, the function.
So, all we need to do is we're going to print it as a number and we're going to do length of femboy.
So, now if we run this, boom. We can also do length of furry, which is Huh?
What is happening here?
>> [laughter] >> Huh?
Bro, what is happening?
Am I losing my mind? mind? There must be something really obvious that I'm missing. So, Okay, let's do a bit of debugging. Let's see what's actually happening. So, when we we're going to also going to print the current meme.
What?
>> [laughter] >> What?
I mean, I I appreciate the dick joke.
That's funny, but what Oh my god.
Ah.
I'm >> [sighs and gasps] >> Ah. This is the problem here.
Yeah.
It's already being iterated here, silly.
Oh my >> [laughter] >> god.
Ah.
Oh, no.
Oh, I bet people were watching going lol. What a What a silly goose.
What a silly goose. Is this going to be nine?
It is nine. Oh.
>> [laughter] >> See, you're watching some printf debugging in real time, my man. You're >> [laughter] >> You're welcome.
Oh my god, man.
>> [laughter] >> Oh, that was so funny.
Oh my god, okay.
Now, before we go, I I do also want to cuz I want to do a thumbnail where I also have like size of Uh that'll be fun to use. Let me show you how size of works.
So, size of is a function that you can use to get the size of anything really. So, let's say you want to do this.
Or actually, if we're going to do the might as well make it big. Let's go.
So, uh this is Oh, sure I should print it.
So, we're going to print the size of D, of course.
Let's just do this.
All right, it's not a I think it wants like long unsigned.
Oh.
Oh my god, what am I It's very hot outside, okay? That's the It does want long unsigned, lol. Cuz I'm not I'm on a Okay, yeah.
So, that actually gave us four four bytes. That's because this is actually an integer. So, um which is Yeah, but if we if you want the the size of a character, it's actually one byte, right? So, um that's that's what this is. Am I Am I making any sense? Let's see, if we do value of femboy, that's eight um because uh we're on a 16-bit machine, so that's uh 64-bit or eight bytes.
I think that I think that's good. Yeah, we'll just we'll just use that. Thank you very much for watching. I hope you enjoyed this. It was a bit all over the place. I think it was pretty funny.
Hopefully, it was pretty informative.
Um I don't know, if If want to check out my books, they're on GitHub.
Got some cool stories right here. You can check You can check out Whisper, short story of Protectorate.
And I'll see you in the next one.
Bye-bye.
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 views•2026-05-29
🚀 BCS613C Compiler Design | Module 1 to 5 Schema Evaluation 🔥 | VTU 6th Sem 💯 #VTU #bcs613c #exam
Pranavaa-y4y
104 views•2026-06-02











