{"id":19754,"date":"2022-11-07T16:04:49","date_gmt":"2022-11-07T10:34:49","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-what-is-the-output-please-explain-considering-i-am-a-novice-in-c-closed\/"},"modified":"2022-11-07T16:04:49","modified_gmt":"2022-11-07T10:34:49","slug":"solved-what-is-the-output-please-explain-considering-i-am-a-novice-in-c-closed","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-what-is-the-output-please-explain-considering-i-am-a-novice-in-c-closed\/","title":{"rendered":"[Solved] what is the output? Please explain, considering i am a novice in c [closed]"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-6901705\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"6901705\" data-parentid=\"6899800\" data-score=\"12\" 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<p>Time for a crash course on arrays in C.<\/p>\n<p>First of all, let&#8217;s fix the initializer for the array:<\/p>\n<pre><code>int a[3][4] = {\n                { 1,  2,  3,  4},\n                { 5,  6,  7,  8},\n                { 9, 10, 11, 12}\n              };\n<\/code><\/pre>\n<p>This defines a 3-element array of 4-element arrays of <code>int<\/code>.  The type of the <em>expression<\/em> <code>a<\/code> is &#8220;3-element array of 4-element arrays of <code>int<\/code>&#8220;.   <\/p>\n<p>Now for the headache-inducing part.  Except when it&#8217;s the operand of the <code>sizeof<\/code> or unary <code>&amp;<\/code> operators, or if it&#8217;s a string literal being used to initialize another array in a declaration, an expression of array type will have its type implicitly converted (&#8220;decay&#8221;) to a pointer type.  <\/p>\n<p>If the expression <code>a<\/code> appears by itself in the code (such as in a statement like <code>printf(\"%p\", a);<\/code>, its type is converted from &#8220;3-element array of 4-element array of <code>int<\/code>&#8221; to &#8220;pointer to 4-element array of <code>int<\/code>&#8220;, or <code>int (*)[4]<\/code>.  Similarly, if the expression <code>a[i]<\/code> appears in the code, its type is converted from &#8220;4-element array of <code>int<\/code>&#8221; (<code>int [4]<\/code>) to &#8220;pointer to <code>int<\/code>&#8221; (<code>int *<\/code>).  If <code>a<\/code> or <code>a[i]<\/code> are operands of either <code>sizeof<\/code> or <code>&amp;<\/code>, however, the conversion doesn&#8217;t happen.  <\/p>\n<p>In a similar vein, array subscripting is done through pointer arithmetic: the expression <code>a[i]<\/code> is interpreted as though it were written <code>*(a+i)<\/code>.  You offset <code>i<\/code> elements from the base of the array and dereference the result.  Thus, <code>a[0]<\/code> is the same as <code>*(a + 0)<\/code>, which is the same as <code>*a<\/code>.  <code>a[i][j]<\/code> is the same as writing <code>*(*(a + i) + j)<\/code>.  <\/p>\n<p>Here&#8217;s a table summarizing all of the above:<\/p>\n<pre>\nExpression   Type          Decays To    Resulting Value\n----------   ----          ---------    -----\n         a   int [3][4]    int (*)[4]   Address of the first element of the array\n        &amp;a   int (*)[3][4] n\/a          Same as above, but type is different\n        *a   int [4]       int *        Same as above, but type is different\n      a[0]   int [4]       int *        Same as above\n    *(a+0)   int [4]       int *        Same as above\n      a[i]   int [4]       int *        Address of the first element of the i'th subarray\n    *(a+i)   int [4]       int *        Same as above\n     &amp;a[i]   int (*)[4]    n\/a          Same as above, but type is different\n     *a[i]   int           n\/a          Value of the 0'th element of the i'th subarray\n   a[i][j]   int                        Value of the j'th element of the i'th subarray\n *(a[i]+j)   int                        Same as above\n*(*(a+i)+j)  int                        Same as above\n<\/pre>\n<p>Hopefully, that should give you everything you need to figure out what the output should be.  However, the <code>printf<\/code> statement should be written as<\/p>\n<pre><code>printf(\"%p %d %d\\n\", (void *) a[0]+1, *(a[0]+1), *(*(a+0)+1));\n<\/code><\/pre>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">1<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved what is the output? Please explain, considering i am a novice in c [closed] <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] Time for a crash course on arrays in C. First of all, let&#8217;s fix the initializer for the array: int a[3][4] = { { 1, 2, 3, 4}, { 5, 6, 7, 8}, { 9, 10, 11, 12} }; This defines a 3-element array of 4-element arrays of int. The type of the expression &#8230; <a title=\"[Solved] what is the output? Please explain, considering i am a novice in c [closed]\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-what-is-the-output-please-explain-considering-i-am-a-novice-in-c-closed\/\" aria-label=\"More on [Solved] what is the output? Please explain, considering i am a novice in c [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":[361,324,505,712],"class_list":["post-19754","post","type-post","status-publish","format-standard","hentry","category-solved","tag-arrays","tag-c","tag-multidimensional-array","tag-pointers"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] what is the output? Please explain, considering i am a novice in c [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-what-is-the-output-please-explain-considering-i-am-a-novice-in-c-closed\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] what is the output? Please explain, considering i am a novice in c [closed] - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] Time for a crash course on arrays in C. First of all, let&#8217;s fix the initializer for the array: int a[3][4] = { { 1, 2, 3, 4}, { 5, 6, 7, 8}, { 9, 10, 11, 12} }; This defines a 3-element array of 4-element arrays of int. The type of the expression ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-what-is-the-output-please-explain-considering-i-am-a-novice-in-c-closed\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-07T10:34:49+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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-is-the-output-please-explain-considering-i-am-a-novice-in-c-closed\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-is-the-output-please-explain-considering-i-am-a-novice-in-c-closed\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] what is the output? Please explain, considering i am a novice in c [closed]\",\"datePublished\":\"2022-11-07T10:34:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-is-the-output-please-explain-considering-i-am-a-novice-in-c-closed\/\"},\"wordCount\":266,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"arrays\",\"c++\",\"multidimensional-array\",\"pointers\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-is-the-output-please-explain-considering-i-am-a-novice-in-c-closed\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-what-is-the-output-please-explain-considering-i-am-a-novice-in-c-closed\/\",\"name\":\"[Solved] what is the output? Please explain, considering i am a novice in c [closed] - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-11-07T10:34:49+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-is-the-output-please-explain-considering-i-am-a-novice-in-c-closed\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-what-is-the-output-please-explain-considering-i-am-a-novice-in-c-closed\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-is-the-output-please-explain-considering-i-am-a-novice-in-c-closed\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] what is the output? Please explain, considering i am a novice in c [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=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] what is the output? Please explain, considering i am a novice in c [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-what-is-the-output-please-explain-considering-i-am-a-novice-in-c-closed\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] what is the output? Please explain, considering i am a novice in c [closed] - JassWeb","og_description":"[ad_1] Time for a crash course on arrays in C. First of all, let&#8217;s fix the initializer for the array: int a[3][4] = { { 1, 2, 3, 4}, { 5, 6, 7, 8}, { 9, 10, 11, 12} }; This defines a 3-element array of 4-element arrays of int. The type of the expression ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-what-is-the-output-please-explain-considering-i-am-a-novice-in-c-closed\/","og_site_name":"JassWeb","article_published_time":"2022-11-07T10:34:49+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-what-is-the-output-please-explain-considering-i-am-a-novice-in-c-closed\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-what-is-the-output-please-explain-considering-i-am-a-novice-in-c-closed\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] what is the output? Please explain, considering i am a novice in c [closed]","datePublished":"2022-11-07T10:34:49+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-what-is-the-output-please-explain-considering-i-am-a-novice-in-c-closed\/"},"wordCount":266,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["arrays","c++","multidimensional-array","pointers"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-what-is-the-output-please-explain-considering-i-am-a-novice-in-c-closed\/","url":"https:\/\/jassweb.com\/solved\/solved-what-is-the-output-please-explain-considering-i-am-a-novice-in-c-closed\/","name":"[Solved] what is the output? Please explain, considering i am a novice in c [closed] - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-11-07T10:34:49+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-what-is-the-output-please-explain-considering-i-am-a-novice-in-c-closed\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-what-is-the-output-please-explain-considering-i-am-a-novice-in-c-closed\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-what-is-the-output-please-explain-considering-i-am-a-novice-in-c-closed\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] what is the output? Please explain, considering i am a novice in c [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=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","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\/19754","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=19754"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/19754\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=19754"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=19754"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=19754"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}