ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

First Program in C Programming Language

Updated on July 14, 2018
rajkishor09 profile image

Raj is an ardent coder who loves exploring new technology. He is an IT pro with 9 years of exp in C#, Angular, React, Vue.

learn to program in c language
learn to program in c language

You might be thinking that you have learnt lot about C language background and now eagerly want to write your first program in C. To do so first of all you need a C compiler, I have been using Turbo C++ compiler for this purpose. Why Turbo C++ compiler why not Turbo C compiler? Because Turbo C++ compiler supports both C & C++ program and if you want to learn C++, you don’t need to change your compiler. One more thing, Turbo C++ compiler provides mouse support which Turbo C compiler doesn’t.

I assume that you have installed C compiler in your PC and now want to try your first program. Here is an example of your first C program which has been developed using Turbo C++ compiler.

How to Write Program in C

#include <stdio.h>

void main()
{
printf("Welcome to C");
}

How to Compile and Run C Program

Just type the above line in the C editor and press Alt + F9 to compile that program. If there is any mistakes, it will show “Error” message otherwise it will show “Success” message. Now press Ctrl + F9 to run compiled program and you will see similar output. If you cannot see anything then press Alt + F5 to see output window.

How Turbo C editor looks when you run it. I use Turbo C compiler on Windows 7
How Turbo C editor looks when you run it. I use Turbo C compiler on Windows 7
You learnt how to program in C and its time to see the result. People start their program with "hello world" program but I start with "welcome".
You learnt how to program in C and its time to see the result. People start their program with "hello world" program but I start with "welcome".

How to Program With C, an Explanation

Let’s understand each and every line of this program. The very first line #include <stdio.h> tells the compiler to include a header filestdio.h” in the program. Header file in C is nothing but collection of various functions. Here we are using "printf()" library function from"stdio.h" header file. The next line is "void main()" which is the beginning of the program. Every program must have a "main()" because program starts execution from this function (read more about main function here). But what does the keyword void means before the main(). This means that main function will not return any value to the compiler. I know this is tough to understand now; these things will be discussed in detailed in function page.

The curly open and close braces { } defines the scope of the “main()” function means “main()” function’s boundaries. The line between curly braces printf("Hello, World!"); is the one of function defined in stdio.h whose job is to print message specified in double quotation. At the end of the line there is a semicolon (;) which is the end of that statement. C statements always end with a semicolon (;).

One thing you should keep in your mind that in C program, instructions declared in “main()”, are executed from top to bottom. To understand it better let’s extend the above program.

How to write program in c

#include<stdio.h>
#include<conio.h>

void main()
{
clrscr();
printf("Welcome to C. ");
printf("C is a Programming Language. ");
printf("Hello! How are you?");
getch();
}

C Program Output

Sample C program code for new learner. It's a great language which can teach you lots of thing.
Sample C program code for new learner. It's a great language which can teach you lots of thing. | Source

How to Program With C, an Extended Explanation

The top two lines include two header files “stdio.h” and “conio.h” respectively. The “stdio.h” header file contains “printf()” and “conio.h” file contains “clrscr()” and “getch()”. The “clrscr()” function clears the output screen, means any output shown by previously run program will be erased and that is why we always put them at the beginning. Next is three “printf()” statements which will print three different messages. The “getch()” waits for a keyboard input and if we press any key on keyboard the program exits. So we don’t need to press Alt + F5 to see the output as we did in above program.

The uses of “getch()” function will be discussed later in detail.

How to Program in C Language Poll.

Did this help you to write your first C Program?

See results

© 2009 RAJKISHOR SAHU

Comments

    0 of 8192 characters used
    Post Comment

    • profile image

      mikeydcarroll67 

      3 years ago

      I love the tutorial that you have written!

    • profile image

      Padma 

      4 years ago

      Very useful

    • profile image

      meehell 

      5 years ago

      cool

    • unixunited profile image

      unixunited 

      6 years ago

      Nice, Turbo C++ is old though, I would recommend at least using Codeblocks.

    • Java Programs profile image

      Java Programs 

      6 years ago from India

      Great Hub ..... I really think C or C++ are some of the first languages to learn. Initially I started working with C book and then moved to C++. By the time I started learning Java, it was really easy to apply what I had already learned and quickly pick it up.

    • profile image

      Khader 

      6 years ago

      Thankssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss

    • profile image

      jojie 

      6 years ago

      thanks its too easy to understand

    • profile image

      prince roy 

      6 years ago

      yeh i think it is the best language that i learn

    • profile image

      Jeffcas 

      6 years ago

      guys can you help me create a program that can compute for the percentage of a grade pleeeaaseee!.. thanks

    • profile image

      paul 

      6 years ago

      nice.. this site could help me on my course (information technology) specially the programming languages

      God bless you rajkishor09

    • profile image

      jatin 

      6 years ago

      very usefull site

    • profile image

      Deepak 

      6 years ago

      Cool i am unable to run my program because i have written studio.h instead of stdio.h .After watching this i have run my program

    • profile image

      Mukesh K Sharma 

      6 years ago

      my output is more than one page long but i can see only one the last page ..how to view the other pages of my output

    • profile image

      neri 

      7 years ago

      thank you it helps me :)

    • profile image

      gros 

      7 years ago

      hi my prof asked me to do a program the out put is like this;

      0

      0

      0

      0

      0

      0

      0

      0

      0

      0

      [1] Bottom

      [2] Top

      if u press 1 the output will be like this

      0

      0

      0

      0

      0

      0

      0

      0

      0

      1

      [1] Bottom

      [2] Top

      then if u press 2

      another out put will be like this

      1

      0

      0

      0

      0

      0

      0

      0

      1

      it is continues until it will be like this

      1

      1

      1

      1

      1

      1

      1

      1

      1

      1

    • profile image

      liz 

      7 years ago

      Easy to understand.....I like it.

    • profile image

      Keerthi 

      7 years ago

      Verry useful site,thanx the creater

    • profile image

      Himesh 

      7 years ago

      yeah its easy 2 undrstnd...!

    • profile image

      surya 

      7 years ago

      very easy to understand.....thanks to hubpages

    • profile image

      mani 

      7 years ago

      easy way to develop software skills this procedure

    • profile image

      VAJITH 

      7 years ago

      ITS EASY FOR BEGINERS TO KNOW ABT :C"

    • profile image

      arun 

      7 years ago

      this is useful for our study and proggramming

    • profile image

      shashi 

      7 years ago

      its easy to understand

    • profile image

      ahnsel 

      8 years ago

      eoooww!!!!mor power guys!!!god bless!b careful??..

    • profile image

      silpa 

      8 years ago

      Its very usefull hub.or we can call it as Knowledge Repository.

    • profile image

      NAMRATA KALRA 

      8 years ago

      GOOD

    • profile image

      kaleem toofan 

      8 years ago

      i just love dis site

    • nekros729 profile image

      nekros729 

      8 years ago

      Another hello world, but there are quite a few links. ;-)

    • profile image

      ammarajamal 

      8 years ago

      it is the most interesting site,which gives lots of information rgarding computer

    • profile image

      puarl 

      8 years ago

      how we understand program

    • brad4l profile image

      brad4l 

      9 years ago from USA

      Cool Hub :)I really think C or C++ are some of the best first languages to learn. I started working through a C book and then switched to C++. By the time I started learning Java, it was really easy to apply what I had already learned to Java and quickly pick it up.

    working

    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, hubpages.com 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: https://hubpages.com/privacy-policy#gdpr

    Show Details
    Necessary
    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 googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
    Features
    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)
    Marketing
    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.
    Statistics
    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)