{"id":393591,"date":"2025-11-30T13:51:12","date_gmt":"2025-11-30T12:51:12","guid":{"rendered":"https:\/\/dutable.com\/?p=393591"},"modified":"2025-11-30T14:00:24","modified_gmt":"2025-11-30T13:00:24","slug":"compiling-your-first-c-program-in-unix","status":"publish","type":"post","link":"https:\/\/dutable.com\/compiling-your-first-c-program-in-unix\/","title":{"rendered":"Compiling Your First C Program in Unix: Step-by-Step Guide"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/dutable.com\/compiling-your-first-c-program-in-unix\/#Table_of_Contents\" >Table of Contents<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/dutable.com\/compiling-your-first-c-program-in-unix\/#Introduction_to_Unix_C_Programming\" >Introduction to Unix C Programming<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/dutable.com\/compiling-your-first-c-program-in-unix\/#What_You_Need_Before_You_Begin\" >What You Need Before You Begin<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/dutable.com\/compiling-your-first-c-program-in-unix\/#How_Unix_Handles_Programs\" >How Unix Handles Programs<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/dutable.com\/compiling-your-first-c-program-in-unix\/#Writing_Your_First_C_Program\" >Writing Your First C Program<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/dutable.com\/compiling-your-first-c-program-in-unix\/#Savings_the_Program_in_The_Right_Way\" >Savings the Program in The Right Way<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/dutable.com\/compiling-your-first-c-program-in-unix\/#Introduction_to_GCC_The_GNU_Compiler_Collection\" >Introduction to GCC: The GNU Compiler Collection<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/dutable.com\/compiling-your-first-c-program-in-unix\/#Step-by-Step_Building_a_C_Program\" >Step-by-Step: Building a C Program<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/dutable.com\/compiling-your-first-c-program-in-unix\/#Running_the_Executable_File\" >Running the Executable File<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/dutable.com\/compiling-your-first-c-program-in-unix\/#Mistakes_and_the_Ways_to_overcome_them\" >Mistakes and the Ways to overcome them<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/dutable.com\/compiling-your-first-c-program-in-unix\/#Commenting_and_Making_Code_more_Readable\" >Commenting and Making Code more Readable<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/dutable.com\/compiling-your-first-c-program-in-unix\/#The_Compilation_Stages_An_Overview\" >The Compilation Stages: An Overview<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/dutable.com\/compiling-your-first-c-program-in-unix\/#Execution_Rights_and_File_Permissions\" >Execution Rights and File Permissions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/dutable.com\/compiling-your-first-c-program-in-unix\/#Examples_in_Practice_Introduction\" >Examples in Practice: Introduction<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/dutable.com\/compiling-your-first-c-program-in-unix\/#Tips_for_Debugging\" >Tips for Debugging<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/dutable.com\/compiling-your-first-c-program-in-unix\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n\n<p class=\"wp-block-paragraph\">The first time to compile a C program may be daunting&#8211;it may be a Unix environment where commands, files and terminal operations are unknown. This is however one of the most empowering experiences of any novice programmer. As soon as you have the knowledge of how to translate a simple C file into an executable program, you have the key to the world of systems programming, embedded development, operating systems work, and the myriad other areas of computing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This article takes you through the process step-by-step: how to write your first C program, how to save this program, how to know about compilers such as GCC, how to compile your program, how to run it and how to trouble shoot the most common beginner mistakes. All that is clarified in a simple practical and beginner-based manner so that you can develop confidence instantly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To help you learn even more, here is a resource to aid in your learning of what a c program is and how the language functions at the most simple level.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Table_of_Contents\"><\/span><strong>Table of Contents<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A C Programming on Unix Introduction.<br><\/li>\n\n\n\n<li>What You Need Before You Start.<br><\/li>\n\n\n\n<li>How Unix Handles Programs<br><\/li>\n\n\n\n<li>Writing Your First C Program<br><\/li>\n\n\n\n<li>Program Correction Savings.<br><\/li>\n\n\n\n<li>Getting acquainted with GCC: The GNU Compiler Collection.<br><\/li>\n\n\n\n<li>Step-by-Step: Preparing a C Program.<br><\/li>\n\n\n\n<li>Running the Executable File<br><\/li>\n\n\n\n<li>Mistakes to avoid and the ways out.<br><\/li>\n\n\n\n<li>Commenting and Increasing Code Readability.<br><\/li>\n\n\n\n<li>Learning the Compilation Stages.<br><\/li>\n\n\n\n<li>Execution Rights and file permissions.<br><\/li>\n\n\n\n<li>Practical Sports Beginner and Intermediate.<br><\/li>\n\n\n\n<li>Tips for Debugging<br><\/li>\n\n\n\n<li>Conclusion<br><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Introduction_to_Unix_C_Programming\"><\/span><strong>Introduction to Unix C Programming<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">C and Unix were created simultaneously. True to say, Unix was first rewritten in C in the early 1970s, and it is this combination that computer science has known ever since. Unix offers a highly effective and consistent platform to operate the C language, with the developers having full control over the compile-run cycle.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Unix systems (such as Linux or macOS terminals) can be uncontemplated to newcomers, as everything seems to be run using text commands. These commands are however very logical when disaggregated. Once you get your first C program to compile successfully, you will think of the beauty of the Unix ecosystem clean, controllable, and developer-centered.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_You_Need_Before_You_Begin\"><\/span><strong>What You Need Before You Begin<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Prior to starting, you must have:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>One of the Unix-based Operating Systems<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This includes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Distributions based on Linux (Ubuntu, Fedora, Debian, Mint, etc.).<br><\/li>\n\n\n\n<li>macOS (has Unix roots)<br><\/li>\n\n\n\n<li>Unix servers or cloud terminals (e.g. SSH access to a Linux server)<br><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>A Terminal<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">All the commands will be typed on the terminal.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>A Text Editor<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Unix has numerous editors, including:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>nano (beginner-friendly)<br><\/li>\n\n\n\n<li>vim (fast, but requires education)<br><\/li>\n\n\n\n<li>emacs<br><\/li>\n\n\n\n<li>gui editors such as Vs code (not mandatory, but useful)<br><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>A C Compiler: GCC<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">GCC is usually pre-installed with most Unix systems or it can be installed with ease.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To verify the existence of GCC, write:<br>gcc &#8211;version<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you get a version number, then that is fine.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Otherwise, one can install GCC (under Linux):<br>sudo apt-get build-essential.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">or on MacOS (needs Xcode command-line tools):<br>xcode-select &#8211;install<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_Unix_Handles_Programs\"><\/span><strong>How Unix Handles Programs<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The way Unix treats code to know about compilation:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>C file (.c) &#8212; your source code<br><\/li>\n\n\n\n<li>Compiler &#8211; translates machine code to source code.<br><\/li>\n\n\n\n<li>Object file (.o) &#8211; compiled code.<br><\/li>\n\n\n\n<li>Execution code: a runnable code.<br><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Unix terminal coordinates these steps by use of simple commands. This may seem to be a technical process, but all the steps are foreseeable.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Writing_Your_First_C_Program\"><\/span><strong>Writing Your First C Program<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We will begin with the most basic one: a Hello, World! program.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Open your terminal and type:<br>nano hello.c<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This executes the Nano editor of a new file called <strong>hello.c<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now type the following C code:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">#include &lt;stdio.h&gt;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">int main() {<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;printf(&#8220;Hello, Unix world!\\n&#8221;);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;return 0;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s what each line means:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>importing the standard input\/output library.<br><\/li>\n\n\n\n<li>int main: the beginning of the program.<br><\/li>\n\n\n\n<li>printf: will output any text to the terminal.<br><\/li>\n\n\n\n<li>return 0: informs the operating system that the program has been run successfully.<br><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">This small program already illustrates the style of all C applications.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/dutable.com\/wp-content\/uploads\/2025\/11\/image-435.png\" alt=\"Screenshot of a Unix nano text editor displaying a simple C program that prints &#039;Hello, Unix World!&#039;.\" class=\"wp-image-393593\" title=\"\" srcset=\"https:\/\/dutable.com\/wp-content\/uploads\/2025\/11\/image-435.png 1024w, https:\/\/dutable.com\/wp-content\/uploads\/2025\/11\/image-435-300x300.png 300w, https:\/\/dutable.com\/wp-content\/uploads\/2025\/11\/image-435-150x150.png 150w, https:\/\/dutable.com\/wp-content\/uploads\/2025\/11\/image-435-768x768.png 768w, https:\/\/dutable.com\/wp-content\/uploads\/2025\/11\/image-435-500x500.png 500w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Savings_the_Program_in_The_Right_Way\"><\/span><strong>Savings the Program in The Right Way<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>If you&#8217;re using Nano:<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Press CTRL + O to save<br><\/li>\n\n\n\n<li>Press ENTER to confirm<br><\/li>\n\n\n\n<li>Press CTRL + X to exit<br><\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/dutable.com\/wp-content\/uploads\/2025\/11\/image-436.png\" alt=\"Nano editor screenshot showing the &#039;Write Out&#039; command while saving a C program file named hello.c.\" class=\"wp-image-393594\" title=\"\" srcset=\"https:\/\/dutable.com\/wp-content\/uploads\/2025\/11\/image-436.png 1024w, https:\/\/dutable.com\/wp-content\/uploads\/2025\/11\/image-436-300x300.png 300w, https:\/\/dutable.com\/wp-content\/uploads\/2025\/11\/image-436-150x150.png 150w, https:\/\/dutable.com\/wp-content\/uploads\/2025\/11\/image-436-768x768.png 768w, https:\/\/dutable.com\/wp-content\/uploads\/2025\/11\/image-436-500x500.png 500w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>If using Vim:<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Press Esc<br><\/li>\n\n\n\n<li>Type :wq<br><\/li>\n\n\n\n<li>Press Enter<br><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">You have saved your file <strong>hello.c<\/strong> in your current directory.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can check it using:<br>ls<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Your file should be listed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Introduction_to_GCC_The_GNU_Compiler_Collection\"><\/span><strong>Introduction to GCC: The GNU Compiler Collection<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A widely used compiler in the world is GCC (Gnu Compiler Collection). It converts human readable C code into machine instructions that are comprehended by the CPU.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Why GCC is important:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Free and open-source<br><\/li>\n\n\n\n<li>Very portable (works with virtually any system)<br><\/li>\n\n\n\n<li>Reliable and fast<br><\/li>\n\n\n\n<li>Several languages (C, C++, Fortran, etc.)<br><\/li>\n\n\n\n<li>Develops wise tips to starters.<br><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">When you compile a C program, what you are telling GCC is to translate your .c file into an executable file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step-by-Step_Building_a_C_Program\"><\/span><strong>Step-by-Step: Building a C Program<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To compile <strong>hello.c<\/strong>, run:<br>gcc hello.c -o hello<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s what each part means:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>gcc: the compiler command<br><\/li>\n\n\n\n<li>hello.c: your source file<br><\/li>\n\n\n\n<li>-o hello: output file (your final program) name.<br><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In case the command is completed successfully, there will be no message. This is normal.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To see your new executable you can list files:<br>ls<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now you should see:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>hello.c<br><\/li>\n\n\n\n<li>hello<br><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Running_the_Executable_File\"><\/span><strong>Running the Executable File<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To run your program:<br>.\/hello<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You should see:<br><strong>Hello, Unix world!<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is when you will start your C programming life-cycle when you will see your own code running.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Mistakes_and_the_Ways_to_overcome_them\"><\/span><strong>Mistakes and the Ways to overcome them<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Error 1: Missing Semicolon<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Fix:<\/strong> Add semicolon.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Error 2: Typing errors in Function Names.<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Fix:<\/strong> Check spelling.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Error 3: Missing Header File<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Fix:<\/strong> Add missing header.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Error 4: Saving File of the incorrect extension.<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Fix:<\/strong> Always use .c.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Error 5: Running Denied Permission.<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Fix:<\/strong><strong><br><\/strong> chmod +x hello<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Commenting_and_Making_Code_more_Readable\"><\/span><strong>Commenting and Making Code more Readable<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Good code is readable code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Single-line comment<br>\/\/ This displays a greeting statement.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Multi-line comment<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\/*<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;In this program, a message is printed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;It is of learning simple compilation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">*\/<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Commenting helps:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Late you know your own code.<br><\/li>\n\n\n\n<li>Your intention is comprehended by others.<br><\/li>\n\n\n\n<li>Debugging becomes easier<br><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The_Compilation_Stages_An_Overview\"><\/span><strong>The Compilation Stages: An Overview<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">GCC in fact undertakes four significant stages:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Preprocessing<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">gcc -E hello.c<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Compilation<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">gcc -S hello.c<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Assembly<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">gcc -c hello.c<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Output: hello.o<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Linking<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">gcc hello.o -o hello<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The knowledge of these stages assists in debugging and optimization.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Execution_Rights_and_File_Permissions\"><\/span><strong>Execution Rights and File Permissions<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To view permissions:<br>ls -l<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You might see:<br>-rwxr-xr-x 1 user user 8544 hello<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This breaks down to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>r = read<br><\/li>\n\n\n\n<li>w = write<br><\/li>\n\n\n\n<li>x = execute<br><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">If your file has no execute permission:<br>chmod u+x hello<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/dutable.com\/wp-content\/uploads\/2025\/11\/image-437.png\" alt=\"Unix terminal screenshot showing execution of the compiled C program producing the output &#039;Hello, Unix World!&#039;.\" class=\"wp-image-393595\" title=\"\" srcset=\"https:\/\/dutable.com\/wp-content\/uploads\/2025\/11\/image-437.png 1024w, https:\/\/dutable.com\/wp-content\/uploads\/2025\/11\/image-437-300x300.png 300w, https:\/\/dutable.com\/wp-content\/uploads\/2025\/11\/image-437-150x150.png 150w, https:\/\/dutable.com\/wp-content\/uploads\/2025\/11\/image-437-768x768.png 768w, https:\/\/dutable.com\/wp-content\/uploads\/2025\/11\/image-437-500x500.png 500w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Examples_in_Practice_Introduction\"><\/span><strong>Examples in Practice: Introduction<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example 1: Requesting User input.<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">#include &lt;stdio.h&gt;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">int main() {<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;int age;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;printf(&#8220;Enter your age: &#8220;);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;scanf(&#8220;%d&#8221;, &amp;age);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;printf( you are age years old);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;return 0;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">}<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example 2: Simple Arithmetic Program<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">#include &lt;stdio.h&gt;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">int main() {<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;int a, b;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;printf(&#8220;Enter two numbers: &#8220;);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;scanf(&#8220;%d %d&#8221;, &amp;a, &amp;b);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;printf(&#8220;Sum = %d\\n&#8221;, a + b);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;printf(&#8220;Difference = %d\\n&#8221;, a &#8211; b);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;printf(&#8220;Product = %d\\n&#8221;, a * b);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;return 0;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">}<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example 3: Using Loops<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">#include &lt;stdio.h&gt;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">int main() {<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;for(int i = 1; i &lt;= 5; i++) {<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(&#8220;Iteration %d\\n&#8221;, i);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;return 0;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">}<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Tips_for_Debugging\"><\/span><strong>Tips for Debugging<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Add Print Statements<br><\/li>\n\n\n\n<li>Enable Warnings:<br>gcc -Wall hello.c -o hello<br><\/li>\n\n\n\n<li>Step-by-Step Inspection using gdb<br><\/li>\n\n\n\n<li>Re-check File Paths<br><\/li>\n\n\n\n<li>Check Semicolons, Braces, Parentheses<br><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span><strong>Conclusion<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You have now learned the entire procedure of writing, saving, compiling and executing your first C program within a Unix. you have also learned the GCC functionality, compilation stages, how to debug, and testing your code using real life examples.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is not as hard as it might have appeared in the beginning after you divide it into steps. Unix terminal is one of the most effective tools that a programmer can work with and combining it with the C language gives you complete power over what your computing environment is going to be like- not only running your programs but also running your system.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Knowing these fundamentals will ready you to do more advanced programmation, algorithms, data structures, and even systems engineering. Keep on trying and experiment with more complicated programs and most importantly, always bear in mind, all great programmers started with a simple hello.c.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The first time to compile a C program may be daunting&#8211;it may be a Unix environment where commands, files and terminal operations are unknown. This is however one of the most empowering experiences of any novice programmer. As soon as you have the knowledge of how to translate a simple C file into an executable&#8230;<\/p>\n","protected":false},"author":1905,"featured_media":393598,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4580,4577,12164],"tags":[29087,29848,29847],"class_list":["post-393591","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-education","category-science-technology","category-technology","tag-c-programming","tag-gcc-guide","tag-unix-tutorial"],"_links":{"self":[{"href":"https:\/\/dutable.com\/wp-json\/wp\/v2\/posts\/393591","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dutable.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dutable.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dutable.com\/wp-json\/wp\/v2\/users\/1905"}],"replies":[{"embeddable":true,"href":"https:\/\/dutable.com\/wp-json\/wp\/v2\/comments?post=393591"}],"version-history":[{"count":2,"href":"https:\/\/dutable.com\/wp-json\/wp\/v2\/posts\/393591\/revisions"}],"predecessor-version":[{"id":393604,"href":"https:\/\/dutable.com\/wp-json\/wp\/v2\/posts\/393591\/revisions\/393604"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dutable.com\/wp-json\/wp\/v2\/media\/393598"}],"wp:attachment":[{"href":"https:\/\/dutable.com\/wp-json\/wp\/v2\/media?parent=393591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dutable.com\/wp-json\/wp\/v2\/categories?post=393591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dutable.com\/wp-json\/wp\/v2\/tags?post=393591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}