{"id":11697,"date":"2023-01-16T11:38:59","date_gmt":"2023-01-16T11:38:59","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=11697"},"modified":"2023-04-13T11:29:33","modified_gmt":"2023-04-13T11:29:33","slug":"define-structure-in-c","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/","title":{"rendered":"Define Structure in C"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673869002601-Define%20structure%20in%20c.jpg\" alt=\"\" \/><\/p>\n<p>A structure in C enables programmers to group different types of variables together under a single name. Structure in C language is a very powerful feature that allows for the creation of more complex data structures. In this article, we will discuss the structure definition in C, how to declare a structure in C, usage of structure in C, and some examples, and at the end, we will also see what is a nested structure in C. So, without any further delay, let&#8217;s move on to our next section.<\/p>\n<h2>What is Structure in C?<\/h2>\n<p>In C language, a user-defined data type called structure allows us to store a variety of distinct data types. The word &quot;member&quot; refers to each component of a structure. Because they can contain different types of information, structures can emulate the usage of classes and templates.<\/p>\n<p>The structure is specified using the struct keyword. Let&#8217;s look at the syntax to define structure in C language.<\/p>\n<pre><code>struct structure_name   \n{  \n    data_type member1;  \n    data_type member2;  \n    .  \n    .  \n    data_type memeberN;  \n};  <\/code><\/pre>\n<p>Let&#8217;s look at an example of how to define structure in C example for an entity employee.<\/p>\n<pre><code>struct employee  \n{   int id;  \n    char name[20];  \n    float salary;  \n};<\/code><\/pre>\n<p>The memory allocation for the structure employee defined in the preceding example is displayed in the next image.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673869052453-Define%20structure%20in%20c1.png\" alt=\"\" \/><\/p>\n<p>In this case, a struct is a keyword; the employee is the structure&#8217;s name; and id, name, and salary are its members or fields. Let&#8217;s interpret it using the following diagram:<\/p>\n<h3>Define structure in C<\/h3>\n<p>Structure variables must first be defined before being created. Structures may be defined using the struct keyword.<\/p>\n<p><strong>Syntax:-<\/strong><\/p>\n<pre><code>struct name_of_the_structure \n{\n    data_type member1;\n    data_type member2;\n    ...\n    data_type memberN;\n};<\/code><\/pre>\n<p><strong>Example of C Structures<\/strong><\/p>\n<pre><code>struct bill\n{\n   float amount;\n   int id;\n   char address[100];\n};<\/code><\/pre>\n<h3>How to Declare structure variable?<\/h3>\n<p>To make it simple to access a structure member, we can create a variable for the structure. Structure variables can be declared in one of two ways:<\/p>\n<ol>\n<li>By using the struct keyword in the main() method.<\/li>\n<li>By declaring a variable when the structure is defined.<\/li>\n<\/ol>\n<p><strong>1st way:<\/strong><br \/>\nLet&#8217;s look at an example of using the struct keyword to define structure variable. Declaring it within the main function is appropriate.<\/p>\n<pre><code>struct employee  \n{   int id;  \n    char name[50];  \n    float salary;  \n};  <\/code><\/pre>\n<p>Put the provided code within the main() method at this point.<\/p>\n<pre><code>struct employee e1, e2;  <\/code><\/pre>\n<p>The values kept in the structure can be accessed using the variables e1 and e2. Here, e1 and e2 may be handled similarly to Java and C++ objects.<\/p>\n<p><strong>2nd way:<\/strong><br \/>\nLet&#8217;s see a different approach to declaring variables as the structure is being defined.<\/p>\n<pre><code>struct employee  \n{   int id;  \n    char name[50];  \n    float salary;  \n}e1,e2;  <\/code><\/pre>\n<p><strong>Which strategy is best?<\/strong><br \/>\nUse the first method if some variables are not fixed. You have the freedom to declare the structure variable several times.<br \/>\nUse the second strategy if the number of variables is fixed. Declaring a variable in the main() method saves you code.<\/p>\n<h3>Accessing members of the structure<\/h3>\n<p>There are two ways to access structure members:<\/p>\n<ol>\n<li>By . (member or dot operator)<\/li>\n<li>By -&gt; (structure pointer operator)<\/li>\n<\/ol>\n<p>Let&#8217;s look at the code for the (member) operator to access the id member of the p1 variable.<br \/>\np1.id  <\/p>\n<h2>Why use structure?<\/h2>\n<p>There are conditions where we need to keep more than one attribute for an entity in the C language. An entity need not include all the information of a single type. It is capable of having various properties from various data types. As an illustration, a student object may have a name (string), roll number (int), and marks (float). We have the following methods for storing this sort of student-related information:<\/p>\n<ul>\n<li>Construct individual arrays for storing names, roll numbers, and marks.<\/li>\n<li>Use a special data structure to store the collection of different data types.<\/li>\n<\/ul>\n<h2>C Structure example<\/h2>\n<p>Let&#8217;s see a simple structure in C example.<\/p>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_11653 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_11653 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_11653 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_11653 .wpsm_nav-tabs > li.active > a, #tab_container_11653 .wpsm_nav-tabs > li.active > a:hover, #tab_container_11653 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_11653 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_11653 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_11653 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_11653 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_11653 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_11653 .wpsm_nav-tabs > li > a:hover , #tab_container_11653 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_11653 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_11653 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_11653 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_11653 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_11653 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_11653 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_11653 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_11653 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_11653 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_11653 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_11653 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_11653\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_11653\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_11653_1\" aria-controls=\"tabs_desc_11653_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_11653\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_11653_1\">\r\n\t\t\t\t\t\t\t\t<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\">#include&lt;stdio.h&gt;  \r\n#include &lt;string.h&gt;    \r\nstruct employee      \r\n{   int id;      \r\n    char name[50];      \r\n}e1;  \/\/declaring e1 variable for structure    \r\nint main( )    \r\n{    \r\n   \/\/store first employee information    \r\n   e1.id=101;    \r\n   strcpy(e1.name, \"Abhishek Sharma\");\/\/copying string into char array    \r\n   \/\/printing first employee information    \r\n   printf( \"employee 1 id : %d&#92;n\", e1.id);    \r\n   printf( \"employee 1 name : %s&#92;n\", e1.name);    \r\nreturn 0;  \r\n}\r\n<\/pre>\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_11653 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_11653 a\"),jQuery(\"#tab-content_11653\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<p><strong>Output<\/strong><\/p>\n<pre><code>employee 1 id: 101\nemployee 1 name: Abhishek Sharma<\/code><\/pre>\n<p><strong>Explanation:<\/strong> The above program demonstrates the use of structure in C programming language. First, a structure is defined using the keyword &quot;struct&quot; with the name &quot;employee&quot;. It has two member variables &#8211; an integer &quot;id&quot; and a character array &quot;name&quot; of size 50. Next, a structure variable &quot;e1&quot; is declared for the &quot;employee&quot; structure. In the main function, the program stores information about the first employee in the &quot;e1&quot; structure. The &quot;id&quot; value of the employee is set to 101 using the dot (.) operator. The &quot;name&quot; of the employee is set using the strcpy() function, which copies the string &quot;Abhishek Sharma&quot; into the &quot;name&quot; character array of the &quot;e1&quot; structure.<\/p>\n<h2>Nested Structure in C<\/h2>\n<p>Complex data types can be generated by nesting one structure inside another utilizing C&#8217;s functionality. For instance, we could need to keep the address of an employee for an object in a structure. Street number, city, state, and pin code are additional subparts that can be included in the attribute address. As a result, in order to save the employee&#8217;s address, we must nest the structure in which the address is stored within the structure that contains the employee&#8217;s address. Consider the program below.<\/p>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_11654 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_11654 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_11654 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_11654 .wpsm_nav-tabs > li.active > a, #tab_container_11654 .wpsm_nav-tabs > li.active > a:hover, #tab_container_11654 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_11654 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_11654 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_11654 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_11654 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_11654 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_11654 .wpsm_nav-tabs > li > a:hover , #tab_container_11654 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_11654 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_11654 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_11654 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_11654 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_11654 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_11654 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_11654 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_11654 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_11654 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_11654 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_11654 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_11654\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_11654\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_11654_1\" aria-controls=\"tabs_desc_11654_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_11654\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_11654_1\">\r\n\t\t\t\t\t\t\t\t<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\">#include&lt;stdio.h&gt;  \r\nstruct address   \r\n{  \r\n    char city[20];  \r\n    int pin;  \r\n    char phone[14];  \r\n};  \r\nstruct employee  \r\n{  \r\n    char name[20];  \r\n    struct address add;  \r\n};  \r\nvoid main ()  \r\n{  \r\n    struct employee emp;  \r\n    printf(\"Enter employee information?&#92;n\");  \r\n    scanf(\"%s %s %d %s\",emp.name,emp.add.city, &amp;emp.add.pin, emp.add.phone);  \r\n    printf(\"Printing the employee information....&#92;n\");  \r\n    printf(\"name: %s&#92;nCity: %s&#92;nPincode: %d&#92;nPhone: %s\",emp.name,emp.add.city,emp.add.pin,emp.add.phone);  \r\n}\r\n<\/pre>\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_11654 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_11654 a\"),jQuery(\"#tab-content_11654\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<p><strong>Output<\/strong><\/p>\n<pre><code>Abhay\nDelhi\n123456\n1234567890\nEnter employee information?\nPrinting the employee information....\nname: Abhay\nCity: Delhi\nPincode: 123456\nPhone: 1234567890<\/code><\/pre>\n<p><strong>Explanation:<\/strong> This program demonstrates the use of nested structure in C language. The code starts by defining two structures &#8211; &quot;address&quot; and &quot;employee&quot;. The &quot;address&quot; structure has three member variables &#8211; a character array &quot;city&quot; of size 20, an integer &quot;pin&quot;, and a character array &quot;phone&quot; of size 14. The &quot;employee&quot; structure has two member variables &#8211; a character array &quot;name&quot; of size 20 and an &quot;address&quot; structure variable &quot;add&quot;. In the main function, the program declares an &quot;employee&quot; structure variable &quot;emp&quot;. Then, it prompts the user to enter the employee information using the printf() function. The scanf() function is used to read the input values into the &quot;emp&quot; structure members &#8211; &quot;name&quot;, &quot;add.city&quot;, &quot;add.pin&quot;, and &quot;add.phone&quot;.<\/p>\n<p><strong>The structure can be nested in the following ways.<\/strong><\/p>\n<ol>\n<li>By separate structure<\/li>\n<li>By Embedded structure<\/li>\n<\/ol>\n<p><strong>1) Separate structure<\/strong><br \/>\nIn this case, we build two structures, but the dependent structure must be a member of the primary structure. Consider the case below.<\/p>\n<pre><code>struct Date  \n{  \n   int dd;  \n   int mm;  \n   int yyyy;   \n};  \nstruct Employee  \n{     \n   int id;  \n   char name[20];  \n   struct Date doj;  \n}emp1;  <\/code><\/pre>\n<p>As you can see, the variable doj (date of joining) is of type Date. In this case, doj is a part of the Employee hierarchy. The Date structure may be applied in a variety of structures in this fashion.<\/p>\n<p><strong>2) Embedded structure<\/strong><br \/>\nWe can declare the structure inside the structure due to the embedded structure. Since it cannot be utilized in many data structures, it takes fewer lines of code. Consider the case below.<\/p>\n<pre><code>struct Employee  \n{     \n   int id;  \n   char name[20];  \n   struct Date  \n    {  \n      int dd;  \n      int mm;  \n      int yyyy;   \n    }doj;  \n}emp1;  <\/code><\/pre>\n<h3>Accessing Nested Structure in C<\/h3>\n<p>We can access the member of the nested structure in C by Outer_Structure.Nested_Structure.member as given below:<\/p>\n<pre><code>e1.doj.dd  \ne1.doj.mm  \ne1.doj.yyyy  <\/code><\/pre>\n<h3>Nested Structure in C example<\/h3>\n<p>Let&#8217;s look at a straightforward example of a nested structure in C.<\/p>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_11655 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_11655 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_11655 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_11655 .wpsm_nav-tabs > li.active > a, #tab_container_11655 .wpsm_nav-tabs > li.active > a:hover, #tab_container_11655 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_11655 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_11655 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_11655 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_11655 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_11655 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_11655 .wpsm_nav-tabs > li > a:hover , #tab_container_11655 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_11655 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_11655 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_11655 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_11655 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_11655 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_11655 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_11655 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_11655 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_11655 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_11655 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_11655 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_11655\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_11655\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_11655_1\" aria-controls=\"tabs_desc_11655_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_11655\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_11655_1\">\r\n\t\t\t\t\t\t\t\t<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\">#include &lt;stdio.h&gt;  \r\n#include &lt;string.h&gt;  \r\nstruct Employee  \r\n{     \r\n   int id;  \r\n   char name[20];  \r\n   struct Date  \r\n    {  \r\n      int dd;  \r\n      int mm;  \r\n      int yyyy;   \r\n    }doj;  \r\n}e1;  \r\nint main( )  \r\n{  \r\n   \/\/storing employee information  \r\n   e1.id=101;  \r\n   strcpy(e1.name, \"Abhay\");\/\/copying string into char array  \r\n   e1.doj.dd=10;  \r\n   e1.doj.mm=11;  \r\n   e1.doj.yyyy=2014;  \r\n  \r\n   \/\/printing first employee information  \r\n   printf( \"employee id : %d&#92;n\", e1.id);  \r\n   printf( \"employee name : %s&#92;n\", e1.name);  \r\n   printf( \"employee date of joining (dd\/mm\/yyyy) : %d\/%d\/%d&#92;n\", e1.doj.dd,e1.doj.mm,e1.doj.yyyy);  \r\n   return 0;  \r\n}<\/pre>\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_11655 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_11655 a\"),jQuery(\"#tab-content_11655\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<p><strong>Output<\/strong><\/p>\n<pre><code>employee id: 101\nemployee name: Abhay\nemployee date of joining (dd\/mm\/yyyy): 10\/11\/2014<\/code><\/pre>\n<p><strong>Explanation:<\/strong> This program demonstrates the use of nested structure in C programming language, specifically in the context of storing and printing the date of joining of an employee along with their other information. The code defines a structure named &quot;Employee&quot; which has three member variables &#8211; an integer &quot;id&quot;, a character array &quot;name&quot;, and another structure &quot;Date&quot; which has three integer member variables &#8211; &quot;dd&quot; (day), &quot;mm&quot; (month), and &quot;yyyy&quot; (year). In the main function, the program declares an &quot;Employee&quot; structure variable &quot;e1&quot;. It then stores the employee information such as &quot;id&quot;, &quot;name&quot;, and &quot;date of joining&quot; into their respective member variables of the &quot;e1&quot; structure using assignment statements and strcpy() function to copy the string.<\/p>\n<p><strong>Conclusion<\/strong><br \/>\nIn this article, we have taught the structure in C language, you have learned the basics of structure in C programming, and Structure definition in C language. You started with a small introduction to a structure in C and moved ahead to discuss the uses of a structure in C. Next, you learned about the syntax of structures, how to declare and initialize a structure in C, and how to access the elements of a structure in C.<\/p>\n<h2>FAQs<\/h2>\n<p>Here are some frequently asked questions on structure in C language.<\/p>\n<p><strong>Q1: What is the purpose of using a structure in C?<\/strong><br \/>\n<strong>Ans:<\/strong> The purpose of using structures in C is to group related data together to make it easier to work with, manage, and organize.<\/p>\n<p><strong>Q2: Can you have arrays as members of a structure in C?<\/strong><br \/>\n<strong>Ans:<\/strong> Yes, you can have arrays as members of a structure in C.<\/p>\n<p><strong>Q3: Can you have structures as members of a structure in C?<\/strong><br \/>\n<strong>Ans:<\/strong> Yes, you can have structures as members of a structure in C.<\/p>\n<p><strong>Q4: Can you have pointers as members of a structure in C?<\/strong><br \/>\n<strong>Ans:<\/strong> Yes, you can have pointers as members of a structure in C.<\/p>\n<p><strong>Q5: How do you pass a structure to a function in C?<\/strong><br \/>\n<strong>Ans:<\/strong> You can pass a structure to a function in C by using the structure name as the argument.<\/p>\n<p><strong>Q6: Can you return a structure from a function in C?<\/strong><br \/>\n<strong>Ans:<\/strong> Yes, you can return a structure from a function in C.<\/p>\n<p><strong>Q7: How do you compare two structures in C?<\/strong><br \/>\n<strong>Ans:<\/strong> You can compare two structures in C by comparing each of their members.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A structure in C enables programmers to group different types of variables together under a single name. Structure in C language is a very powerful feature that allows for the creation of more complex data structures. In this article, we will discuss the structure definition in C, how to declare a structure in C, usage [&hellip;]<\/p>\n","protected":false},"author":52,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-11697","post","type-post","status-publish","format-standard","hentry","category-c-programming"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Define Structure in C<\/title>\n<meta name=\"description\" content=\"Understanding structure in C language, structure definition in C, and nested structure in c in detail.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Define Structure in C\" \/>\n<meta property=\"og:description\" content=\"Understanding structure in C language, structure definition in C, and nested structure in c in detail.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/\" \/>\n<meta property=\"og:site_name\" content=\"PrepBytes Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prepbytes0211\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-16T11:38:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-04-13T11:29:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673869002601-Define%20structure%20in%20c.jpg\" \/>\n<meta name=\"author\" content=\"Prepbytes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prepbytes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"Define Structure in C\",\"datePublished\":\"2023-01-16T11:38:59+00:00\",\"dateModified\":\"2023-04-13T11:29:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/\"},\"wordCount\":1556,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673869002601-Define%20structure%20in%20c.jpg\",\"articleSection\":[\"C Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/\",\"name\":\"Define Structure in C\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673869002601-Define%20structure%20in%20c.jpg\",\"datePublished\":\"2023-01-16T11:38:59+00:00\",\"dateModified\":\"2023-04-13T11:29:33+00:00\",\"description\":\"Understanding structure in C language, structure definition in C, and nested structure in c in detail.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673869002601-Define%20structure%20in%20c.jpg\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673869002601-Define%20structure%20in%20c.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/43.205.93.38\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C Programming\",\"item\":\"https:\/\/prepbytes.com\/blog\/category\/c-programming\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Define Structure in C\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/43.205.93.38\/#website\",\"url\":\"http:\/\/43.205.93.38\/\",\"name\":\"PrepBytes Blog\",\"description\":\"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING\",\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/43.205.93.38\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/43.205.93.38\/#organization\",\"name\":\"Prepbytes\",\"url\":\"http:\/\/43.205.93.38\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"contentUrl\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"width\":160,\"height\":160,\"caption\":\"Prepbytes\"},\"image\":{\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/prepbytes0211\/\",\"https:\/\/www.instagram.com\/prepbytes\/\",\"https:\/\/www.linkedin.com\/company\/prepbytes\/\",\"https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\",\"name\":\"Prepbytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"caption\":\"Prepbytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Define Structure in C","description":"Understanding structure in C language, structure definition in C, and nested structure in c in detail.","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:\/\/prepbytes.com\/blog\/define-structure-in-c\/","og_locale":"en_US","og_type":"article","og_title":"Define Structure in C","og_description":"Understanding structure in C language, structure definition in C, and nested structure in c in detail.","og_url":"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2023-01-16T11:38:59+00:00","article_modified_time":"2023-04-13T11:29:33+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673869002601-Define%20structure%20in%20c.jpg","type":"","width":"","height":""}],"author":"Prepbytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Prepbytes","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"Define Structure in C","datePublished":"2023-01-16T11:38:59+00:00","dateModified":"2023-04-13T11:29:33+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/"},"wordCount":1556,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673869002601-Define%20structure%20in%20c.jpg","articleSection":["C Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/define-structure-in-c\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/","url":"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/","name":"Define Structure in C","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673869002601-Define%20structure%20in%20c.jpg","datePublished":"2023-01-16T11:38:59+00:00","dateModified":"2023-04-13T11:29:33+00:00","description":"Understanding structure in C language, structure definition in C, and nested structure in c in detail.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/define-structure-in-c\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673869002601-Define%20structure%20in%20c.jpg","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673869002601-Define%20structure%20in%20c.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/define-structure-in-c\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/43.205.93.38\/"},{"@type":"ListItem","position":2,"name":"C Programming","item":"https:\/\/prepbytes.com\/blog\/category\/c-programming\/"},{"@type":"ListItem","position":3,"name":"Define Structure in C"}]},{"@type":"WebSite","@id":"http:\/\/43.205.93.38\/#website","url":"http:\/\/43.205.93.38\/","name":"PrepBytes Blog","description":"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING","publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/43.205.93.38\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/43.205.93.38\/#organization","name":"Prepbytes","url":"http:\/\/43.205.93.38\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/","url":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","contentUrl":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","width":160,"height":160,"caption":"Prepbytes"},"image":{"@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/prepbytes0211\/","https:\/\/www.instagram.com\/prepbytes\/","https:\/\/www.linkedin.com\/company\/prepbytes\/","https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA"]},{"@type":"Person","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e","name":"Prepbytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","caption":"Prepbytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/11697","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/users\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=11697"}],"version-history":[{"count":3,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/11697\/revisions"}],"predecessor-version":[{"id":15588,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/11697\/revisions\/15588"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=11697"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=11697"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=11697"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}