07 CBCP2101 - Topic03
07 CBCP2101 - Topic03
3 Language
LEARNING OUTCOMES
By the end of this topic, you should be able to:
1. Differentiate the three different types of programming languages, by
levels;
2. Explain briefly on the history of C language development; and
3. Describe the six phases that are involved in developing a program in
C environment.
INTRODUCTION
In Topics 1 and 2, we looked at the basics of program development. We will now
continue exploring programming language in more detail.
Writing programs in machine language is not an easy task for the programmer.
To overcome this problem, many different programming languages have been
created, to enable instructions to be given in forms other than machine language.
These instructions need to be translated into machine language, before a
computer can run them. This topic will give an explanation on the different types
of programming languages. Next, C language and its environment will be
introduced. By the end of this topic, one example of a simple C program will be
discussed.
ACTIVITY 3.1
High-Level
Explanation
Languages
C A universal language that is usually used to write system software or
system applications.
C++ An extension from C language that provides support for object-
oriented programming.
Ada Language that is developed for the Defence Department in the United
States, for its real-time systems.
Lisp For artificial intelligence applications.
Pascal For teaching programming.
Fortran For scientific and engineering applications.
COBOL For processing business data.
ACTIVITY 3.2
Before we continue reading the next topic, create a networked mind map
of the three levels of programming languages that you have just read.
Present that in your tutorial.
SELF-CHECK 3.1
3.2 C LANGUAGE
Let us take a step back to the past, to get a brief history of C language.
The C language history has links with the existence of B and BCPL programming
languages. BCPL is a language that was used to write operating systems and
compilers, which was developed by Martin Richards in the year 1967. In the
1970s, Ken Thompson developed the B language that was used in developing the
UNIX operating system at Bell Laboratories. Based on B language, Dennis Ritchie
developed the C language at Bell Laboratories in 1972. This language was then
used to develop UNIX.
For more information on the history of C programming, visit the web site
http://syazwan.tripod.com/introc.htm or any other relevant sites.
(c) C standard Library ă makes available the supporting functions that can be
reused in program development. Among functions that are available in the
standard library are: mathematical functions like sin( ) and sqrt( ), functions
to do input and output, graphical functions and others.
Figure 3.1 on the next page shows a C development environment. It shows the six
phases involved in the process of developing a C program, which are:
(a) Editing;
(b) Pre-processing;
(c) Compiling;
(d) Linking;
(e) Loading; and
(f) Executing.
SELF-CHECK 3.2
Identify a software that you can use to edit and compile programs.
Program 3.1
#include <stdio.h> B
void main(void) {
printf(“Welcome to OUM!\n”); C
}
Welcome to OUM
Notice however that the file name stdio.h in the pre-processor statement is
surrounded by the symbol < and >. This is actually to let the pre-processor know
that the file is found in the usual place. This usual place is dependent on the
computerÊs environment. For example, in the UNIX environment, the normal place
is stated in the file .profile. In the DOS mode, it is normally stated in the file
autoexec.bat.
The code that is marked as C in Program 3.1 is a function definition. The function
that is defined in the program is called main() function. The main() function is
a special function that is the starting point in the execution of any C program.
Notice that the function definition consists of two parts. The first part is the
function head that provides specific information on the function defined; for
example, function name. The second part is the function body which consists of
statements enclosed in { and }. When a function is called, the statements within
the body will be executed. In the case of main() function in the program 3.1, the
body only contains one statement which is:
printf(“Welcome to OUM!\n”);
This statement is the calling of the function printf(), which is one of the
functions that is available in the C standard library functions. We can call this
function printf() if we need to output a string on the computer screen. In the
statement above, the string “Welcome to OUM!\n” is passed to the printf()
function to be output.
The function will display every character in the string, except the enclosing
double quotes (which is the character „) and the control character \n at the end of
the string. The double quotes are the markers for the start and end of the string.
The control character \n is called the new line character. When this character is
found in the printf() function, it will move the cursor to the beginning of the
next line. The new line character is one of the many control characters in the
printf() function. Every control character will have a specific meaning in the
functions given.
SELF-CHECK 3.3
In Section 3.4, there are symbols that were used in Program 3.1. Can you
explain them briefly?
Symbols Explanation
/*.........*/
#include
{.........}
“\n”
ACTIVITY 3.3
1. Write/edit program 3.1 using a notepad and save the file with the
name atur.c.
WELL
WELCOME
WELCOME TO
WELCOME TO OUM!
C Language Environment
Assembly language Linker
C standard library Loader
Compiler Machine language
Editor