Information Technology Center

Home | About | Comments | Lectures | Notice | Registration

MASTERING C WITH MC KENZIE

Lesson One

A Simple C Program - Hello World

You Will Learn About :

The material provided on this site is part of a complete course in Mastering C Programming. C programming at introductory level is FREE.


The Structure of C

A C program is made up of one or more of functions. A function is a group of related statements. One function must be named main( )

There are rules for all spoken languages. C a computer language also has rules which the programmer must observe.

Here are some to commit to memory.

The Rules

  1. C is case sensitive. Use lowercase or common letters for all functions.
  2. Every C program must have a function called main( )
  3. All functions must begin with an opening brace { and end with a closing brace }
  4. All statements end with a semi-colon

The Source Code

/* Program 1A - Hello Program */

main()
{

   printf("Hello, world");
  
}

Instructions :


Points to Note

Detailed Explanation :

  1. main( ) and printf( ) are written in lower case characters.
  2. Comments must be preceded by /* and ended with */ Do not separated the asterisk from the slashes with a space . This    /    *     will not work
  3. Comments may be written above, below or even within the body of the function called main( ).
  4. The printf( ) function is used to display a message on screen. Double quotes are needed around the message to be displayed.

C does not care how the program is written as long as all of the syntax rules are followed. The next program, Program 1B , looks bad to the reader but not to the C compiler

 

Clear Code

The compiler is the program which converts the code you write ( source code ) into object or machine code which the computer "understands". We need to present our code in a readable format for the benefit of other programmers and ourselves but the computer does not care.

/* Program 1B - Fun Program */ main(){printf("this is fun");}


The Newline Character

The sequence `\n' is C notation for "newline character", which, when printed, skips the terminal to the beginning of the next line. Notice that `\n' represents only a single character.

/* Program 1A - Hello Program */

main()
{

   printf("I am glad \n to be learning C programming");
  
}

The \n newline character forces the words "to be learning C programming" to begin on a new line.


Assignment One


1. Change the contents of the printf( ) string to "Programming is fun"
2. Include your name and address within the same printf() statement but on a new line

 

.......End of Lesson One.......

 

 


Lecturer:

The Tutor
Do you have a question or a comment ?
tutordam@yahoo.com


Home | About | Comments | Lectures | Notice | Registration