0% found this document useful (0 votes)
5 views16 pages

Lecture 3

The document provides an overview of the C programming language, detailing its history, development phases, and basic structure. C was developed in the 1970s and is known for its speed, portability, and efficiency, making it suitable for various applications such as operating systems and embedded systems. The document also explains the compilation process and includes a simple C program example with an explanation of its components.

Uploaded by

madin20232022
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views16 pages

Lecture 3

The document provides an overview of the C programming language, detailing its history, development phases, and basic structure. C was developed in the 1970s and is known for its speed, portability, and efficiency, making it suitable for various applications such as operating systems and embedded systems. The document also explains the compilation process and includes a simple C program example with an explanation of its components.

Uploaded by

madin20232022
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

University of Hafr Al-Batin

Hafr Al-Batin Community College ( HBCC )


Computer Science & Engineering Technology Unit (CSET)

CST121 + CNT 234: Introduction to


Computer Programming

Overview of C Language

Lecture-3
What is C?
A programming language written by
Brian Kernighan and Dennis Ritchie in
1970’s.
It was the language for writing UNIX.
It became the first "portable" language
In recent years C has been used as a
general-purpose language because of its
popularity with programmers.

2
History of C
• In 1972 Dennis Ritchie at Bell Labs writes C and in 1978 the
publication of The C Programming Language by Kernighan &
Ritchie caused a revolution in the computing world
• In 1983, the American National Standards Institute (ANSI)
established a committee to provide a modern, comprehensive
definition of C. The resulting definition, the ANSI standard, or
"ANSI C", was completed late 1988.
• Dialects of C
– Common C
– ANSI C
• ANSI/ ISO 9899: 1990
• Called American National Standards Institute ANSI C

3
History of C
• Evolved from two previous languages: BCPL , B
• BCPL (Basic Combined Programming Language)
used for writing OS & compilers
• B used for creating early versions of UNIX OS
• Both were “typeless” languages **
• C language evolved from B (Dennis Ritchie –
Bell labs)

** Typeless – no data types. Every data item occupied 1 word in memory.


4
Why use C?
• Mainly because it produces code that runs nearly
as fast as code written in assembly language.
Also, it is portable to different computer
architectures.

• Some examples of the use of C :


– Operating Systems
– Embedded Systems
– Assemblers, Compilers and Interpreters
– Device Drivers (e.g., network driver, printer driver)
– Utilities (e.g., antiviruses, disk compressors)
– Application programs (e.g., text editors, games,
graphics, databases)
– etc…
5
Why C is Still Useful?
• Because C provides:
Speed and portability
Efficiency, high performance and high quality
software
flexibility and power
Many high-level and low-level operations → middle level
Stability and small size code
Provide functionality through rich set of function
libraries
Gateway for other professional languages like C →
C++ → Java

Note:
• There are billions of lines of C code available on the Internet.
• Portable programs will run on any machine but….. You may have to re-compile.
• Program correctness and robustness are most important than program
efficiency.
6
Development with C
Writing program in C goes through 6 phases:
1. Editor or IDE is used to write the source code of
program (.c file).
2. Preprocessor includes the available routines to
source code.
3. Compiler translates or converts the source code
into object code (.obj file).
4. Linker resolves external references and produces
executable code (.exe file).
5. Loader loads this executable code into memory.
6. CPU executes or runs the .exe code.
7
Development with C

Figure: Compilation Process in C


8
Basics of C Environment
• C systems consist of 3 parts
– Environment
– Language
– C Standard Library (a rich collection of existing functions )
• Avoid reinventing the wheel
• Software reusability
• Development environment has 6 phases:
1. Edit
2. Pre-processor
3. Compile
4. Link
5. Load
6. Execute 9
Basics of C Environment
Program edited in
Phase 1 Editor Disk Editor and stored
on disk
Preprocessor
Phase 2 Preprocessor Disk program processes
the code
Creates object code
Phase 3 Compiler Disk and stores on disk

Links object code


Phase 4 Linker Disk with libraries and
stores on disk
10
Basics of C Environment
Primary memory
Puts program in
Phase 5 Loader memory

Primary memory
Takes each instruction
Phase 6 CPU and executes it storing
new data values

11
Simple C Program
/* A first C Program*/

1. #include <stdio.h>
2. void main()

3. {

4. printf("Hello World \n");


5. }

12
Simple C Program
• Line 1: #include <stdio.h>
– As part of compilation, the C compiler runs a
program called the C preprocessor. The
preprocessor is able to add and remove code from
your source file.
– In this case, the directive #include tells the
preprocessor to include code from the file stdio.h.
– This file contains declarations for functions that
the program needs to use. A declaration for the
printf function is in this file.

13
Simple C Program
• Line 2: void main()
– This statement declares the main function.
– A C program can contain many functions but must always
have one main function.
– A function is a self-contained module of code that can
accomplish some task.
– Functions are examined later.
– The "void" specifies the return type of main. In this case,
nothing is returned to the operating system.
• Line 3: {
– This opening bracket denotes the start of the program.

14
Simple C Program
• Line 4: printf("Hello World \n");
– printf is a function from a standard C library that is used to
print strings to the standard output, normally your screen.
– The compiler links code from these standard libraries to
the code you have written to produce the final executable.
– The "\n" is a special format modifier that tells the printf to
put a line feed at the end of the line.
– If there were another printf in this program, its string
would print on the next line.
• Line 5: }
– This closing bracket denotes the end of the program.

15
Escape Sequence
• \n new line
• \t tab
• \r carriage return
• \a alert
• \\ backslash
• \” double quote

The combination of a backslash (\) and some character are called


escape sequences because the backslash causes an "escape" or
change from the normal meaning of the characters which follow it,
i.e., the characters are taken as commands rather than as data.
16

You might also like