Pin Me

C Programming For Beginners - Part 8

written by: Noel Kalicharan•edited by: J. F. Amprimoz•updated: 10/2/2008

In this article, we explain what characters are - the basic building blocks of any program. We then show how to write our first C program, a variation of the classic "Hello World" program.

  • slide 1 of 3


    In computer terminology, we use the term character to refer to any one of the following:

    a digit from 0 to 9;

    an uppercase letter from A to Z;

    a lowercase letter from a to z;

    a special symbol like (, ), $, =, <, >, +, -, /, *, etc.

    The following are commonly used terms:

    letter – one of a to z or A to Z

    lowercase letter one of a to z

    uppercase letter one of A to Z

    digit one of 0,1,2,3,4,5,6,7,8,9

    special character any symbol except a letter or a digit

    e.g. +, <, >, $, &, *, /, =

    alphabetic used to refer to a letter

    numeric used to refer to a digit

    alphanumeric used to refer to a letter or a digit

    Characters are the basic building blocks used in writing programs;

    we put characters together to form variables and constants;

    we put variables, constants and special characters to form expressions such as (a + 2.5) * c;

    we add special words such as if, else and while to form statements such as

    if (a > 0) b = a + 2;

    and we put statements together to form programs.

  • slide 2 of 3

    Welcome to C Programming

    We take a quick peek at the C programming language by writing a program to print, on the screen, the message

    Welcome to BrightHub

    One solution is the following

    #include <stdio.h>
    main() {
    printf("Welcome to BrightHub");

    The statement

    #include <stdio.h>

    is called a compiler directive. This simply means that it provides information the compiler needs to compile your program. In C, input/output instructions are provided by means of standard functions stored in a standard library. These functions use variable (and other) declarations stored in a special header file called stdio.h. Any program which uses an input/output instruction (such as printf) must inform the compiler to include the declarations in the file stdio.h with the program. If this is not done, the compiler will not know how to interpret the input/output statements used in the program.

    A C program consists of one or more functions (or, subprograms), one of which must be called main. Our solution consists of just one function so it must be called main. The (round) brackets after main are necessary because, in C, a function name is followed by a list of arguments, enclosed in brackets. If there are no arguments, the brackets must still be present. Here, main has no arguments so the brackets alone are present.

    Every function has a section called the body of the function. The body is where the work of the function is performed. The left and right braces, { and }, are used to define the start and end, respectively, of the body. In C, one or more statements enclosed by { and } is called a block or compound statement.

    The body of main contains one statement:

    printf("Welcome to BrightHub");

    printf is a standard output function which, in this example, takes one argument, a string constant "Welcome to BrightHub". Note that, as with all functions, the argument is enclosed in round brackets. The semicolon is used to indicate the end of the statement. We say the semicolon terminates the statement. When executed, this statement will print

    Welcome to BrightHub

    on the ‘standard output’. For now, take this to mean the screen.