{"id":2933,"date":"2018-11-26T11:01:30","date_gmt":"2018-11-26T05:31:30","guid":{"rendered":"http:\/\/www.csestack.org\/?p=2933"},"modified":"2024-05-16T14:18:47","modified_gmt":"2024-05-16T08:48:47","slug":"difference-between-strlen-sizeof-c-cpp-code","status":"publish","type":"post","link":"https:\/\/www.csestack.org\/difference-between-strlen-sizeof-c-cpp-code\/","title":{"rendered":"Difference Between strlen and sizeof in C [Code Explained in Detail]"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69fd5a134d8c1\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #000000;color:#000000\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #000000;color:#000000\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69fd5a134d8c1\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.csestack.org\/difference-between-strlen-sizeof-c-cpp-code\/#strlen_in_C\" >strlen() in C<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.csestack.org\/difference-between-strlen-sizeof-c-cpp-code\/#sizeof_in_C\" >sizeof() in C<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.csestack.org\/difference-between-strlen-sizeof-c-cpp-code\/#How_to_find_the_length_of_the_string_using_sizeof_operator_in_C\" >How to find the length of the string using sizeof() operator in C?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.csestack.org\/difference-between-strlen-sizeof-c-cpp-code\/#How_to_find_number_of_elements_in_the_array_using_sizeof_Operator\" >How to find number of elements in the array using sizeof Operator()?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.csestack.org\/difference-between-strlen-sizeof-c-cpp-code\/#Why_is_the_size_of_the_string_one_higher_than_the_length_of_the_same_string\" >Why is the size of the string one higher than the length of the same string?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.csestack.org\/difference-between-strlen-sizeof-c-cpp-code\/#strlen_Vs_sizeof\" >strlen() Vs sizeof()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.csestack.org\/difference-between-strlen-sizeof-c-cpp-code\/#Difference_Between_strlen_and_sizeof_in_C_Programming\" >Difference Between strlen and sizeof in C Programming:<\/a><\/li><\/ul><\/nav><\/div>\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"strlen_in_C\"><\/span>strlen() in C<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>The <code>strlen()<\/code> is a predefined function in C programming languages. It returns the number of characters in the string. When we pass the pointer of the string to the function, it goes through the complete string, until it finds the NULL-terminated character.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It counts all the characters present in the string.<\/li>\n\n\n\n<li>This function is defined in the string.h header file.<\/li>\n\n\n\n<li>You need to include <code>string.h<\/code> header file before using this function in your C code.<\/li>\n<\/ul>\n\n\n\n<p><strong>Example Code for strlen():<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &lt;stdio.h&gt;\n#include &lt;string.h&gt;\nint main()\n{\n  char str1[] = &quot;CSEstack Programming&quot;;\n  printf(&quot;Length of string is %d.&quot;, strlen(str1));\n  return 0;\n}<\/pre><\/div>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Length of string is 20.<\/pre>\n\n\n\n<p>From the above output of the program, you can see, the function also counts the space and other special characters in the string.<\/p>\n\n\n\n<p><strong>Use:<\/strong> The <code>strlen()<\/code> function is very useful for solving many of the coding questions. For example: check if the two given strings are anagram, where you have to find the length of both strings. If the two strings have different lengths, they can not be anagrams.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"sizeof\"><span class=\"ez-toc-section\" id=\"sizeof_in_C\"><\/span>sizeof() in C<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>The <code>sizeof()<\/code> is one of the most useful operators in C programming. As it takes one input operand, it is the unary operator.<\/p>\n\n\n\n<p>There are <a href=\"https:\/\/www.csestack.org\/basic-derived-user-defined-data-types-c-explained-example\/\">different data types in C programming<\/a>. You can pass any data type object as an operand including primitive types (such as <code>int<\/code>, <code>float<\/code>, <code>char<\/code>&#8230;) and compound types objects (such as structure, union)<\/p>\n\n\n\n<p><strong>Return Type:<\/strong> <code>sizeof()<\/code> returns the total size assigned to the given operand. The output data type is represented as <code>size_t<\/code>.<\/p>\n\n\n\n<p>If we run the same program as above to print the size of the same\u00a0string, here is an output.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &lt;stdio.h&gt;\nint main()\n{\n  char str1[] = &quot;CSEstack Programming&quot;;\n  printf(&quot;Size string is %d.&quot;, sizeof(str1));\n  return 0;\n}<\/pre><\/div>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Size of string is 21.<\/pre>\n\n\n\n<p><strong>Note:<\/strong> Here we are considering the size of the character is one byte. It can be different based on the system and compiler designing.<\/p>\n\n\n\n<p>You can also pass the data type to the <code>sizeof<\/code> operator.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &lt;stdio.h&gt;\nint main()\n{\n  printf(&quot;Size of integere is %d.&quot;, sizeof(int));\n  printf(&quot;Size of float is %d.&quot;, sizeof(float));\n  printf(&quot;Size of character is %d.&quot;, sizeof(char));\n  return 0;\n}<\/pre><\/div>\n\n\n\n<p>Remember, the output of the above program may be different based on the system and compiler that you are using.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"string-length\"><span class=\"ez-toc-section\" id=\"How_to_find_the_length_of_the_string_using_sizeof_operator_in_C\"><\/span>How to find the length of the string using sizeof() operator in C?<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>If you are not sure about the size of the character, you can divide the size of the string\u00a0(or array) by the character. You will\u00a0get the length of the string.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &lt;stdio.h&gt;\n#include &lt;string.h&gt;\nint main()\n{\n  char str1[] = &quot;CSEstack Programming&quot;;\n  printf(&quot;Size of string is %d.&quot;, sizeof(str1)\/sizeof(char));\n  return 0;\n}<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"array-size\"><span class=\"ez-toc-section\" id=\"How_to_find_number_of_elements_in_the_array_using_sizeof_Operator\"><\/span>How to find number of elements in the array using sizeof Operator()?<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>In the case of an integer\u00a0array, you need to divide the size of the array by the size of integer to get the number of elements in the array.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &lt;stdio.h&gt;\n#include &lt;string.h&gt;\nint main()\n{\n  char arr[] = [24,5,6,7,3,54,7];\n  printf(&quot;Number of elements in the array:&quot;, sizeof(arr)\/sizeof(int));\n  return 0;\n}<\/pre><\/div>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Number of elements on the array: 7<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"compare\"><span class=\"ez-toc-section\" id=\"Why_is_the_size_of_the_string_one_higher_than_the_length_of_the_same_string\"><\/span>Why is the size of the string one higher than the length of the same string?<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>When you declare a string, &#8216;\\0&#8217; NULL-terminated character will be added as the last character as a delimiter to represent the end of the string.<\/p>\n\n\n\n<p><strong>Comparing strlen and sizeof:<\/strong><\/p>\n\n\n\n<p>Function\u00a0<code>strlen()<\/code> represents the number of characters in the string excluding delimiter\u00a0<code>'\\0'<\/code>. Whereas, operator <code>sizeof()<\/code> returns the memory size allocated to save the string. It also counts the memory size required to save the character &#8216;<code>\\0'<\/code>.<\/p>\n\n\n\n<p>For an empty string, the length of the string is zero but the size of the string is one.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &lt;stdio.h&gt;\n#include &lt;string.h&gt;\nint main()\n{\n  char str1[] = &quot;&quot;;\n  printf(&quot;Length of the string is %d.&quot;, strlen(str1));\n  printf(&quot;\\nSize of the string is %d.&quot;, sizeof(str1));\n  return 0;\n}<\/pre><\/div>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Length of the string is 0.<br>Size of the string is 1.<\/pre>\n\n\n\n<p>So, the size of the string will be one higher than the length of the string.<\/p>\n\n\n\n<p><strong>Usage of sizeof() Operator in C Programming:<\/strong><\/p>\n\n\n\n<p>The <code>sizeof()<\/code> operator is mostly used for memory management calls like <code>malloc()<\/code>, <code>memset()<\/code>, <code>memcpy()<\/code>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"strlen_Vs_sizeof\"><\/span>strlen() Vs sizeof()<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>Let&#8217;s compare these two built-in functions in C programming.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"difference\"><span class=\"ez-toc-section\" id=\"Difference_Between_strlen_and_sizeof_in_C_Programming\"><\/span>Difference Between strlen and sizeof in C Programming:<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Function\/Operation\/Evaluation:<\/strong><br>The <code>strlen()<\/code> returns the length of the string stored in the array, however, <code>sizeof()<\/code> returns the total allocated size assigned to the array.<\/li>\n\n\n\n<li><strong>Difference in Return Value:<\/strong><br>If you pass the same string as the input to both functions <code>strlen()<\/code> and <code>sizeof()<\/code>, the size of the string will be one higher than the length of the string. (Considering the size of the character in one byte.)<\/li>\n\n\n\n<li><strong>Dependency:<\/strong><br>The size of the string also depends on your system and the design of your C compiler.<\/li>\n\n\n\n<li><strong>Data Type Support:<\/strong><br>Unlike <code>strlen()<\/code>, we can use the\u00a0function\u00a0<code>sizeof()<\/code> with any datatypes.<\/li>\n\n\n\n<li><strong>Return Type:<\/strong><br>The return type of the <code>strlen()<\/code> is the integer, whereas the return type of the <code>sizeof()<\/code> operator is <code>size_t<\/code>.<\/li>\n<\/ul>\n\n\n\n<p>This is all about the difference between <code>strlen()<\/code> and <code>sizeof()<\/code> in C \/ C++ programming. If you have any queries, let&#8217;s discuss this in the comment section.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is the main difference between strlen and sizeof C and CPP programming? Explain the code for string length and array size with examples.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,7],"tags":[339,340],"class_list":["post-2933","post","type-post","status-publish","format-standard","hentry","category-c-cpp","category-code","tag-sizeof","tag-strlen"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Difference Between strlen and sizeof in C [Code Explained in Detail]<\/title>\n<meta name=\"description\" content=\"What is the main difference between strlen and sizeof C and CPP programming? Explain the code for string length and array size with examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.csestack.org\/difference-between-strlen-sizeof-c-cpp-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Difference Between strlen and sizeof in C [Code Explained in Detail]\" \/>\n<meta property=\"og:description\" content=\"What is the main difference between strlen and sizeof C and CPP programming? Explain the code for string length and array size with examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.csestack.org\/difference-between-strlen-sizeof-c-cpp-code\/\" \/>\n<meta property=\"og:site_name\" content=\"CSEstack\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/aniruddha.ca\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/aniruddha.ca\" \/>\n<meta property=\"article:published_time\" content=\"2018-11-26T05:31:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-16T08:48:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.csestack.org\/wp-content\/uploads\/2024\/01\/csestack-blog.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Aniruddha Chaudhari\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ani_chaudhari\" \/>\n<meta name=\"twitter:site\" content=\"@ani_chaudhari\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Aniruddha Chaudhari\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.csestack.org\\\/difference-between-strlen-sizeof-c-cpp-code\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.csestack.org\\\/difference-between-strlen-sizeof-c-cpp-code\\\/\"},\"author\":{\"name\":\"Aniruddha Chaudhari\",\"@id\":\"https:\\\/\\\/www.csestack.org\\\/#\\\/schema\\\/person\\\/634ef1a9c4f38b0d340c6d45fa771218\"},\"headline\":\"Difference Between strlen and sizeof in C [Code Explained in Detail]\",\"datePublished\":\"2018-11-26T05:31:30+00:00\",\"dateModified\":\"2024-05-16T08:48:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.csestack.org\\\/difference-between-strlen-sizeof-c-cpp-code\\\/\"},\"wordCount\":687,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/www.csestack.org\\\/#\\\/schema\\\/person\\\/634ef1a9c4f38b0d340c6d45fa771218\"},\"keywords\":[\"sizeof\",\"strlen\"],\"articleSection\":[\"C \\\/ C++\",\"Code\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.csestack.org\\\/difference-between-strlen-sizeof-c-cpp-code\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.csestack.org\\\/difference-between-strlen-sizeof-c-cpp-code\\\/\",\"url\":\"https:\\\/\\\/www.csestack.org\\\/difference-between-strlen-sizeof-c-cpp-code\\\/\",\"name\":\"Difference Between strlen and sizeof in C [Code Explained in Detail]\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.csestack.org\\\/#website\"},\"datePublished\":\"2018-11-26T05:31:30+00:00\",\"dateModified\":\"2024-05-16T08:48:47+00:00\",\"description\":\"What is the main difference between strlen and sizeof C and CPP programming? Explain the code for string length and array size with examples.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.csestack.org\\\/difference-between-strlen-sizeof-c-cpp-code\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.csestack.org\\\/difference-between-strlen-sizeof-c-cpp-code\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.csestack.org\\\/difference-between-strlen-sizeof-c-cpp-code\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.csestack.org\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Difference Between strlen and sizeof in C [Code Explained in Detail]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.csestack.org\\\/#website\",\"url\":\"https:\\\/\\\/www.csestack.org\\\/\",\"name\":\"CSEstack\",\"description\":\"Computer Science &amp; Programming Portal\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.csestack.org\\\/#\\\/schema\\\/person\\\/634ef1a9c4f38b0d340c6d45fa771218\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.csestack.org\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.csestack.org\\\/#\\\/schema\\\/person\\\/634ef1a9c4f38b0d340c6d45fa771218\",\"name\":\"Aniruddha Chaudhari\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.csestack.org\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/Aniruddha-Chaudhari.jpg\",\"url\":\"https:\\\/\\\/www.csestack.org\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/Aniruddha-Chaudhari.jpg\",\"contentUrl\":\"https:\\\/\\\/www.csestack.org\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/Aniruddha-Chaudhari.jpg\",\"width\":634,\"height\":634,\"caption\":\"Aniruddha Chaudhari\"},\"logo\":{\"@id\":\"https:\\\/\\\/www.csestack.org\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/Aniruddha-Chaudhari.jpg\"},\"description\":\"I am a Python enthusiast who loves Linux and Vim. I hold a Master of Computer Science degree from NIT Trichy and have 10 years of experience in the IT industry, focusing on the Software Development Lifecycle from Requirements Gathering, Design, Development to Deployment. I have worked at IBM, Ericsson, and NetApp, and I share my knowledge on CSEstack.org.\",\"sameAs\":[\"https:\\\/\\\/www.csestack.org\",\"https:\\\/\\\/www.facebook.com\\\/aniruddha.ca\",\"pythonwithani\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/aniruddha28\\\/\",\"https:\\\/\\\/x.com\\\/ani_chaudhari\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCw0a__B0eJsvCujkSIfLTAA\"],\"url\":\"https:\\\/\\\/www.csestack.org\\\/author\\\/anicse\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Difference Between strlen and sizeof in C [Code Explained in Detail]","description":"What is the main difference between strlen and sizeof C and CPP programming? Explain the code for string length and array size with examples.","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:\/\/www.csestack.org\/difference-between-strlen-sizeof-c-cpp-code\/","og_locale":"en_US","og_type":"article","og_title":"Difference Between strlen and sizeof in C [Code Explained in Detail]","og_description":"What is the main difference between strlen and sizeof C and CPP programming? Explain the code for string length and array size with examples.","og_url":"https:\/\/www.csestack.org\/difference-between-strlen-sizeof-c-cpp-code\/","og_site_name":"CSEstack","article_publisher":"https:\/\/www.facebook.com\/aniruddha.ca","article_author":"https:\/\/www.facebook.com\/aniruddha.ca","article_published_time":"2018-11-26T05:31:30+00:00","article_modified_time":"2024-05-16T08:48:47+00:00","og_image":[{"width":1280,"height":720,"url":"https:\/\/www.csestack.org\/wp-content\/uploads\/2024\/01\/csestack-blog.jpg","type":"image\/jpeg"}],"author":"Aniruddha Chaudhari","twitter_card":"summary_large_image","twitter_creator":"@ani_chaudhari","twitter_site":"@ani_chaudhari","twitter_misc":{"Written by":"Aniruddha Chaudhari","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.csestack.org\/difference-between-strlen-sizeof-c-cpp-code\/#article","isPartOf":{"@id":"https:\/\/www.csestack.org\/difference-between-strlen-sizeof-c-cpp-code\/"},"author":{"name":"Aniruddha Chaudhari","@id":"https:\/\/www.csestack.org\/#\/schema\/person\/634ef1a9c4f38b0d340c6d45fa771218"},"headline":"Difference Between strlen and sizeof in C [Code Explained in Detail]","datePublished":"2018-11-26T05:31:30+00:00","dateModified":"2024-05-16T08:48:47+00:00","mainEntityOfPage":{"@id":"https:\/\/www.csestack.org\/difference-between-strlen-sizeof-c-cpp-code\/"},"wordCount":687,"commentCount":2,"publisher":{"@id":"https:\/\/www.csestack.org\/#\/schema\/person\/634ef1a9c4f38b0d340c6d45fa771218"},"keywords":["sizeof","strlen"],"articleSection":["C \/ C++","Code"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.csestack.org\/difference-between-strlen-sizeof-c-cpp-code\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.csestack.org\/difference-between-strlen-sizeof-c-cpp-code\/","url":"https:\/\/www.csestack.org\/difference-between-strlen-sizeof-c-cpp-code\/","name":"Difference Between strlen and sizeof in C [Code Explained in Detail]","isPartOf":{"@id":"https:\/\/www.csestack.org\/#website"},"datePublished":"2018-11-26T05:31:30+00:00","dateModified":"2024-05-16T08:48:47+00:00","description":"What is the main difference between strlen and sizeof C and CPP programming? Explain the code for string length and array size with examples.","breadcrumb":{"@id":"https:\/\/www.csestack.org\/difference-between-strlen-sizeof-c-cpp-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.csestack.org\/difference-between-strlen-sizeof-c-cpp-code\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.csestack.org\/difference-between-strlen-sizeof-c-cpp-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.csestack.org\/"},{"@type":"ListItem","position":2,"name":"Difference Between strlen and sizeof in C [Code Explained in Detail]"}]},{"@type":"WebSite","@id":"https:\/\/www.csestack.org\/#website","url":"https:\/\/www.csestack.org\/","name":"CSEstack","description":"Computer Science &amp; Programming Portal","publisher":{"@id":"https:\/\/www.csestack.org\/#\/schema\/person\/634ef1a9c4f38b0d340c6d45fa771218"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.csestack.org\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.csestack.org\/#\/schema\/person\/634ef1a9c4f38b0d340c6d45fa771218","name":"Aniruddha Chaudhari","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Aniruddha-Chaudhari.jpg","url":"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Aniruddha-Chaudhari.jpg","contentUrl":"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Aniruddha-Chaudhari.jpg","width":634,"height":634,"caption":"Aniruddha Chaudhari"},"logo":{"@id":"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Aniruddha-Chaudhari.jpg"},"description":"I am a Python enthusiast who loves Linux and Vim. I hold a Master of Computer Science degree from NIT Trichy and have 10 years of experience in the IT industry, focusing on the Software Development Lifecycle from Requirements Gathering, Design, Development to Deployment. I have worked at IBM, Ericsson, and NetApp, and I share my knowledge on CSEstack.org.","sameAs":["https:\/\/www.csestack.org","https:\/\/www.facebook.com\/aniruddha.ca","pythonwithani","https:\/\/www.linkedin.com\/in\/aniruddha28\/","https:\/\/x.com\/ani_chaudhari","https:\/\/www.youtube.com\/channel\/UCw0a__B0eJsvCujkSIfLTAA"],"url":"https:\/\/www.csestack.org\/author\/anicse\/"}]}},"_links":{"self":[{"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/posts\/2933","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/comments?post=2933"}],"version-history":[{"count":17,"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/posts\/2933\/revisions"}],"predecessor-version":[{"id":11362,"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/posts\/2933\/revisions\/11362"}],"wp:attachment":[{"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/media?parent=2933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/categories?post=2933"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/tags?post=2933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}