You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>Imagine you have a collection of data that you want to store together, like a person's details. You can create a struct to hold this data:</p>
2078
+
<pre><code>struct Person {
2079
+
int age;
2080
+
char name[20];
2081
+
};</code></pre>
2082
+
</div>
2083
+
<divclass="content-block">
2084
+
<h3>Some cool things about structures:</h3>
2085
+
<ul>
2086
+
<li><strong>Structure Padding:</strong> When you define a structure, the compiler might add some extra space (padding) between members to ensure they're aligned properly in memory.<br>
2087
+
<p>For example:</p>
2088
+
<pre><code>struct Example {
2089
+
char a; // 1 byte
2090
+
int b; // 4 bytes
2091
+
}; // The total size might be 8 bytes due to padding</code></pre></li>
2092
+
<li><strong>Bit Fields:</strong> You can specify the number of bits for a structure member, which is useful when working with limited memory:<br>
2093
+
<pre><code>struct PackedData {
2094
+
unsigned int flag: 1;
2095
+
unsigned int mode: 2;
2096
+
};</code></pre></li>
2097
+
<li><strong>Nested Structures:</strong> You can define a structure within another structure:<br>
2098
+
<pre><code>struct Address {
2099
+
char street[20];
2100
+
char city[10];
2101
+
};
2102
+
2103
+
struct Person {
2104
+
int age;
2105
+
char name[20];
2106
+
struct Address address;
2107
+
};</code></pre></li>
2108
+
</ul>
2109
+
</div>
2110
+
<divclass="content-block">
2111
+
<h3>File Handling in C:</h3>
2112
+
<p>File handling allows you to read and write data to files. Here are some key functions:</p>
2113
+
<ul>
2114
+
<li><strong>fopen():</strong> Opens a file.</li>
2115
+
<li><strong>fread()</strong> and <strong>fwrite():</strong> Read and write data to files.</li>
2116
+
<li><strong>fclose():</strong> Closes a file.</li>
0 commit comments