In this mastery I will talk to you about a really simple topic, “Strings”.<\/p>\n
Well, first of all strings<\/strong> are\u00a0a one-dimensional array of characters which is terminated by a\u00a0null<\/strong>\u00a0character ‘\u0000’. Thus a null-terminated string contains the characters that comprise the string followed by a\u00a0null<\/strong>.<\/p>\n The following declaration and initialization create a string consisting of the word “Hello”. To hold the null character at the end of the array, the size of the character array containing the string is one more than the number of characters in the word “Hello.”<\/p>\n <\/p>\n If you follow the rule of array initialization, then you can write the above statement as follows:<\/p>\n <\/p>\n Following is the memory presentation of above defined string in C\/C++:<\/p>\n <\/em><\/p>\n Actually, you do not place the null character at the end of a string constant. The C++ compiler automatically places the ‘\u0000’ at the end of the string when it initializes the array. Let us try to print above-mentioned string:<\/p>\n <\/p>\n When the above code is compiled and executed, it produces result something as follows:<\/p>\n <\/p>\n For any other doubt please feel free to write it in the comments.<\/p>\n Sources:<\/p>\n http:\/\/stackoverflow.com\/questions\/10219225\/c-create-string-of-text-and-variables<\/a><\/p>\n http:\/\/www.cs.fsu.edu\/~myers\/c++\/notes\/stringobj.html<\/a><\/p>\n -The Admin<\/p>\n <\/a> <\/p>\n","protected":false},"excerpt":{"rendered":" In this mastery I will talk to you about a really simple topic, “Strings”. Well, first of all strings are a one-dimensional array of characters which is terminated by a null character ‘’. Thus a null-terminated string contains the characters that comprise the… Continue Reading →<\/a><\/p>\n","protected":false},"author":259,"featured_media":27974,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3],"tags":[582,206,62,152,617,615],"_links":{"self":[{"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/posts\/27976"}],"collection":[{"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/users\/259"}],"replies":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/comments?post=27976"}],"version-history":[{"count":1,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/posts\/27976\/revisions"}],"predecessor-version":[{"id":27977,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/posts\/27976\/revisions\/27977"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/media\/27974"}],"wp:attachment":[{"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/media?parent=27976"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/categories?post=27976"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/tags?post=27976"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}char<\/span> greeting[6<\/span>] =<\/span> {'H'<\/span>, 'e'<\/span>, 'l'<\/span>, 'l'<\/span>, 'o'<\/span>, '\u0000'<\/span>};\n<\/pre>\n<\/div>\n
char<\/span> greeting[] =<\/span> \"Hello\"<\/span>;\n<\/pre>\n<\/div>\n
#include <iostream><\/span>\n\nusing<\/span> namespace<\/span> std;\n\nint<\/span> main<\/span> ()\n{\n char<\/span> greeting[6<\/span>] =<\/span> {'H'<\/span>, 'e'<\/span>, 'l'<\/span>, 'l'<\/span>, 'o'<\/span>, '\u0000'<\/span>};\n\n cout <<<\/span> \"Greeting message: \"<\/span>;\n cout <<<\/span> greeting <<<\/span> endl;\n\n return<\/span> 0<\/span>;\n}\n<\/pre>\n<\/div>\n
Greeting message:<\/span> Hello\n<\/pre>\n<\/div>\n