Categories
C Programming

Basics of Writing Computer Programs

Overview Writing Computer Programs:

Programs start as a set of instructions written by humans. They start as an idea, which are put into text as a source file, containing source code. The source file is transformed into an object file by the compiler. Then a program called a linker takes the object file and combines it with predefined routines from a standard library and creates an executable.

Wrappers for Computer Programs:

Fortunately you don’t need to run compiler, linker etc individually they are wrapped into one tool. Some editors go further to create an IDE (Integrated Development Environment) that contains an editor, compiler, linker, project manager and debugger.

Actually Writing Computer Programs:

1. Create a place for your program:

mkdir hello

cd hello

2. Write the code

vi hello.c

type:

#include <stdio.h>
int main()
{
printf("Hello World\n");
return(0);
}

3. Run the compiler

Generic Unix C Compiler

cc -g -ohello hello.c

-g : enables debugging

-ohello : tells compiler program is to be called hello

GNU C Compiler

gcc -g -Wall -ohello hello.c

-Wall : turns on warnings

4. Execute the Program

hello

or

./hello