Msimbazi Centre Training Institute Information and Communication Technology C-Programming Chapter 1 Overview
Msimbazi Centre Training Institute Information and Communication Technology C-Programming Chapter 1 Overview
Facts about C
C was invented to write an operating system called UNIX.
C is a successor of B language which was introduced around the
early 1970s.
The language was formalized in 1988 by the American National
Standard Institute (ANSI).
The UNIX OS was totally written in C.
Today C is the most widely used and popular System Programming
Language.
Most of the state-of-the-art software have been implemented using
C.
Why Use C?
C was initially used for system development work, particularly the
programs that make-up the operating system. C was adopted as a system
development language because it produces code that runs nearly as fast as
the code written in assembly language. Some examples of the use of C
might be:
Operating Systems
Language Compilers
Assemblers
Text Editors
Print Spoolers
Network Drivers
Modern Programs
Databases
Language Interpreters
Utilities
C Programs
A C program can vary from 3 lines to millions of lines and it should be written into
one or more text files with extension ".c"; for example, hello.c. You can use "vi",
"vim" or any other text editor to write your C program into a file.
This tutorial assumes that you know how to edit a text file and how to
write source code inside a program file.
CHAPTER 2 ENVIORNMENT SETUP
If you want to set up your environment for C programming language, you need the
following two software tools available on your computer, (a) Text Editor and (b)
The C Compiler.
Text Editor
This will be used to type your program. Examples of a few editors include
Windows Notepad, OS Edit command, Brief, Epsilon, EMACS, and vim or vi.
The name and version of text editors can vary on different operating systems. For
example, Notepad will be used on Windows, and vim or vi can be used on
Windows as well as on Linux or UNIX.
Let us look at a simple code that would print the words "Hello World":
#include <stdio.h>
int main()
{
/* my first program in C */
printf("Hello, World! \n");
getchar();
return 0;
}
Msimbazi Centre Training Institute (MCTI)
Page 3
Let us take a look at the various parts of the above program:
4. The next line printf(...) is another function available in C which causes the
message "Hello, World!" to be displayed on the screen.
5. The next line return 0; terminates the main() function and returns the value 0.
printf
(
"Hello, World! \n"
)
;
Semicolons
In a C program, the semicolon is a statement terminator. That is, each individual
statement must be ended with a semicolon. It indicates the end of one logical
entity.
Given below are two different statements:
Identifiers
A C identifier is a name used to identify a variable, function, or any other user-
defined item. An identifier starts with a letter A to Z, a to z, or an underscore ‘_’
followed by zero or more letters, underscores, and digits (0 to 9).
C does not allow punctuation characters such as @, $, and % within
identifiers. C is a case-sensitive programming language. Thus, Manpower
and manpower are two different identifiers in C. Here are some examples of
acceptable identifiers:
Keywords
The following list shows the reserved words in C. These reserved words may
not be used as constants or variables or any other identifier names.
Whitespace in C
A line containing only whitespace, possibly with a comment, is known as a blank
line, and a C compiler totally ignores it.
Whitespace is the term used in C to describe blanks, tabs, newline characters and
comments. Whitespace separates one part of a statement from another and enables
Msimbazi Centre Training Institute (MCTI)
Page 5
the compiler to identify where one element in a statement, such as int, ends and the
next element begins.