ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

C programming in Linux

Updated on April 5, 2011

For you guys (and gals) out there who wants to explore C programming in Linux, you'll be delighted to know that I'll be publishing a number of hubs dedicated to this topic. I've been programming in C for more than 10 years and I'm hoping that I can transfer this knowledge via easy-to-follow and easy-to-understand hubs.

In this hub, being the first one, I'll quickly show you the coverage that I expect to cover across the different hubs. As an intro, I'll show you how to get you setup with Linux and the C compiler called "gcc" that we'll be using. Overtime, I'll keep updating this hub so that it'll have clickable links to the hubs discussing each specific topic.

Please understand that even though we are using Linux here to create our C programs, you should not have much trouble using them on when programming C using other systems like Windows, Mac or others.

Here are the topics I wish to cover:

Formal introduction to C programming

Programming fundamentals in C

Functions in C

  • User-defined functions. Library functions. External user-defined functions. Command-line arguments.

Controlling program flow

  • Loops. If-Else. Switch-Case. Goto.


  • Single and Multi-dimensional.

Abstract data structure

  • Structure. Union. Enum.


  • Variable. Function pointers.


  • Print debugging. Debugger.

Right, let's get started, let's get your Linux setup...

Getting Linux

Today, Linux is packaged and distributed from a lot of sources on the Internet, these are called "Linux distributions" or "distros" in geek-speak. Technically, you'll not only be installing Linux in your computer but also a bunch of applications that go with the distro; like a window manager, file editor programs, package/program and file managers, web browsers like Firefox and many more.

To see what are the available distros, point your web browser to Scroll down a bit and locate on the right-hand side of the page a list of the popular distros ranked according to the number of hits per day (HPD). It's wise to pick one from among the top ones like Ubuntu or Fedora or Debian since that means many people are using them which would tend to mean that they're stable and highly supported.

I'm using a Debian-based distro called "Joli OS". Therefore if you're using a Debian-based distro like Ubuntu, the commands I use here should apply to you directly. If not, however, you should not have any trouble finding out the equivalent for your chosen distro. If you're having trouble with any of the commands I use, just drop me a comment below and I'll be happy to answer.

Most distros should already ship the C compiler and linker programs that we need. If, however, they're not available, it should be trivial to install them.

What do we need?

Basically, other than Linux, you'll need the following:

  1. Terminal - a command-line interface where you enter commands or run programs
  2. C compiler - we'll use the free and open-source compiler called GCC
  3. Linker - we'll use the free and open-source linker from a package called "BINUTILS"
  4. Text editor - any text editor that you like; I use "vim".

The terminal

I'll be using extensively the terminal so this is a good time to fire up (start up) that terminal program in your Linux box. To start a Terminal or Console, try to find it under Applications --> System or Applications --> Utilities. It'll be called "Terminal" or "Console" or "Konsole".

Below is a screenshot of a terminal called "Konsole" in a distro called "Kubuntu".

GCC C compiler

To test if you have the C compiler installed, simply type the following command on a terminal or console:

gcc --version

If you don't have the compiler installed, simply install it using a package manager that comes with your distro. In a Debian-based system, you can install this easily using the terminal using the following command: (In the example below I'm installing gcc version 4.3, you can safely install other versions if you like.)

sudo apt-get install gcc-4.3


Next is to check if you already have the linker installed, please enter the command below:

ld --version

As in the compiler described above, if you don't have the linker installed, you can install it using your distro's package manager or enter the commands in the terminal:

sudo apt-get install binutils

Text editor

We're almost done... now we'll need a text editor which we'll use to write our programs. As I've mentioned above, I'm using "vim", however, you are very much welcome and encouraged to choose a text editor that you feel like using. I will make some suggestions, however.

I would choose an editor with the following features:

  1. Syntax highlighting - Since you'll be writing C programs, it'd be helpful if the editor can colorize or highlight certain words (aka "syntax") in our program. This will help us prevent some really common typing mistakes.
  2. Light-weight - You will most likely be switching between your editor and the terminal to run your programs as you progress therefore you would want an editor that's not processor-heavy and memory-hungry; unless of course you have tons of CPU and memory power at your disposal.
  3. Built-in compile and run functions - Most editors designed for programmers will have a feature that allows you to compile and run your programs from within the editor itself. Most of these editors are called "IDE" or Integrated Development Environment. You'll have the advantage of not having to switch between your editor and terminal when programming which eases your life a bit.
  4. Powerful search functions - As your program gets longer, it'll help you a lot if you can quickly and flexibly search through your code. Some editors also offer a function that lets you jump to a certain line number in your code. And most editors even offer a search and replace function which replaces some text automatically.
  5. Macros support - This is an advanced feature that you might not use at the start. However as you get more experienced with writing code, you'll notice that often you will be constantly repeating some keystrokes in various lines of your code. A "macro" is a function that allows you to save those keystrokes so that you can replay them on a different line in your code; a real time-saver.

Some of the popular text editor of choice when programming C:

  1. ViM -
  2. Geany -
  3. Nano -
  4. Eclipse -
  5. Emacs -

All good!

So there you have it! I hope this hub has helped you get ready for C programming in Linux. (...and the sleepless nights ahead... just kidding!)


    0 of 8192 characters used
    Post Comment

    No comments yet.


    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at:

    Show Details
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the or domains, for performance and efficiency reasons. (Privacy Policy)
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)