C Tutorial with Code Examples and Practice Exercises
A C tutorial helps beginners and programmers learn the C programming language through structured lessons, code examples, and hands-on exercises. It covers a range of topics, from basics to advanced, enabling users to write efficient, powerful, and system-level programs in C.
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">&nbsp;</span></p><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-outline-level: 1;"><strong><span style="font-size: 24.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 18.0pt;">Introduction</span></strong></p><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">If you're looking to <strong>learn C programming language</strong>, you're in the right place. This <strong><a href="https://www.tpointtech.com/c-programming-language-tutorial">C tutorial</a></strong> is designed to guide beginners through the fundamental concepts of C programming, using practical code examples and <strong>exercises</strong> that will help reinforce your learning. Whether you're a student, an aspiring software developer, or someone switching to system-level programming, understanding C gives you a strong foundation for many other languages and technologies.</span></p><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-outline-level: 2;"><strong><span style="font-size: 18.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Why Learn C Programming Language?</span></strong></p><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">C is one of the most powerful and widely used programming languages globally. Known for its speed, efficiency, and close-to-hardware features, C is often the language of choice for developing operating systems, embedded systems, and performance-critical applications.</span></p><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Here are a few reasons to <strong>learn C programming language</strong>:</span></p><ul type="disc"><li class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-list: l6 level1 lfo1; tab-stops: list 36.0pt;"><strong><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Efficiency</span></strong><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">: C provides low-level access to memory and system processes.</span></li><li class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-list: l6 level1 lfo1; tab-stops: list 36.0pt;"><strong><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Portability</span></strong><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">: Programs written in C can run on different machines with little or no modification.</span></li><li class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-list: l6 level1 lfo1; tab-stops: list 36.0pt;"><strong><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Foundation for other languages</span></strong><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">: Languages like C++, Java, and even Python have roots in C.</span></li><li class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-list: l6 level1 lfo1; tab-stops: list 36.0pt;"><strong><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Job Opportunities</span></strong><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">: C is still heavily used in systems programming, embedded development, and hardware interfacing.</span></li></ul><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">This <strong>C tutorial</strong> will take you through a practical path, making sure you don&rsquo;t just read, but also write and run C code.</span></p><div class="MsoNormal" style="margin-bottom: .0001pt; text-align: center; line-height: normal;" align="center"><hr align="center" size="2" width="100%"></div><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-outline-level: 2;"><strong><span style="font-size: 18.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Getting Started with C</span></strong></p><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Before diving into the examples, make sure you have a C compiler installed. You can use <strong>GCC</strong> for Linux/macOS or <strong>MinGW</strong> for Windows. Alternatively, IDEs like <strong>Code::Blocks</strong> or <strong>Dev C++</strong> make setup easier.</span></p><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-outline-level: 3;"><strong><span style="font-size: 13.5pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Your First C Program</span></strong></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">#include &lt;stdio.h&gt;</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">&nbsp;</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">int main() {</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>printf("Hello, World!\");</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>return 0;</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">}</span></p><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal;"><strong><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Explanation</span></strong><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">:</span></p><ul type="disc"><li class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-list: l0 level1 lfo2; tab-stops: list 36.0pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">#include &lt;stdio.h&gt;</span><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';"> is a preprocessor directive that includes the Standard Input Output library.</span></li><li class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-list: l0 level1 lfo2; tab-stops: list 36.0pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">int main()</span><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';"> is the main function from where execution begins.</span></li><li class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-list: l0 level1 lfo2; tab-stops: list 36.0pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">printf()</span><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';"> is used to print text to the screen.</span></li><li class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-list: l0 level1 lfo2; tab-stops: list 36.0pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">return 0;</span><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';"> signifies successful completion of the program.</span></li></ul><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal;"><strong><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Practice Exercise</span></strong><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">:</span></p><ul type="disc"><li class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-list: l5 level1 lfo3; tab-stops: list 36.0pt;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Modify the code to print your name.</span></li><li class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-list: l5 level1 lfo3; tab-stops: list 36.0pt;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Add multiple </span><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">printf()</span><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';"> statements to print your age, location, or a short bio.</span></li></ul><div class="MsoNormal" style="margin-bottom: .0001pt; text-align: center; line-height: normal;" align="center"><hr align="center" size="2" width="100%"></div><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-outline-level: 2;"><strong><span style="font-size: 18.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Variables and Data Types</span></strong></p><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Variables store data, and each variable must have a data type in C.</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">int age = 25;</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">float height = 5.9;</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">char grade = 'A';</span></p><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal;"><strong><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Practice Exercise</span></strong><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">:</span></p><ul type="disc"><li class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-list: l3 level1 lfo4; tab-stops: list 36.0pt;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Declare variables of different data types.</span></li><li class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-list: l3 level1 lfo4; tab-stops: list 36.0pt;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Write a program to accept user input using </span><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">scanf()</span><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';"> and display it.</span></li></ul><div class="MsoNormal" style="margin-bottom: .0001pt; text-align: center; line-height: normal;" align="center"><hr align="center" size="2" width="100%"></div><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-outline-level: 2;"><strong><span style="font-size: 18.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Control Structures: if, else, and switch</span></strong></p><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">C provides standard control structures for decision-making.</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">int number = 10;</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">&nbsp;</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">if (number &gt; 0) {</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>printf("Positive number\");</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">} else {</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>printf("Non-positive number\");</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">}</span></p><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal;"><strong><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Practice Exercise</span></strong><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">:</span></p><ul type="disc"><li class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-list: l8 level1 lfo5; tab-stops: list 36.0pt;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Write a program to check if a number is even or odd.</span></li><li class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-list: l8 level1 lfo5; tab-stops: list 36.0pt;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Use a </span><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">switch</span><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';"> statement to build a simple calculator.</span></li></ul><div class="MsoNormal" style="margin-bottom: .0001pt; text-align: center; line-height: normal;" align="center"><hr align="center" size="2" width="100%"></div><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-outline-level: 2;"><strong><span style="font-size: 18.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Loops in C</span></strong></p><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Loops help you execute a block of code multiple times.</span></p><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-outline-level: 3;"><strong><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">for</span></strong><strong><span style="font-size: 13.5pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';"> loop example:</span></strong></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">for (int i = 1; i &lt;= 5; i++) {</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>printf("%d\", i);</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">}</span></p><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal;"><strong><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Practice Exercise</span></strong><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">:</span></p><ul type="disc"><li class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-list: l4 level1 lfo6; tab-stops: list 36.0pt;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Use a </span><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">while</span><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';"> loop to print numbers from 1 to 10.</span></li><li class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-list: l4 level1 lfo6; tab-stops: list 36.0pt;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Write a program to find the sum of the first 100 natural numbers using a </span><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">for</span><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';"> loop.</span></li></ul><div class="MsoNormal" style="margin-bottom: .0001pt; text-align: center; line-height: normal;" align="center"><hr align="center" size="2" width="100%"></div><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-outline-level: 2;"><strong><span style="font-size: 18.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Functions in C</span></strong></p><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Functions allow you to modularize code.</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">int add(int a, int b) {</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>return a + b;</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">}</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">&nbsp;</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">int main() {</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>int sum = add(5, 3);</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>printf("Sum: %d\", sum);</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>return 0;</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">}</span></p><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal;"><strong><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Practice Exercise</span></strong><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">:</span></p><ul type="disc"><li class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-list: l1 level1 lfo7; tab-stops: list 36.0pt;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Write a function to calculate the factorial of a number.</span></li><li class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-list: l1 level1 lfo7; tab-stops: list 36.0pt;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Write a function that checks if a number is prime.</span></li></ul><div class="MsoNormal" style="margin-bottom: .0001pt; text-align: center; line-height: normal;" align="center"><hr align="center" size="2" width="100%"></div><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-outline-level: 2;"><strong><span style="font-size: 18.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Arrays and Strings</span></strong></p><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Arrays store multiple values of the same type.</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">int numbers[5] = {1, 2, 3, 4, 5};</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">char name[] = "Alice";</span></p><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal;"><strong><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Practice Exercise</span></strong><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">:</span></p><ul type="disc"><li class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-list: l2 level1 lfo8; tab-stops: list 36.0pt;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Write a program to find the largest number in an array.</span></li><li class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-list: l2 level1 lfo8; tab-stops: list 36.0pt;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Write a program to reverse a string.</span></li></ul><div class="MsoNormal" style="margin-bottom: .0001pt; text-align: center; line-height: normal;" align="center"><hr align="center" size="2" width="100%"></div><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-outline-level: 2;"><strong><span style="font-size: 18.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">File Handling in C</span></strong></p><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">C allows reading from and writing to files.</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">FILE *fp = fopen("data.txt", "w");</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">fprintf(fp, "Writing to a file in C!");</span></p><p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New';">fclose(fp);</span></p><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal;"><strong><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Practice Exercise</span></strong><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">:</span></p><ul type="disc"><li class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-list: l7 level1 lfo9; tab-stops: list 36.0pt;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Create a file and write user input into it.</span></li><li class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-list: l7 level1 lfo9; tab-stops: list 36.0pt;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Read the contents of a file and display them on the screen.</span></li></ul><div class="MsoNormal" style="margin-bottom: .0001pt; text-align: center; line-height: normal;" align="center"><hr align="center" size="2" width="100%"></div><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal; mso-outline-level: 2;"><strong><span style="font-size: 18.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Conclusion</span></strong></p><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">This <strong>C tutorial</strong> provides a solid foundation for learning the<strong> <a href="https://www.tpointtech.com/c-programming-language-tutorial">Learn C programming language</a></strong> through hands-on <strong>code examples</strong> and practical <strong>exercises</strong>. Mastering C not only helps you understand how software interacts with hardware but also opens doors to embedded systems, operating systems, and high-performance applications.</span></p><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; line-height: normal;"><span style="font-size: 12.0pt; font-family: 'Cambria','serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';">Continue practicing, explore advanced topics like pointers and memory management, and challenge yourself with real-world problems. Stay consistent, and you&rsquo;ll be writing powerful C programs in no time!</span></p>
C Tutorial with Code Examples and Practice Exercises
Image Source: tpointtech4@gmail.com

disclaimer

Comments

https://themediumblog.com/public/assets/images/user-avatar-s.jpg

0 comment

Write the first comment for this!