Sunday, March 1, 2015

Let's see how we’ll C!

Course Outline   Next Topic

C is a very good language to start learning the art of computer programming. It’s simple and straight forward.  

Without further ado, let’s start writing your first program.

First you need an IDE (integrated development environment, believe it or not, I still have to Google what this acronym stands for but don't worry you don't need to know). I suggest to use Code::Blocks. Well, CodeBlocks simply build your program. You can write code and run/execute them directly here.

Save this as hello.c.

1
2
3
4
5
#include <stdio.h>
     
main() {     
    printf("Hello World!");   
}
    Line 1 just imports the library we needed. Just imagine libraries as collection of codes that let you use commands defined on them. stdio is the standard library for input/output. It’s one of the basic libraries in C.

    In Line 3, we have the main(). The program executes what is inside the main block.

    Line 4 is the code to print a simple text in C. Semicolon (;) is what you used to terminate a statement or command. It's like a period (.) in English and other languages. But take note, your sentence can be understood without a period (like this one) but your C statement can't without a semicolon It will result to a compilation error. 

    So yeah, basically that would be the skeleton of most C programs. 

    After saving, build and run the program using Code::Blocks. 

    There you have it! Your first hello word program! And I’m sure there are still many to come!

    Course Outline   Next Topic

    No comments:

    Post a Comment