{"id":13928,"date":"2023-02-11T14:49:06","date_gmt":"2023-02-11T09:19:06","guid":{"rendered":"https:\/\/fastbitlab.com\/?p=13928"},"modified":"2023-02-11T14:49:06","modified_gmt":"2023-02-11T09:19:06","slug":"microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal","status":"publish","type":"post","link":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\/","title":{"rendered":"Microcontroller Embedded C Programming lecture 177| String variable Vs string literal"},"content":{"rendered":"<div class=\"boldgrid-section\" style=\"background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"container\">\n<div class=\"row\" style=\"padding-top: 35px; padding-bottom: 0px; background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"col-md-1 col-sm-12 col-xs-12 col-lg-1\">\n<div class=\"boldgrid-shortcode\" data-imhwpb-draggable=\"true\">\n\n<\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<div class=\"col-md-10 col-sm-12 col-xs-12 col-lg-10\">\n<h1 class=\"\" style=\"text-align: center; font-size: 35px; border-width: 0px; line-height: 50px;\"><strong><span style=\"color: #000080;\">String variable Vs string literal<\/span><\/strong><\/h1>\n<div class=\"row bg-editor-hr-wrap\" style=\"border-width: 0px; margin-top: 0px;\">\n<div class=\"col-lg-12 col-md-12 col-xs-12 col-sm-12\">\n<div>\n<div class=\"bg-hr bg-hr-10 color2-color\" style=\"border-style: solid; border-width: 0px 0px 3px;\"><\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\">A string literal is a sequence of characters that are directly written in the code, while a string variable is a named memory location that stores a reference to a string value that can be changed during runtime.<\/span><\/p>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 25px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><b>String Variable<\/b><\/span><\/p>\n<figure id=\"attachment_13931\" aria-describedby=\"caption-attachment-13931\" style=\"width: 629px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-13931 \" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/02\/Figure-1-6.png\" alt=\"Figure 1. Code \" width=\"629\" height=\"244\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-1-6.png 1633w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-1-6-300x116.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-1-6-1024x397.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-1-6-768x298.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-1-6-600x233.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-1-6-1536x595.png 1536w\" sizes=\"(max-width: 629px) 100vw, 629px\" \/><figcaption id=\"caption-attachment-13931\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 1. Code<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400;\"><span style=\"color: #000000;\">Here, the first printf is to print the address of the msg1 variable. So, that&#8217;s a reason I use <strong>&amp;msg1<\/strong>.<\/span>&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">The second one is to print the value which is contained in the variable msg1. That&#8217;s why I use msg1 here.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">You can see the output in the SWV ITM Data Console, the address of the msg1 variable is&nbsp; 0x2001ffdc. This actually belongs to the RAM address.&nbsp; So because RAM starts from 0x200 in this microcontroller.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And look at the value of the msg1 variable, it is also 0x2001ffdc. When you have an array, the address of msg1 or the value of msg1, both are the same.<\/span><\/p>\n<figure id=\"attachment_13932\" aria-describedby=\"caption-attachment-13932\" style=\"width: 671px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-13932 \" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/02\/Figure-2-4.png\" alt=\"Figure 2. Analyze the output\" width=\"671\" height=\"214\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-2-4.png 1839w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-2-4-300x95.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-2-4-1024x326.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-2-4-768x244.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-2-4-600x191.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-2-4-1536x489.png 1536w\" sizes=\"(max-width: 671px) 100vw, 671px\" \/><figcaption id=\"caption-attachment-13932\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 2. Analyze the output<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Here we have an array, let&#8217;s say 0x2001ffdc, 0x2001ffde, 0x2001ffdf, like that. \u201cHello\u201d is the first element and this is msg1.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So, if you print the value of this definitely it is going to print 0x2001ffdc.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\"><span style=\"color: #ff0000;\"><strong>What if you do &amp;msg1?<\/strong><\/span>&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">&amp;msg1 is nothing but &amp;(msg1+0). Here, msg1+0 is the first element. So, that&#8217;s basically what you&#8217;re asking is the address of the first element. The address of the first element is 0x2001ffdc. That&#8217;s why, in an array, the value of the msg1 array variable or the address of the msg1 array variable is the same. So, you can see that those are the same values.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Now you can also go to the variable window, you can see that if you expand this &#8220;Hello how are you?&#8221; These characters are stored from this address onwards, as shown in Figure 3.&nbsp;<\/span><\/p>\n<figure id=\"attachment_13933\" aria-describedby=\"caption-attachment-13933\" style=\"width: 609px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-13933 \" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/02\/Figure-3-2.png\" alt=\"Figure 3. Code\" width=\"609\" height=\"270\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-3-2.png 1627w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-3-2-300x133.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-3-2-1024x454.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-3-2-768x340.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-3-2-600x266.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-3-2-1536x681.png 1536w\" sizes=\"(max-width: 609px) 100vw, 609px\" \/><figcaption id=\"caption-attachment-13933\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 3. Code<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Basically, msg1 is a local variable or a local array. It is not global data, it&#8217;s local to the main function.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400;\"><span style=\"color: #000000;\">From our earlier discussion on variables you know that local variables are transient variables. That&#8217;s why it doesn&#8217;t make any sense to store \u201cHello how are you?\u201d in the data memory permanently throughout the lifespan of a program. So, the global data will be stored in the data memory throughout the lifespan of a program.<\/span>&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">\u201cHello, how are you?\u201d data is actually transient data. That&#8217;s a reason it doesn&#8217;t make any sense to store this permanently on the data memory. That&#8217;s why this data is copied from the flash memory into this array during the runtime of the program.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Now let&#8217;s investigate that. Let\u2019s open the disassembly window and see.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s just step over and take a look at the value of the r3 register. So, that is a flash address, 0x8001354. But we know msg1 belongs to RAM. Arrays are created in the RAM.&nbsp;<\/span><\/p>\n<figure id=\"attachment_13934\" aria-describedby=\"caption-attachment-13934\" style=\"width: 642px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-13934 \" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/02\/Figure-4-2.png\" alt=\"Figure 4. Disassembly\" width=\"642\" height=\"312\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-4-2.png 1619w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-4-2-300x146.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-4-2-1024x498.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-4-2-768x373.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-4-2-600x292.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-4-2-1536x747.png 1536w\" sizes=\"(max-width: 642px) 100vw, 642px\" \/><figcaption id=\"caption-attachment-13934\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 4. Disassembly<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Now let&#8217;s open the memory browser and type 2001ffdc. Look at Figure 5, these are the memory allocations and this is where our array is created. So, these memory locations belong to our array, that is msg1.<\/span><\/p>\n<figure id=\"attachment_13936\" aria-describedby=\"caption-attachment-13936\" style=\"width: 572px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-13936\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/02\/Figure-5-1.png\" alt=\"String variable Vs string literal\" width=\"572\" height=\"299\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-5-1.png 1619w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-5-1-300x157.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-5-1-1024x536.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-5-1-768x402.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-5-1-600x314.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-5-1-1536x804.png 1536w\" sizes=\"(max-width: 572px) 100vw, 572px\" \/><figcaption id=\"caption-attachment-13936\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 5. Memory browser<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Now what happens is, these instructions will copy \u201cHello how are you?\u201d this string from flash into msg1 array. So, because when you create the binary, that string is a part of the binary, which will be stored in the flash memory.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So, you have to note one point here, this data copying is not done by the startup code, this is done during the function execution.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">But here msg1 is not global data, this is transient data or local data. That&#8217;s why data copying happens when that function is called. Here the main is called. So, that&#8217;s why it is taking place here during the runtime of the function. And once the main function exits this data(msg1) will be removed from the RAM.&nbsp; So, strictly speaking, this variable is actually created in the stack memory of the RAM.&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">If you are confused, let me explain with some diagrams.&nbsp;<\/span><\/p>\n<figure id=\"attachment_13937\" aria-describedby=\"caption-attachment-13937\" style=\"width: 633px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-13937\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/02\/Figure-6-1.png\" alt=\"String variable Vs string literal\" width=\"633\" height=\"305\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-6-1.png 1839w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-6-1-300x145.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-6-1-1024x494.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-6-1-768x370.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-6-1-600x289.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-6-1-1536x741.png 1536w\" sizes=\"(max-width: 633px) 100vw, 633px\" \/><figcaption id=\"caption-attachment-13937\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 6. Diagram<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Look at Figure 6, here we have RAM. In the microcontroller, we have RAM of 192 kilobytes(192KB).&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">There will be a start and end of RAM. 0x2000-0000 is the start of the RAM and 0x2002-FFFC is the end of the RAM.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And the RAM will be divided into a couple of sections like<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">\u2192 One section is for global data.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">\u2192 Another section for stack data. Here, the transient variables will be created and destroyed.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">\u2192 Some part of the RAM will be reserved for the heap for dynamic memory allocation. Here we don&#8217;t care about the heap because we are not using any dynamic memory allocation APIs.<\/span><span style=\"font-weight: 400;\">&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400;\">When the function is called all local variables are created in the stack, and when the program exits those memories will be reclaimed.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400;\">So, a stack will be tracked by the stack pointer(SP) register of the processor. Here there will be the start of the stack(S-stack) and the end of the stack(E-stack).<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Whenever the variables are created in the stack, the stack pointer actually decrements. And whenever variables are destroyed a stack pointer will reclaim those memory addresses. So, dynamically the stack will shrink and expand. In our case, the msg1 variable or array is a local variable. So, that&#8217;s a reason msg1 will be created in the stack.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And we know that there is also a flash memory, which is our permanent memory flash. When you load the binary into the flash, the &#8220;Hello how are you?&#8221; that string is stored in the flash memory.&nbsp;<\/span><\/p>\n<blockquote>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><b>&nbsp;<span style=\"color: #000000;\">Data copy takes place during the run-time of a function.<\/span><\/b><\/p>\n<\/blockquote>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">When the main function is called that string is copied into the msg1[] array. This is not done by the startup code. This is done during the runtime of the function.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Suppose, in the global section, there is an array called global msg1[] array, in that case, the startup code would have copied the string into a global data into the global section. That happens because control comes prior to the main. In that case, the startup code would have copied that data from flash to the global array.&nbsp; So, in our program there is no global array, this is what happens behind the scenes.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Now let me just step over and execute these instructions, and here you can see that the string is copied from flash into RAM into this array, as shown in Figure 7.&nbsp;<\/span><\/p>\n<figure id=\"attachment_13938\" aria-describedby=\"caption-attachment-13938\" style=\"width: 666px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-13938\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/02\/Figure-7.png\" alt=\"String variable Vs string literal\" width=\"666\" height=\"361\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-7.png 1623w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-7-300x163.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-7-1024x556.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-7-768x417.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-7-600x326.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-7-1536x834.png 1536w\" sizes=\"(max-width: 666px) 100vw, 666px\" \/><figcaption id=\"caption-attachment-13938\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 7. Code<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Remember that, now you have two copies of this string. Copy-1 is created in the Flash and one more copy is created in the stack or the RAM, that is copy-2. So, 2 copies are created.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">When you do msg1[0] = \u2018K\u2019; (if you assign some other value) Here you change copy-2, not copy-1. Copy-1 cannot be modified, because that is in the flash.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So, you cannot just change the contents of the flash using your pointer access. That&#8217;s not possible.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 25px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><b>String literal or string constant<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Here we are add one more string definition \u2192&nbsp; <strong>char *pmsg2 = \u201cfastbitlab.com\u201d;<\/strong>&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">After that, I&#8217;ll print msg1 and msg2. So, you can use&nbsp; <strong><span style=\"color: #000080;\">%s<\/span><\/strong>, as I said before %s needs char *, which is terminated with a null character.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Then, I&#8217;ll print the address of the pmsg2 variable, because pmsg2 is a pointer variable. So, &amp;pmsg2.&nbsp;&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Then, I\u2019ll print the value of the pmsg2 variable, I will write pmsg2.<\/span><\/p>\n<figure id=\"attachment_13939\" aria-describedby=\"caption-attachment-13939\" style=\"width: 675px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-13939\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/02\/Figure-8.png\" alt=\"String variable Vs string literal\" width=\"675\" height=\"302\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-8.png 1631w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-8-300x134.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-8-1024x458.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-8-768x343.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-8-600x268.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-8-1536x687.png 1536w\" sizes=\"(max-width: 675px) 100vw, 675px\" \/><figcaption id=\"caption-attachment-13939\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 8. Code<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s analyze what could be the result of the address of the \u2018pmsg2\u2019 variable and the value of the \u2018pmsg2\u2019 variable.&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Here(line 20), <strong>&amp;pmsg2<\/strong> is the address of *pmsg2 variable. We know that *pmsg2 is a local variable. So, the address of this variable will be in RAM. Definitely, it is going to print some RAM addresses. So, both are local variables.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">What about this string \u201dfastbitlab.com\u201d? Now, this is a string literal or a string constant that is stored in a flash. \u201cHello how are you?\u201d and \u201cfastbitlab.com\u201d both are stored in a flash. Why? Because it is part of the binary. When you create a binary it is part of the flash. So, both are living in ROM or flash.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\"><strong>char msg1[] = \u201cHello how are you?\u201d<\/strong> In this case there is a data copy.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">But, char *pmsg2 = \u201cfastbitlab.com\u201d in this case there is no data copy, just a pointer assignment. So, the pmsg2 is going to display a flash address.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s check the output. 0x2001ffd8 is a RAM address. So, 0x800130c is a flash address. So, the pmsg2 variable living in RAM points to flash(line 16). So, pmsg2 is created in the stack.&nbsp;<\/span><\/p>\n<figure id=\"attachment_13940\" aria-describedby=\"caption-attachment-13940\" style=\"width: 659px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-13940\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/02\/Figure-9.png\" alt=\"String variable Vs string literal\" width=\"659\" height=\"331\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-9.png 1833w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-9-300x151.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-9-1024x515.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-9-768x386.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-9-600x301.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-9-1536x772.png 1536w\" sizes=\"(max-width: 659px) 100vw, 659px\" \/><figcaption id=\"caption-attachment-13940\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 9. Diagram<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Here pmsg2 is created in stack and string is created in stack flash. But pmsg2 is created in the stack and pointing to flash. So, that&#8217;s a reason you can&#8217;t do pmsg2[0] = \u2018k\u2019; (you can\u2019t assign some other value). Because pmsg2 is pointing to flash.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">You cannot change the flash contents like this. It&#8217;s not allowed. Even if you do this it does not affect the microcontroller. Because, we write access to the flash will be detained or it will be blocked by the flash controller unless you give some special instructions to the flash controller like you have to insert some password and all, and you have to unlock write access to the flash, then only you can do this technique to write into the flash. Otherwise, simply you cannot modify the flash content by taking its address.&nbsp; The flash controller will not allow you to do that. So, this does not affect the microcontroller.&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400;\"><span style=\"color: #000000;\">But the same code, if you try it on your host computer, then may lead to an unexpected result, and your application may even crash.&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Here we add <strong>msg1[0] = \u2018b\u2019;<\/strong> \/\/Replace &#8216;h&#8217; by&nbsp; &#8216;b&#8217;.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And I do the same thing for the pointer also.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><strong><span style=\"color: #000000;\">pmsg2[0] = \u2018b\u2019;&nbsp;<\/span><\/strong><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s check this code. Here, the compiler didn&#8217;t issue any errors. The compiler has no problem with this code, even though this code is wrong. The compiler actually ignored this, so the compiler basically won&#8217;t throw any warning or error on this (line 19).<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<figure id=\"attachment_13942\" aria-describedby=\"caption-attachment-13942\" style=\"width: 641px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-13942\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/02\/Figure-10.png\" alt=\"String variable Vs string literal\" width=\"641\" height=\"308\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-10.png 1631w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-10-300x144.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-10-1024x492.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-10-768x369.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-10-600x288.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-10-1536x737.png 1536w\" sizes=\"(max-width: 641px) 100vw, 641px\" \/><figcaption id=\"caption-attachment-13942\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 10. Code<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So, <strong>pmsg2[0]= \u2018b\u2019<\/strong> is the wrong code. So, you should not be doing something like this. Because you are trying to modify read-only memory.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">That&#8217;s why, why should you maintain the *pmsg2 variable definition as a constant data definition. The best way to write this string definition is char const(as shown in Figure 11, line 16).&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">This is a valid or more suitable string definition for a string literal or a string constant.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px;\">&nbsp;<\/p>\n<figure id=\"attachment_13943\" aria-describedby=\"caption-attachment-13943\" style=\"width: 696px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-13943\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/02\/Figure-11.png\" alt=\"String variable Vs string literal\" width=\"696\" height=\"388\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-11.png 1555w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-11-300x167.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-11-1024x571.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-11-768x428.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-11-600x335.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-11-1536x856.png 1536w\" sizes=\"(max-width: 696px) 100vw, 696px\" \/><figcaption id=\"caption-attachment-13943\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 11. Code<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Now, if you try to execute this there is an error. Here we can see that there is an error. So, the compiler will not allow you to do something like this.&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">For a time being let&#8217;s remove the const and let&#8217;s try once again.<\/span><\/p>\n<figure id=\"attachment_13944\" aria-describedby=\"caption-attachment-13944\" style=\"width: 615px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-13944\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/02\/Figure-12.png\" alt=\"String variable Vs string literal\" width=\"615\" height=\"268\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-12.png 1627w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-12-300x131.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-12-1024x446.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-12-768x335.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-12-600x261.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-12-1536x669.png 1536w\" sizes=\"(max-width: 615px) 100vw, 615px\" \/><figcaption id=\"caption-attachment-13944\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 12. Code<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">You can see that &#8216;h&#8217; is replaced by &#8216;b&#8217;, but \u201cfastbitlab.com\u201d this string is not modified. So, it has no effect.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">That&#8217;s about the difference between a string variable and a string constant or a string literal. So, don&#8217;t forget to use const here, that&#8217;s a good practice.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Now let&#8217;s execute the same program on our host and let&#8217;s see how the host responds to this program. So, let&#8217;s run.<\/span><\/p>\n<figure id=\"attachment_13945\" aria-describedby=\"caption-attachment-13945\" style=\"width: 653px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-13945\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/02\/Figure-13.png\" alt=\"String variable Vs string literal\" width=\"653\" height=\"366\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-13.png 1523w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-13-300x168.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-13-1024x574.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-13-768x430.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-13-600x336.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-13-800x450.png 800w\" sizes=\"(max-width: 653px) 100vw, 653px\" \/><figcaption id=\"caption-attachment-13945\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 13. Code<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Here we can see that \u201cH&#8221; is replaced by \u201cb\u201d. <strong>pmsg2[0] =\u2019b\u2019<\/strong> this line is disabled, That\u2019s ok.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400;\"><span style=\"color: #000000;\">And then 0061FF08 is the RAM address. There is a difference between 0061FF08 and 00405044. So, 00405044 belongs to the read-only section or read-only memory. So, this is happening on the computer.<\/span>&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Enable <strong>pmsg2[0] = \u2018b\u2019;<\/strong> and let&#8217;s see what happens. Here we are trying to change the content of the read-only memory location. Let&#8217;s see how this program behaves on the host.&nbsp;<\/span><\/p>\n<figure id=\"attachment_13946\" aria-describedby=\"caption-attachment-13946\" style=\"width: 679px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-13946\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/02\/Figure-14.png\" alt=\"String variable Vs string literal\" width=\"679\" height=\"336\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-14.png 1521w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-14-300x149.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-14-1024x507.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-14-768x380.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-14-600x297.png 600w\" sizes=\"(max-width: 679px) 100vw, 679px\" \/><figcaption id=\"caption-attachment-13946\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 14. Code<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let\u2019s run the program. And here you can see that the application crashes, as shown in Figure 14.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Because the operating system detected that you are trying to change the content of the read-only section and that&#8217;s the reason the operating system terminated your executable.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">We saw that on the microcontroller it has no effect. That&#8217;s a reason if you have some string definition, then always you should maintain the data as constant. So, if anyone tries to modify that you can see that the compiler throws an error. <\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 20px; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; line-height: 31px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><b>FastBit Embedded Brain Academy Courses<\/b><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; border-width: 0px;\"><span style=\"color: #000000;\">C<span style=\"font-weight: 400;\"><span style=\"color: #000000;\">lick here:<\/span><span style=\"color: #0000ff;\">&nbsp;<\/span><\/span><\/span><span style=\"color: #0000ff;\"><a style=\"color: #0000ff; text-decoration: underline;\" href=\"http:\/\/fastbitlab.com\/course1\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/fastbitlab.com\/course1<\/span><\/a><\/span><\/p>\n<h2 class=\"\">&nbsp;<\/h2>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; String variable Vs string literal &nbsp; A string literal is a sequence of characters that are directly written in the code, while a string variable is a named memory location that stores a reference to a string value that can be changed during runtime. &nbsp; String Variable &nbsp; Here, the first printf is to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":13932,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"off","ocean_gallery_id":[],"footnotes":""},"categories":[8],"tags":[16],"class_list":["post-13928","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-microcontroller-embedded-c-programming","entry","has-media"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>String variable Vs string literal | FastBit EBA<\/title>\n<meta name=\"description\" content=\"String variable Vs string literal. A string literal is a sequence of characters that are directly written in the code, while a string\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"String variable Vs string literal | FastBit EBA\" \/>\n<meta property=\"og:description\" content=\"String variable Vs string literal. A string literal is a sequence of characters that are directly written in the code, while a string\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\/\" \/>\n<meta property=\"og:site_name\" content=\"FastBit EBA\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/fastbiteba\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-02-11T09:19:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-2-4.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1839\" \/>\n\t<meta property=\"og:image:height\" content=\"585\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"FastBitLab\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:site\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"FastBitLab\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\\\/\"},\"author\":{\"name\":\"FastBitLab\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\"},\"headline\":\"Microcontroller Embedded C Programming lecture 177| String variable Vs string literal\",\"datePublished\":\"2023-02-11T09:19:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\\\/\"},\"wordCount\":2280,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/Figure-2-4.png\",\"keywords\":[\"Microcontroller Embedded C programming Lectures\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\\\/\",\"name\":\"String variable Vs string literal | FastBit EBA\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/Figure-2-4.png\",\"datePublished\":\"2023-02-11T09:19:06+00:00\",\"description\":\"String variable Vs string literal. A string literal is a sequence of characters that are directly written in the code, while a string\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\\\/#primaryimage\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/Figure-2-4.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/Figure-2-4.png\",\"width\":1839,\"height\":585,\"caption\":\"Figure 2. Analyze the output\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Microcontroller Embedded C Programming lecture 177| String variable Vs string literal\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"name\":\"FastBit EBA\",\"description\":\"Your Online Academy of Embedded Systems\",\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\",\"name\":\"FastBit EBA\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"width\":640,\"height\":640,\"caption\":\"FastBit EBA\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/fastbiteba\\\/\",\"https:\\\/\\\/x.com\\\/fastbiteba\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/fastbit-embedded-brain-academy-b3167b124\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCa1REBV9hyrzGp2mjJCagBg\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\",\"name\":\"FastBitLab\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"caption\":\"FastBitLab\"},\"description\":\"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"String variable Vs string literal | FastBit EBA","description":"String variable Vs string literal. A string literal is a sequence of characters that are directly written in the code, while a string","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\/","og_locale":"en_US","og_type":"article","og_title":"String variable Vs string literal | FastBit EBA","og_description":"String variable Vs string literal. A string literal is a sequence of characters that are directly written in the code, while a string","og_url":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\/","og_site_name":"FastBit EBA","article_publisher":"https:\/\/www.facebook.com\/fastbiteba\/","article_published_time":"2023-02-11T09:19:06+00:00","og_image":[{"width":1839,"height":585,"url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-2-4.png","type":"image\/png"}],"author":"FastBitLab","twitter_card":"summary_large_image","twitter_creator":"@fastbiteba","twitter_site":"@fastbiteba","twitter_misc":{"Written by":"FastBitLab","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\/#article","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\/"},"author":{"name":"FastBitLab","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d"},"headline":"Microcontroller Embedded C Programming lecture 177| String variable Vs string literal","datePublished":"2023-02-11T09:19:06+00:00","mainEntityOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\/"},"wordCount":2280,"commentCount":0,"publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-2-4.png","keywords":["Microcontroller Embedded C programming Lectures"],"articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\/","url":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\/","name":"String variable Vs string literal | FastBit EBA","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\/#primaryimage"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-2-4.png","datePublished":"2023-02-11T09:19:06+00:00","description":"String variable Vs string literal. A string literal is a sequence of characters that are directly written in the code, while a string","breadcrumb":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\/#primaryimage","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-2-4.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-2-4.png","width":1839,"height":585,"caption":"Figure 2. Analyze the output"},{"@type":"BreadcrumbList","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-177-string-variable-vs-string-literal\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fastbitlab.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Microcontroller Embedded C Programming lecture 177| String variable Vs string literal"}]},{"@type":"WebSite","@id":"https:\/\/fastbitlab.com\/blog\/#website","url":"https:\/\/fastbitlab.com\/blog\/","name":"FastBit EBA","description":"Your Online Academy of Embedded Systems","publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fastbitlab.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fastbitlab.com\/blog\/#organization","name":"FastBit EBA","url":"https:\/\/fastbitlab.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","width":640,"height":640,"caption":"FastBit EBA"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/fastbiteba\/","https:\/\/x.com\/fastbiteba","https:\/\/www.linkedin.com\/in\/fastbit-embedded-brain-academy-b3167b124\/","https:\/\/www.youtube.com\/channel\/UCa1REBV9hyrzGp2mjJCagBg"]},{"@type":"Person","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d","name":"FastBitLab","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","caption":"FastBitLab"},"description":"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries."}]}},"_links":{"self":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/13928","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/comments?post=13928"}],"version-history":[{"count":5,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/13928\/revisions"}],"predecessor-version":[{"id":13955,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/13928\/revisions\/13955"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media\/13932"}],"wp:attachment":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media?parent=13928"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/categories?post=13928"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/tags?post=13928"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}