{"id":15967,"date":"2022-10-13T18:05:26","date_gmt":"2022-10-13T12:35:26","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-pointer-c-language-closed\/"},"modified":"2022-10-13T18:05:26","modified_gmt":"2022-10-13T12:35:26","slug":"solved-pointer-c-language-closed","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-pointer-c-language-closed\/","title":{"rendered":"[Solved] Pointer C Language [closed]"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-64614666\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"64614666\" data-parentid=\"64614443\" data-score=\"0\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<blockquote>\n<p>What does this function do?<\/p>\n<\/blockquote>\n<p>It concatenates two strings, i.e. it&#8217;s doing the same as the standard <code>strcat<\/code> function. See <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/man7.org\/linux\/man-pages\/man3\/strcat.3.html\">https:\/\/man7.org\/linux\/man-pages\/man3\/strcat.3.html<\/a><\/p>\n<p>Assume the input is &#8220;Hello World&#8221;.<\/p>\n<p>Just when the function is called, some where in memory it looks like:<\/p>\n<pre><code>String1: Hello\\0\n         ^\n         |\n         s1\n\nString2: World\\0\n         ^\n         |\n         s2\n<\/code><\/pre>\n<p>Now this part<\/p>\n<pre><code>while (*s1 != '\\0') {\n  ++s1;\n} \n<\/code><\/pre>\n<p>Moves the pointer <code>s1<\/code> to the end of <code>String1<\/code>. So you have<\/p>\n<pre><code>String1: Hello\\0\n               ^\n               |\n               s1\n\nString2: World\\0\n         ^\n         |\n         s2\n<\/code><\/pre>\n<p>Then this part<\/p>\n<pre><code>for (; *s1 = *s2; ++s1, ++s2) {\n  ; \/\/ empty statement\n} \n<\/code><\/pre>\n<p>copies characters from <code>String2<\/code> (using <code>s2<\/code>) to the end of <code>String1<\/code> (using <code>s1<\/code>).<\/p>\n<p>After one loop, you&#8217;ll have:<\/p>\n<pre><code>String1: HelloWorldW\n                    ^\n                    |\n                    s1\n\nString2: World\\0\n          ^\n          |\n          s2\n<\/code><\/pre>\n<p>After one more loop, you&#8217;ll have:<\/p>\n<pre><code>String1: HelloWorldWo\n                     ^\n                     |\n                     s1\n\nString2: World\\0\n           ^\n           |\n           s2\n<\/code><\/pre>\n<p>and so on.<\/p>\n<p>In the end you&#8217;ll have<\/p>\n<pre><code>String1: HelloWorld\\0\n                     ^\n                     |\n                     s1\n\nString2: World\\0\n                ^\n                |\n                s2\n<\/code><\/pre>\n<p>Net result: <code>String2<\/code> was concatenated to <code>String1<\/code><\/p>\n<p>A few more words about <code>for (; *s1 = *s2; ++s1, ++s2) {<\/code><\/p>\n<pre><code>The ; says: no initialization needed\n\nThe *s1 = *s2; says: Copy the char that s2 points to to the memory that s1 points to. \nFurther, it serves as \"end-of-loop\" condition, i.e. the loop will end when a \\0 has \nbeen copied\n\nThe ++s1, ++s2 says: Increment both pointers\n<\/code><\/pre>\n<p>In this way characters from <code>String2<\/code> are one-by-one copied to the end of <code>String1<\/code><\/p>\n<p>BTW: Notice that the <code>main<\/code> function is unsafe as too little memory is reserved for <code>String1<\/code><\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">0<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Pointer C Language [closed] <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] What does this function do? It concatenates two strings, i.e. it&#8217;s doing the same as the standard strcat function. See https:\/\/man7.org\/linux\/man-pages\/man3\/strcat.3.html Assume the input is &#8220;Hello World&#8221;. Just when the function is called, some where in memory it looks like: String1: Hello\\0 ^ | s1 String2: World\\0 ^ | s2 Now this part while &#8230; <a title=\"[Solved] Pointer C Language [closed]\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-pointer-c-language-closed\/\" aria-label=\"More on [Solved] Pointer C Language [closed]\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[324,712],"class_list":["post-15967","post","type-post","status-publish","format-standard","hentry","category-solved","tag-c","tag-pointers"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Pointer C Language [closed] - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-pointer-c-language-closed\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Pointer C Language [closed] - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] What does this function do? It concatenates two strings, i.e. it&#8217;s doing the same as the standard strcat function. See https:\/\/man7.org\/linux\/man-pages\/man3\/strcat.3.html Assume the input is &#8220;Hello World&#8221;. Just when the function is called, some where in memory it looks like: String1: Hello ^ | s1 String2: World ^ | s2 Now this part while ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-pointer-c-language-closed\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-13T12:35:26+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-pointer-c-language-closed\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-pointer-c-language-closed\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Pointer C Language [closed]\",\"datePublished\":\"2022-10-13T12:35:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-pointer-c-language-closed\/\"},\"wordCount\":143,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"c++\",\"pointers\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-pointer-c-language-closed\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-pointer-c-language-closed\/\",\"name\":\"[Solved] Pointer C Language [closed] - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-10-13T12:35:26+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-pointer-c-language-closed\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-pointer-c-language-closed\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-pointer-c-language-closed\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Pointer C Language [closed]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Pointer C Language [closed] - JassWeb","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:\/\/jassweb.com\/solved\/solved-pointer-c-language-closed\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Pointer C Language [closed] - JassWeb","og_description":"[ad_1] What does this function do? It concatenates two strings, i.e. it&#8217;s doing the same as the standard strcat function. See https:\/\/man7.org\/linux\/man-pages\/man3\/strcat.3.html Assume the input is &#8220;Hello World&#8221;. Just when the function is called, some where in memory it looks like: String1: Hello ^ | s1 String2: World ^ | s2 Now this part while ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-pointer-c-language-closed\/","og_site_name":"JassWeb","article_published_time":"2022-10-13T12:35:26+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-pointer-c-language-closed\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-pointer-c-language-closed\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Pointer C Language [closed]","datePublished":"2022-10-13T12:35:26+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-pointer-c-language-closed\/"},"wordCount":143,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["c++","pointers"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-pointer-c-language-closed\/","url":"https:\/\/jassweb.com\/solved\/solved-pointer-c-language-closed\/","name":"[Solved] Pointer C Language [closed] - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-10-13T12:35:26+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-pointer-c-language-closed\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-pointer-c-language-closed\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-pointer-c-language-closed\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Pointer C Language [closed]"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/15967","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=15967"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/15967\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=15967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=15967"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=15967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}