<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>string handling in c Archives - NeuralLantern.com</title>
	<atom:link href="https://www.NeuralLantern.com/tag/string-handling-in-c/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.NeuralLantern.com/tag/string-handling-in-c/</link>
	<description></description>
	<lastBuildDate>Sun, 23 Nov 2025 23:41:21 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.NeuralLantern.com/wp-content/uploads/2025/04/cropped-2025-04-04-Lantern-03-32x32.png</url>
	<title>string handling in c Archives - NeuralLantern.com</title>
	<link>https://www.NeuralLantern.com/tag/string-handling-in-c/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Why C Strings End with \0 &#8211; Null Terminated Strings Explained Simply</title>
		<link>https://www.NeuralLantern.com/why-c-strings-end-with-0-null-terminated-strings-explained-simply/</link>
					<comments>https://www.NeuralLantern.com/why-c-strings-end-with-0-null-terminated-strings-explained-simply/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 23 Nov 2025 23:41:20 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[\0 in c]]></category>
		<category><![CDATA[ascii strings]]></category>
		<category><![CDATA[c char array]]></category>
		<category><![CDATA[c language basics]]></category>
		<category><![CDATA[c programming for beginners]]></category>
		<category><![CDATA[c programming strings]]></category>
		<category><![CDATA[c programming tutorial]]></category>
		<category><![CDATA[c string functions]]></category>
		<category><![CDATA[c string termination]]></category>
		<category><![CDATA[c strings]]></category>
		<category><![CDATA[low-level programming]]></category>
		<category><![CDATA[null terminated strings]]></category>
		<category><![CDATA[null terminator]]></category>
		<category><![CDATA[string handling in c]]></category>
		<category><![CDATA[strlen implementation]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=256</guid>

					<description><![CDATA[<p>Null-terminated strings in C use a zero byte (\0) to mark the end instead of storing length. Learn exactly how C strings work under the hood, see the ASCII values for "Hello", and understand why the null terminator exists.</p>
<p>The post <a href="https://www.NeuralLantern.com/why-c-strings-end-with-0-null-terminated-strings-explained-simply/">Why C Strings End with \0 &#8211; Null Terminated Strings Explained Simply</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="Why C Strings End with   - Null Terminated Strings Explained Simply" width="1380" height="776" src="https://www.youtube.com/embed/IPWsPMH12YE?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p>Ever wondered why C strings are just character arrays that magically know where they end? It&#8217;s all because of the null terminator &#8211; that sneaky \0 at the end.</p>



<p>In this video we break it down super simply:</p>



<ul class="wp-block-list">
<li>What a C string actually is (spoiler: just bytes)</li>



<li>Why old-school assembly needed separate length labels</li>



<li>How adding a single zero byte fixed everything</li>



<li>Quick look at ASCII codes for &#8220;Hello&#8221;</li>



<li>Why \0 is the perfect terminator (and how to write it in code)</li>



<li>How loops know when to stop reading the string</li>



<li>Real example in assembly with and without null termination</li>
</ul>



<p>Perfect if you&#8217;re learning C, diving into low-level programming, or just curious about what&#8217;s really happening when you write &#8220;hello&#8221; in C.</p>



<p>Introduction to Null Terminators 00:00:00<br>What is a C String? 00:00:11<br>Problems with Explicit Length in Assembly 00:01:06<br>Idea of a Special Terminator Symbol 00:01:24<br>Introduction to ASCII 00:02:20<br>Why ASCII is Outdated &#8211; Move to UTF 00:03:59<br>Example &#8211; &#8220;Hello&#8221; as ASCII Bytes 00:06:32<br>Mapping &#8220;Hello&#8221; to ASCII Codes 00:07:00<br>How Strings are Stored in Memory 00:08:46<br>The Null Terminator (\0) Explained 00:09:39<br>Null is ASCII Code 0 (NUL) 00:10:02<br>Escape Sequence \0 in Code 00:10:49<br>How Loops Use Null Terminator to Stop 00:11:55<br>Null-Terminated Strings in Assembly 00:12:41<br>Summary of C Strings 00:13:23<br>Outro and Call to Action 00:13:32</p>



<p>Thanks for watching!</p>



<p>Find us on other social media here:</p>



<ul class="wp-block-list">
<li>https://www.NeuralLantern.com/social</li>
</ul>



<p>Please help support us!</p>



<ul class="wp-block-list">
<li>Subscribing + Sharing on Social Media</li>



<li>Leaving a comment or suggestion</li>



<li>Subscribing to our Blog</li>



<li>Watching the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p>hey there let&#8217;s quickly talk about null terminators in c strings</p>



<p>so first off what&#8217;s a c string it&#8217;s basically just a character array it&#8217;s just an array of numbers</p>



<p>and the numbers will be interpreted as characters and what&#8217;s a null terminator it&#8217;s pretty easy it&#8217;s</p>



<p>just a a way to terminate the string so that a program can automatically determine where the</p>



<p>string ends in assembly a lot of times we&#8217;ll have you know a string like we&#8217;ll</p>



<p>say oh gosh I don&#8217;t want to write this out right now we&#8217;ll say you know my</p>



<p>string and we&#8217;ll define it as an array of bytes and then we&#8217;ll say you know</p>



<p>hello or something right and then later in order to tell the assembly program</p>



<p>how long the string is we&#8217;ll use an extra symbol this is not really an</p>



<p>My string length is going to be equal to, this is the ASM assembly by the way in case</p>



<p>you&#8217;re wondering, some kind of special symbol, my string length.</p>



<p>And then now we have defined the actual string and then the length of the string.</p>



<p>But this is kind of annoying, right?</p>



<p>We have to define an extra thing to say how long the string is.</p>



<p>And then we have to pass two different things that are kind of the same name later on when</p>



<p>we want to print a string.</p>



<p>But that&#8217;s not really the best way to do it.</p>



<p>that&#8217;s not really the best way to do it what if instead we just put a special symbol I don&#8217;t know</p>



<p>what should I put right now put a special zero I&#8217;ll just put like a question mark and we&#8217;ll say</p>



<p>that the question mark is a special symbol and then when we want to have part of our program</p>



<p>print the string we can just only give it the string and it can scan the string and as soon</p>



<p>as it sees that special symbol let&#8217;s say the question mark for now it&#8217;ll know when to stop</p>



<p>processing it or whatever we could allow the program to scan in advance to compute the the</p>



<p>length and maybe store it somewhere so we can keep using it we can allow the program to just</p>



<p>continuously print out characters maybe they&#8217;re buffered or something or processing characters</p>



<p>and then just stop when we get to the question mark but the point is it&#8217;s a little bit less work</p>



<p>for us to have a special symbol at the very end okay so a spoiler the symbol is going to be a zero</p>



<p>Now let&#8217;s look at a special table that is called ASCII.</p>



<p>Well, it&#8217;s not, the table&#8217;s not called ASCII,</p>



<p>but this is sort of like a scheme that was invented a long time ago.</p>



<p>I forget what this stands for.</p>



<p>It&#8217;s like American standard, maybe character something, something.</p>



<p>It&#8217;s basically for American purposes.</p>



<p>A long time ago, we decided, you know what?</p>



<p>I&#8217;d like to represent characters using one byte per character.</p>



<p>bits or you know a value that can go between 0 and 255 and we&#8217;ll just start assigning these numbers</p>



<p>to different characters so you can see here on this ascii table it&#8217;s kind of like an old thing</p>



<p>let me turn on my little annotator you can see on this table well the letter h is mapped</p>



<p>to the number 72. so this is this was arbitrary at the time now it&#8217;s a standard because everybody</p>



<p>accepts uh you know ascii uh in certain parts of your programs it&#8217;s kind of a little out of date</p>



<p>of a little out of date now because you know in the modern era it&#8217;s a lot smarter for your programs</p>



<p>to support a world of different characters you know for all different languages than only to</p>



<p>support characters that are common in english and even here there&#8217;s probably some stuff missing that</p>



<p>english users would probably want to add like certain accents and symbols and things like that</p>



<p>so you know the the letter o lowercase o it&#8217;s 111 uh the letter o uppercase is 79 so we&#8217;ve got you</p>



<p>so we&#8217;ve got you know a basic idea of mapping so for the purposes of this example i&#8217;m just</p>



<p>gonna assume we&#8217;re using ascii to make things easier okay so that&#8217;s an ascii table um</p>



<p>oh i guess i should say that the modern scheme that we usually use is called utf let me just uh</p>



<p>write that down on a notepad right now so we&#8217;ve got utf right now it&#8217;s just a different standard</p>



<p>but the same idea you know with ASCII we only had one byte with UTF we have a wide variety of</p>



<p>choices we can do UTF-8 which basically also means one byte it closely map maps to ASCII I</p>



<p>think all or almost all the characters will map to ASCII and then we have UTF-16 which means two</p>



<p>bytes or 16 bits and then we have UTF-32 which is basically four bytes or 32 bits as far as I</p>



<p>while. UTF-32 should be able to handle all the characters that all the languages of the world</p>



<p>commonly use. Just to double check, if you take two to the something power where the power, let&#8217;s</p>



<p>say y, two to the y, where y is the number of bits in question, then you can get an idea for the</p>



<p>number of combinations that you can represent. So two to the 32nd power, that&#8217;s about four billion.</p>



<p>I should have known that off the top of my head. That&#8217;s about four billion possible combinations.</p>



<p>So I don&#8217;t know.</p>



<p>I think in my opinion, probably 32 is enough for all symbols in the world, for all languages</p>



<p>in the world.</p>



<p>I&#8217;m not sure.</p>



<p>If not, then we would probably want to use UTF-64 if that exists, which definitely would</p>



<p>cover all symbols in the world.</p>



<p>But that&#8217;s really not the point of this video.</p>



<p>I just wanted to mention it because if you&#8217;re writing an application on your own, you want</p>



<p>to start your own business or you&#8217;re, you know, you&#8217;re working for someone, you probably</p>



<p>almost certainly do not want to use ASCII.</p>



<p>do not want to use ascii you probably want your database and your program to be able to use utf</p>



<p>16 or 32 because you want to be able to support international users and that&#8217;s not going to work</p>



<p>i had a website a long time ago that i wrote the database was in uh it was like latin 8 or</p>



<p>some scheme in the database where it was basically ascii just you know eight bits per character and i</p>



<p>could type characters in their native language and they were kind of disappointed and i lost a</p>



<p>lot of business until i realized oh i should upgrade my database and my program to support</p>



<p>utf but anyway the point of this video is not international character support the point of this</p>



<p>video is what is a null terminator and how do you use it in a c string so i&#8217;m going to get back on</p>



<p>Hello. Okay, so we got hello. This would basically be an array of characters or an array of in ASCII</p>



<p>one byte characters. So I&#8217;ll put like a number here and a number here and there&#8217;ll be five numbers.</p>



<p>What numbers are they? Well, if we&#8217;re using ASCII, then we should map these</p>



<p>using the ASCII table. So again, in the ASCII table here, what is capital H?</p>



<p>the number 72 and then the lowercase e that&#8217;s going to be the number 101 so i&#8217;ll just maybe do</p>



<p>like an arrow here the number 101 and then the capital h is going to be the number 72 and then</p>



<p>we got two l&#8217;s lowercase so that&#8217;s going to be this right here and that&#8217;s going to be the number</p>



<p>108 and then lowercase o that&#8217;s going to be the number 111 so basically you know you just go</p>



<p>through the characters you want to represent and map them using the ascii table or hopefully</p>



<p>table or hopefully an actual lookup table inside your program and then you can do the same thing</p>



<p>backwards you know what is what does 72 mean it means h so i&#8217;m going to erase this for now</p>



<p>and i&#8217;m going to go back to my little notepad here and i&#8217;m just going to fill out the numbers</p>



<p>so the first is going to be 72 oh actually before i fill these out hang on let me just</p>



<p>show you that this is basically what we&#8217;re trying to translate here so we got like an uppercase h</p>



<p>In many programming languages, definitely C++, which is the one I&#8217;m thinking of, we would use double quotes for an actual long string, like a proper string, a literal string, or like an STD string or something.</p>



<p>And we would use an array of single quoted characters to say this is one character that maps to one or more bytes, in this case, one byte.</p>



<p>So I&#8217;m going to say H-E-L-L-O and put them all in single quotes.</p>



<p>And then we&#8217;ll just sort of like translate the numbers here.</p>



<p>translate the numbers here. So we said the H was 72 because it was capital. It was like a lower</p>



<p>number. And then the E is going to be 101. And then the L is 108. We&#8217;ll do two of those 108.</p>



<p>And then the O was a 111. So you can imagine somewhere in an array of data in the computer,</p>



<p>there&#8217;s the number 72, 101, 108, you know, whatever. And even further thinking about it,</p>



<p>about it a little more deeply the number 72 is not actually in the machine it&#8217;s really a sequence of</p>



<p>ones and zeros right so just imagine that inside the machine there&#8217;s just a ton of ones and zeros</p>



<p>for this particular sequence you know five times eight which would be the number of uh you know</p>



<p>eight is like the number of bits per byte since we&#8217;re doing one byte characters um what is that</p>



<p>40 let me just double check here i want to make sure i&#8217;m saying things that are somewhat correct</p>



<p>that are somewhat correct we&#8217;ll do eight times five whoops i think i screwed something up</p>



<p>eight times five 40 yeah okay so you can imagine 40 ones and zeros just inside the machine</p>



<p>anyway so we talked about before not wanting to specify the length of a string so we&#8217;ll just</p>



<p>place a special marker instead of a question mark we&#8217;ll use the number zero so i&#8217;m going to put a</p>



<p>I forgot if I actually pointed this out or not. I&#8217;ll just do this to be sure.</p>



<p>Somewhere on this, you can see that the number zero in decimal, or zero in hexa, or zero in octal,</p>



<p>you&#8217;re welcome, you know how to do those other systems, is just considered null. So it&#8217;s sort</p>



<p>of a control code, or it&#8217;s not necessarily a symbol, it&#8217;s more of a control code. We&#8217;ll say</p>



<p>the number 72 that means h capital h but if we see the number zero that means null and in the</p>



<p>scheme that we&#8217;re going to use we will say that null terminates the string that&#8217;s why we call it</p>



<p>a null terminator so null terminators are basically just zeros that terminate the string</p>



<p>i could put null here inside of the the character representation just to kind of show you</p>



<p>other languages and we want to do single quoted characters we can usually use an escape sequence</p>



<p>which is just basically slash zero this is not a video about escape sequences but imagine that</p>



<p>every time there is a slash a forward slash and then you know one character after that then the</p>



<p>character will be interpreted zero for example if we just put zero by itself then that actually would</p>



<p>be the ascii code for zero or just the character code for zero in this particular case zero is uh</p>



<p>where the heck is the zero you can&#8217;t even find it oh there it is right there that&#8217;s like so the</p>



<p>the character zero is represented by the number 48 but that&#8217;s not what we actually want we want</p>



<p>the actual number zero because we&#8217;re trying to get a null terminator so anyway we couldn&#8217;t just put</p>



<p>a regular zero in there because it would be interpreted as 48 instead we put a slash which</p>



<p>tells the computer that the thing that follows is a control character so that will be interpreted as</p>



<p>interpreted as actually a zero or null terminator.</p>



<p>So now that we know how to put a null terminator in an array of characters and we know what</p>



<p>it&#8217;s going to look like if we&#8217;re just talking about numbers, we now know that if you have</p>



<p>a program that has let&#8217;s say a for loop and it&#8217;s kind of like going through, you know,</p>



<p>do all the characters, if it&#8217;s going through every single character one by one and doing</p>



<p>something to them, printing them, modifying, adding them to an algorithm, whatever.</p>



<p>this for loop or actually this should probably be a while loop since for loops</p>



<p>are kind of limited and the while loop will know when to break because as soon as it sees a</p>



<p>character that is actually just the number zero it&#8217;ll say oh i found the null terminator i will</p>



<p>now ignore this and break the loop i won&#8217;t do anything with this character because the null</p>



<p>is a terminator it&#8217;s not part of the string um what else you know actually i think that&#8217;s pretty</p>



<p>much it if you&#8217;re in assembly uh i&#8217;m just going to go back to yasm assembly for a second because i</p>



<p>like i like to talk about that lately and imagine we have like a string called my string and we say</p>



<p>it&#8217;s a sequence of bytes and i say hello you know this is how you would do this in x84 60 x 84 64</p>



<p>yasm assembly on ubuntu or just linux then uh you know this string right here is just a string with</p>



<p>null terminate with no null terminator you want to add a null terminator to the end of it so that</p>



<p>null terminator to the end of it so that you can write a better function that would scan your string</p>



<p>and print it without knowing in advance how long it was then you just do a comma zero at the end</p>



<p>and now you can easily write a function to scan or read or process your strings because this is</p>



<p>really what&#8217;s what&#8217;s happening under the hood it&#8217;s just like a sequence of characters and then it</p>



<p>ends with the zero and there you go that&#8217;s the basics of c strings with null terminators</p>



<p>this video i hope you had fun and learned a little bit of stuff i&#8217;ll see you in the next video</p>



<p>hey everybody thanks for watching this video again from the bottom of my heart i really</p>



<p>appreciate it i do hope you did learn something and have some fun if you could do me a please</p>



<p>a small little favor could you please subscribe and follow this channel or these videos or whatever</p>



<p>it is you do on the current social media website that you&#8217;re looking at right now</p>



<p>looking at right now, it would really mean the world to me and it&#8217;ll help make more videos</p>



<p>and grow this community. So we&#8217;ll be able to do more videos, longer videos, better videos,</p>



<p>or just I&#8217;ll be able to keep making videos in general. So please do me a kindness and subscribe.</p>



<p>You know, sometimes I&#8217;m sleeping in the middle of the night and I just wake up because I know</p>



<p>somebody subscribed or followed. It just wakes me up and I get filled with joy. That&#8217;s exactly what</p>



<p>happens every single time. So you could do it as a nice favor to me or you could troll me if you</p>



<p>You could troll me if you want to just wake me up in the middle of the night, just subscribe.</p>



<p>And then I&#8217;ll just wake up.</p>



<p>I promise that&#8217;s what will happen.</p>



<p>Also, if you look at the middle of the screen right now, you should see a QR code, which</p>



<p>you can scan in order to go to the website, which I think is also named somewhere at the</p>



<p>bottom of this video.</p>



<p>And it&#8217;ll take you to my main website where you can just kind of like see all the videos</p>



<p>I published and the services and tutorials and things that I offer and all that good</p>



<p>stuff.</p>



<p>If you have a suggestion for clarifications or errata or just future videos that you want to see,</p>



<p>please leave a comment.</p>



<p>Or if you just want to say, hey, what&#8217;s up?</p>



<p>What&#8217;s going on?</p>



<p>You know, just send me a comment.</p>



<p>Whatever.</p>



<p>I also wake up for those in the middle of the night.</p>



<p>I wake up in a cold sweat and I&#8217;m like,</p>



<p>It would really mean the world to me.</p>



<p>I would really appreciate it.</p>



<p>So again, thank you so much for watching this video.</p>



<p>And enjoy the cool music as I fade into the darkness.</p>



<p>as I fade into the darkness which is coming for us all.</p>



<p>Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/why-c-strings-end-with-0-null-terminated-strings-explained-simply/">Why C Strings End with \0 &#8211; Null Terminated Strings Explained Simply</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/why-c-strings-end-with-0-null-terminated-strings-explained-simply/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
