First C Program

What is a computer program?

A computer program is set of instructions telling the computer to accomplish a desired task. A task is calculating an equation. A task is printing an output to the screen when asked upon. A task is taking an input and saving it in the memory.

How do we write a computer program for a given task?

You write a computer program using a computer programming language, C is such a language. The language has syntax or set of rules as to how to tell the computer to accomplish a given task.

Can we write a computer program?

Yes. We'll start with the traditional introductory program.
Consider the program below.



/*Project:	First Program */
/*File:		Hello.c */
/*Aim:		Traditional Intro */

#include <stdio.h>

main()
{
	printf("Hello, world\n");
}

What does this program exactly do?

First of all, you will need some time to become familiar with many of the conventions of writing a program. As you start writing programs yourself, you will become familiar with the conventions.

This program prints: Hello, world to the screen or to the console.

I suppose printf("Hello, world\n"); is the instruction telling the computer to print Hello, world to the screen or console. What are the other instructions used for?

/*Project:	First Program */
/*File:		Hello.c */
/*Aim:		Traditional Intro */

The above are comments. Whatever typed inside /* */ are comments. Comments are not instructions, and not part of the program to accomplish tasks. The comments areuseful for the programmer as documentation.

include <stdio.h>

An instruction telling the computer to use the library file stdio.h. We'll discuss more about this later; now just include this in all programs.

main()

An instruction telling the computer to create a main module.

{

A syntax requirement. The compiler needs that in order to properly compile the program.

printf("Hello, world\n");

The instruction telling the computer to print Hello, world.

}

A syntax requirement. The compiler needs that in order to properly compile the program.