Skip to main content

How to compile C program in Linux

Although it is super easy to print "Hello World!" in c program, you might wondering if you've switched to linux first time.
Here is the step by step process to compile and run a c program in linux.

1. Open terminal: (CTRL+ALT+T)

Terminal in Ubuntu 14.04 LTS

2. Change directory to desired location: cd DIRECTORY-NAME


3. Open your file in any text editor: Here I am using vim editor.


4. Vim will look something like this


5. Press "i" for go to insert mode


6. Type a "C" program


7. Press "escape" button then ":wq": Here escape key is used for go to command mode, :w for save, and q for quit. For more about vim commands you can visit here.


8. Now its time to compile the program with GNU compiler: Type "gcc" followed by C program you just typed. Hit enter. If there would by any error in your program it will be displayed. Go back to step 3 and fix them.


9. If a new line displayed without any message then it means program has been compiled successfully.


10. Good news, now its time to run your successfully compiled C program: Press "./a.out" and hit (or politely press) enter button.


11. Congratulations, You've just learned to compile and learn C program in linux.


Now you know how to compile and run a c program in linux.
Share if you feel others who are still programming with windows should also know this.

Comments

Popular posts from this blog

Some tools to make life easier

  O ver time, I’ve discovered that the right tools quietly remove friction from everyday work. From managing documents and media to backups, notes, and creative tasks, these applications save time and mental energy. Most are free or open-source, run locally, and respect user control—making them reliable companions for daily digital life. I. Productivity, Notes & Knowledge Management OneNote – Helps organize notes in a structured way using notebooks and sections, making it easier to revisit ideas even after long gaps. Samsung Notes – Works smoothly on Samsung devices and is especially useful for handwritten notes and quick ideas with the S-Pen. Joplin – Stores notes locally in Markdown format, giving full control over data without forcing cloud dependence. Logseq – Encourages thinking in linked ideas rather than isolated notes, which is useful for long-term learning and journaling. Xournal++ – Makes it easy to annotate PDFs and take handwritten notes, especial...

आलसी लोगों की दस विशेषताएं

  कई वर्ष पहले मैने  सोचा था कि आलस पे कुछ लिखु, लेकिन फिर आलस के कारण लिख नहीं सका था। आज आलसी व्यक्तियों की कुछ विशेषताओं से आपको अवगत कराने जा रहा हूँ। 1. वे झूठ नहीं बोलते है आलसी लोग प्राय: झूठ नहीं बोलते है। इन्हें पूर्ण रूप से यह ज्ञात होता है कि एक झूठ को छिपाने के लिए अनेक झूठों का सहारा लेना पड़ता है, जिससे आलस्य का अस्तित्व खतरे में आ सकता है। अत: इन लोगो को झूठ बोलने की अपेक्षा सच बोलना अधिक प्रिय होता है। 2. वे अधिक वफादार होते हैं गैर आलसी लोगों की अपेक्षा आलसी लोग अधिक वफादार होते हैं। जो स्त्री अपने पति के आलस्य  स्वभाव से परिचित रहती है वो उनके चरित्र के प्रति निश्चिंत रहती है। 3. वे अकारण किसी कार्य को जटिल नहीं बनाते हैं आलसी लोग आसान कार्य को आसान तरीके से ही करते है। वे बिना कारण आसान कार्य को जटिल नहीं बनाते है। 4. वे किसी को नुकसान नहीं पहुचाते हैं आलसी लोग प्राय: समदर्शी होते है। वे सभी जीव-जंतुओं में स्वयं को और स्वयं को सभी जीव-जंतुओं में देखते है। अत: वे किसी भी जीव को नुकसान पहुँचाने कि चेष्टा नहीं करते हैं। ...

दोस्त की शादी में न जाने के दस बहाने

  अक्सर ऐसा होता है कि हमें अपने किसी मित्र के  विवाह में शामिल होने की कोई इच्छा नहीं होती है, लेकिन कोई उचित बहाना ना मिलने के कारण हमें विवाह में शामिल होना पड़ता है। अगली बार जब आप ऐसी दुविधा की स्थिति में हो तो निम्नलिखित में से कोई भी बहाना अपने सुविधानुसार उपयोग कर सकते है।   1. ऑफिस से छुट्टी ना मिलना  आपकी बहुत इच्छा थी अपने  मित्र के विवाह मे शामिल होने की, परंतु कार्यालय से अवकास ना मिलने के कारण आप शामिल नहीं  हो सके। 2. यात्रा टिकट का उपलब्ध ना होना बहुत संभव है कि आपका मित्र भारतीय रेल के टिकट की अनुपलब्धता से परिचित ही होगा। 3. उसी तारिख को परिवार के किसी अन्य सदस्य का किसी और करीबी मित्र का विवाह होना ये बहाना अत्यंत कारगर है और ज्यादातर लोग इसे ही उपयोग करते है। 4. बारिश   अचानक बेमौसम तेज बारिश की वजह से आप घर से निकल ही नहीं सके। 5. भूकंप अगर आपका मित्र एकदम लल्लू है तभी इस बहाने पे विश्वास करेगा। 6. कोरोना पॉजीटिव अगर आपके कोरोना पॉजीटिव होने की बात सुनने के बावजूद भी आपका मित्र विवाह में शामिल होने की जिद कर रहा है तो उसके माता-पित...