{"id":2855,"date":"2021-08-27T07:22:36","date_gmt":"2021-08-27T01:52:36","guid":{"rendered":"https:\/\/selfimagination.in\/tips\/?p=2855"},"modified":"2022-01-16T18:23:30","modified_gmt":"2022-01-16T12:53:30","slug":"c-structure","status":"publish","type":"post","link":"https:\/\/selfimagination.in\/tips\/c-structure\/","title":{"rendered":"Structure in C (Struct) \/ Declaration \/ Initialization \/ Usage"},"content":{"rendered":"\n<p>\u0907\u0938 Article \u092e\u0947\u0902 \u0939\u092e Structure in C \u0915\u0947 \u092c\u093e\u0930\u0947 \u092e\u0947\u0902 \u0938\u092e\u091d\u0947\u0902\u0917\u0947\u0964 \u0914\u0930 Struct \u0938\u0947 Related \u0938\u092d\u0940 Topic \u0915\u094b \u0907\u0938 Article \u092e\u0947\u0902 Cover \u0915\u093f\u092f\u093e \u0917\u092f\u093e \u0939\u0948\u0902\u0964 <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is Structure in C ?<\/h2>\n\n\n\n<p>\u0907\u0938 \u0924\u0930\u0939 \u0915\u0947 Data Type \u092e\u0947\u0902 \u0939\u092e \u0905\u0932\u0917-\u0905\u0932\u0917 \u0924\u0930\u0939 \u0915\u0947 Data Type \u0915\u094b Store \u0915\u0930 \u0938\u0915\u0924\u0947 \u0939\u0948\u0902 \u0964 \u092f\u0939 Heterogeneous Type \u0939\u094b\u0924\u093e \u0939\u0948\u0902 \u092f\u093e\u0928\u093f \u0915\u0940 \u0939\u092e \u090f\u0915 \u0939\u0940 \u092e\u0947\u0902 int, char, float \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930 \u0938\u0915\u0924\u0947 \u0939\u0948\u0902, \u0907\u0938 \u0915\u0940 size \u091c\u093f\u0924\u0928\u0947 \u092d\u0940 \u0939\u092e\u0928\u0947 Datatype \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u093f\u092f\u093e \u0939\u0948\u0902 \u0909\u0928\u0915\u093e Sum \u0939\u094b\u0924\u0940 \u0939\u0948\u0902 \u0964<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Declaration of Structure<\/h2>\n\n\n\n<p class=\"wp-block-zozuk-wphindi\">Structure \u0915\u094b \u0907\u0938 \u092a\u094d\u0930\u0915\u093e\u0930 \u0938\u0947 Declare \u0915\u093f\u092f\u093e \u091c\u093e\u0924\u093e \u0939\u0948\u0902 \u0964 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">struct Student\n{\n    int  sch_no;  \/\/Scholar No.\n    char section; \/\/Section Name\n    int  cls;     \/\/Class \n} typedef Stud ;\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Initialization of Structure<\/h2>\n\n\n\n<p class=\"wp-block-zozuk-wphindi\">Structure \u0915\u094b Initialize \u0915\u0930\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f \u0926\u094b \u0924\u0930\u0940\u0915\u0947 \u0939\u0948\u0902 \u0906\u092a \u0926\u094b\u0928\u094b\u0902 \u092e\u0947\u0902 \u0938\u0947 \u0915\u094b\u0908 \u092d\u0940 \u0924\u0930\u0940\u0915\u0947 \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930 \u0938\u0915\u0924\u0947 \u0939\u0948\u0902 \u0964<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">    stud s1;                 \/\/Implicit initialization\n    stud s2 = {1, 'A', 5};   \/\/Explicit initialization \n    stud s3 = {.section = 'B', .sch_no=3, .cls = 4 }; \/\/Designated initialization \n    \n    s1.sch_no  = 2;\n    s1.section = 'B';\n    s1.cls     = 5;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Get Value from Structure<\/h2>\n\n\n\n<p class=\"wp-block-zozuk-wphindi\">Structure \u0938\u0947 \u0935\u0948\u0932\u094d\u092f\u0942 \u0915\u094b \u0907\u0938 \u0924\u0930\u0939 \u0938\u0947 Read \u0915\u093f\u092f\u093e \u091c\u093e\u0924\u093e \u0939\u0948\u0902 \u0964<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">printf(\"Value of s1.scho_no is :%d\\n\", s1.sch_no);\nprintf(\"Value of s1.section is :%c\\n\", s1.section);\nprintf(\"Value of s1.cls     is :%d\\n\", s1.cls);<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">Value of s1.scho_no is :2\nValue of s1.section is :B\nValue of s1.cls     is :5<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/selfimagination.in\/tips\/c-array-declaration-initialization-set-get-2d\/\">Array<\/a> of Structure in C <\/h2>\n\n\n\n<p>\u091c\u0948\u0938\u093e \u0915\u0940 \u0939\u092e \u091c\u093e\u0928\u0924\u0947 \u0939\u0948 \u0915\u0940 Array \u092e\u0947\u0902 \u0939\u092e \u090f\u0915 \u091c\u0948\u0938\u0947 Data Type \u0915\u0940 \u090f\u0915 \u0938\u0947 \u0905\u0927\u093f\u0915 value \u0915\u094b Store \u0915\u0930 \u0930\u0916 \u0938\u0915\u0924\u0947 \u0939\u0948\u0902\u0964 \u092f\u0926\u093f \u0939\u092e \u0915\u093f\u0938\u0940 Structure \u0915\u093e \u092d\u0940 Array \u092c\u0928\u093e\u0928\u093e \u091a\u093e\u0939\u0947 \u0924\u094b \u092c\u0928\u093e \u0938\u0915\u0924\u0947 \u0939\u0948\u0902\u0964 \u0914\u0930 \u091c\u0948\u0938\u0947 \u0915\u0940 \u0939\u092e\u0947\u0902 Array Declare \u0915\u0930\u0924\u0947 \u0938\u092e\u092f \u0915\u093f\u092f\u093e \u0925\u093e \u0935\u0948\u0938\u0947 \u0939\u0940 \u0939\u092e\u0947\u0902 Array of Structure \u0915\u0947 \u0932\u093f\u090f \u0915\u0930\u0928\u093e \u0939\u0948\u0902\u0964 <\/p>\n\n\n\n<p class=\"wp-block-zozuk-wphindi\">\u092f\u0939\u093e\u0901 \u092a\u0930 \u0939\u092e\u0928\u0947 Structure \u0915\u093e Array \u092c\u0928\u093e\u092f\u093e \u0939\u0948\u0902 \u0914\u0930 \u0909\u0938\u092e\u0947 Value Assign \u0915\u0930 Loop \u0938\u0947 Print \u0915\u093f\u092f\u093e \u0939\u0948\u0902 \u0964<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">    stud s[2];           \/\/Declare Array of Structure\n    s[0].sch_no  = 3;\n    s[0].section = 'A';\n    s[0].cls     = 1;\n    \n    s[1].sch_no  = 4;\n    s[1].section = 'C';\n    s[1].cls     = 2;\n\n    for (int i=0; i&lt;2; i++)  \/\/ Print Value of Array Structure\n    {\n        printf(\"\\n\");\n        printf(\"Value of s[%d].scho_no is :%d\\n\", i, s[i].sch_no);\n        printf(\"Value of s[%d].section is :%c\\n\", i, s[i].section);\n        printf(\"Value of s[%d].cls     is :%d\\n\", i, s[i].cls);\n    }\n<\/code><\/pre>\n\n\n\n<p><strong>C Initialize Struct Array<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u0907\u0938 Example \u092e\u0947 \u0939\u092e\u0928\u0947 \u0938\u092c\u0938\u0947 \u092a\u0939\u0932\u0947 stud s[] declare \u0915\u093f\u092f\u093e \u0939\u0948 \u0964 <\/li><li>Next  line \u092e\u0947 Struct Array \u0915\u094b Initialize \u0915\u093f\u092f\u093e \u0939\u0948\u0902 \u0964 <\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/selfimagination.in\/tips\/c-pointer\/\">Pointer<\/a> to a Structure in C <\/h2>\n\n\n\n<p class=\"wp-block-zozuk-wphindi\">\u091c\u0948\u0938\u093e \u0915\u0940 \u0939\u092e \u091c\u093e\u0928\u0924\u0947 \u0939\u0948\u0902 \u0915\u0940 Pointer Value \u0915\u094b Store \u0928 \u0915\u0930\u0924\u0947 \u0939\u0941\u090f Variable \u0915\u0947 Address \u0915\u094b Store \u0915\u0930\u0924\u093e \u0939\u0948\u0902 \u0920\u0940\u0915 \u0935\u0948\u0938\u093e \u0939\u0940 \u091c\u092c \u0939\u092e\u0947\u0902 \u0915\u093f\u0938 Structure \u0915\u0947 Address \u0915\u094b Point \u0915\u0930\u0928\u093e \u0939\u094b \u0924\u094b \u0939\u092e Pointer to a Structure \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0924\u0947 \u0939\u0948\u0902 \u0964\u092f\u0939\u093e\u0901 \u092a\u0930 \u0939\u092e\u0928\u0947 \u091c\u094b \u092a\u0939\u0932\u0947 S1 stud type Struct \u092c\u0928\u093e\u092f\u093e \u0925\u093e \u0909\u0938\u0940 \u0915\u0940 \u0935\u0948\u0932\u094d\u092f\u0942 \u0915\u094b Pointer \u092e\u0947\u0902 \u0932\u0947 \u0915\u0930 \u092a\u094d\u0930\u093f\u0902\u091f \u0915\u0930\u0935\u093e\u0908 \u0939\u0948\u0902 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">stud *p = &amp;s1;\n\nprintf(\"\\n\");\nprintf(\"Value of s1.scho_no is :%d\\n\", p-&gt;sch_no);\nprintf(\"Value of s1.section is :%c\\n\", p-&gt;section);\nprintf(\"Value of s1.cls     is :%d\\n\", p-&gt;cls);\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-zozuk-wphindi\">\u091c\u092c \u0939\u092e pointer \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0924\u0947 \u0939\u0948\u0902 \u0924\u092c -&gt; \u0907\u0938 symbol \u0938\u0947 Inner Variable \u0915\u094b Access \u0915\u0930 \u0938\u0915\u0924\u0947 \u0939\u0948\u0902 \u0964<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p class=\"wp-block-zozuk-wphindi\">\u0909\u092a\u0930\u094b\u0915\u094d\u0924 \u0938\u092d\u0940 Program \u0915\u094b \u090f\u0915 \u0938\u093e\u0925 \u0915\u093f\u092f\u093e \u0917\u092f\u093e \u0939\u0948 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">#include &lt;stdio.h&gt;\n\nstruct Student\n{\n    int  sch_no;\n    char section;  \n    int  cls;  \n}  typedef stud;\n\nvoid main()\n{\n    stud s1;                 \/\/Implicit initialization\n    stud s2 = {1, 'A', 5};   \/\/Explicit initialization \n    stud s3 = {.section = 'B', .sch_no=3, .cls = 4 }; \/\/Designated initialization \n\n    s1.sch_no  = 2;\n    s1.section = 'B';\n    s1.cls     = 5;\n\n    printf(\"Value of s1.scho_no is :%d\\n\", s1.sch_no);\n    printf(\"Value of s1.section is :%c\\n\", s1.section);\n    printf(\"Value of s1.cls     is :%d\\n\", s1.cls);\n\n\n    \/\/ Example Array of Structure\n\n    stud s[2];           \/\/Declare Array of Structure\n    s[0].sch_no  = 3;\n    s[0].section = 'A';\n    s[0].cls     = 1;\n    \n    s[1].sch_no  = 4;\n    s[1].section = 'C';\n    s[1].cls     = 2;\n\n    for (int i=0; i&lt;2; i++)  \/\/ Print Value of Array Structure\n    {\n        printf(\"\\n\");\n        printf(\"Value of s[%d].scho_no is :%d\\n\", i, s[i].sch_no);\n        printf(\"Value of s[%d].section is :%c\\n\", i, s[i].section);\n        printf(\"Value of s[%d].cls     is :%d\\n\", i, s[i].cls);\n    }\n\n\n\n    \/\/ Example Pointer Structure\n\n\n\n    stud *p = &amp;s1;\n    printf(\"\\n\");\n    printf(\"Value of s1.scho_no is :%d\\n\", p-&gt;sch_no);\n    printf(\"Value of s1.section is :%c\\n\", p-&gt;section);\n    printf(\"Value of s1.cls     is :%d\\n\", p-&gt;cls);\n\n}\n  <\/code><\/pre>\n\n\n\n<p class=\"wp-block-zozuk-wphindi\">\u0906\u0936\u093e \u0939\u0948\u0902 \u092e\u0941\u091d\u0947 \u0915\u0940 \u0906\u092a\u0915\u094b \u092f\u0939 Article \u0938\u092e\u091d \u092e\u0947\u0902 \u0906 \u0917\u092f\u093e \u0939\u094b\u0917\u093e , \u092f\u0926\u093f \u0915\u093f\u0938\u0940 \u092d\u0940 \u092a\u094d\u0930\u0915\u093e\u0930 \u0915\u093e \u0915\u094b\u0908 Doubt \u0939\u094b \u0924\u094b \u0906\u092a Comment \u0915\u0930 \u0938\u0915\u0924\u0947 \u0939\u0948\u0902. \u0905\u092a\u0928\u093e \u0915\u0940\u092e\u0924\u0940 \u0938\u092e\u092f \u0926\u0947\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f \u0927\u0928\u094d\u092f\u0935\u093e\u0926\u094d <\/p>\n\n\n\n<p class=\"wp-block-zozuk-wphindi\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0907\u0938 Article \u092e\u0947\u0902 \u0939\u092e Structure in C \u0915\u0947 \u092c\u093e\u0930\u0947 \u092e\u0947\u0902 \u0938\u092e\u091d\u0947\u0902\u0917\u0947\u0964 \u0914\u0930 Struct \u0938\u0947 Related \u0938\u092d\u0940 Topic \u0915\u094b \u0907\u0938 Article \u092e\u0947\u0902 Cover \u0915\u093f\u092f\u093e \u0917\u092f\u093e \u0939\u0948\u0902\u0964 What is Structure in C ? \u0907\u0938 \u0924\u0930\u0939 \u0915\u0947 Data Type \u092e\u0947\u0902 \u0939\u092e \u0905\u0932\u0917-\u0905\u0932\u0917 \u0924\u0930\u0939 \u0915\u0947 Data Type \u0915\u094b Store \u0915\u0930 \u0938\u0915\u0924\u0947 \u0939\u0948\u0902 \u0964 \u092f\u0939 Heterogeneous Type \u0939\u094b\u0924\u093e \u0939\u0948\u0902 \u092f\u093e\u0928\u093f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3017,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[11],"tags":[],"class_list":["post-2855","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/08\/c-structure-hindi.jpg?fit=1200%2C628&ssl=1","_links":{"self":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts\/2855","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/comments?post=2855"}],"version-history":[{"count":42,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts\/2855\/revisions"}],"predecessor-version":[{"id":6457,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts\/2855\/revisions\/6457"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/media\/3017"}],"wp:attachment":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/media?parent=2855"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/categories?post=2855"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/tags?post=2855"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}