SlideShare a Scribd company logo
CSE 1201
Introduction to Programming - in C
Lecture 1
Programming is to Computer
Science as
Mathematics is to Physics
Introduction
• Lecturers
–
Instructors:
Ms. Aurel Liddell (Room E27)
Mr. Lenandlar Singh
Mr. Rayad Lakhan
Mr. Renard Jacobis,
Mr. Kim Shing
Chong*
3 hrs/week
2 hrs/week
– Tutors (labs):
• Lectures
• Laboratory session
• Recommended Texts:
– The C Programming Language by Kernighan and
Ritchie
– C Programming: A Modern Approach by K.N. King
• Assessments*:
– Individual Assignments/ Labs quizzes
– 1 Group Project
– 2 In-class tests
– Final Exam
10%
10%
20%
60%
* subject to change
Learning Outcomes
At the end of this course, you will be able to:
1. Identify the basic terminology used in computer programming
2. Explain the process and tools used in transforming source code into executable
programs
3. Differentiate between programming language paradigms
4. Write, compile and debug programs in C language.
5. Use different data types in a computer program.
6. Design programs involving decision structures, loops and functions.
7. Explain the difference between call by value and call by reference
8. Discuss the dynamics of memory by the use of pointers.
9. Make appropriate decisions about when to use macros vs functions
10. Use different data structures and create/update basic data files.
11. Explain the difference between computer programming and software
engineering
Outline of Today’s Topics
• Software Categories
• The Evolution of Programming Languages
• History of the C Programming Language
• What happens to your program?
– Compilation, Linking, Execution
A Layered View of the Computer
Application Programs
Word-Processors, Spreadsheets,
Database Software, IDEs,
etc…
System Software
Compilers, Interpreters,Preprocessors,
etc.
Operating System, Device Drivers
Machine with all its hardware
Software Categories
• Application S/w
– Programs written for computer users
• Word-processors, spreadsheets, & other
application packages
• System S/w
– Programs written for computer
systems
• Compilers, operating systems, utility
programs, programming languages …
Software Categories cont’d
System S/w: The Operating System (OS)
Provides several essential services:
– Loading & running application programs
– Allocating memory & processor time
– Providing input & output facilities
– Managing files of information
– Manages low-level interaction with hardware
What is Computer Programming?
• Involves writing instructions for the computer hardware
to execute
• The aim is to achieve the outcome of some task quickly
and accurately while producing the same results every
time, given the same input.
• Performed using a suitable programming language
What is a Programming Language?
• A vocabulary and set of grammatical rules
for instructing a computer to perform
specific tasks
• Each language has a unique set of
keywords (words that it understands) and
a special syntax for organizing program
instructions.
• Programs are converted into machine
language so that the computer can
understand it. There are two ways to do
this:
– compile the program
– interpret the program
The Evolution of Programming Languages
• Machine Language (1940s & ‘50s)
– Uses binary code
– Machine-dependent
– Not portable
• Assembly Language (1950s & ‘60s)
– Uses mnemonics
– Machine-dependent
– Not usually portable
• High-Level Language
– Uses English-like language
– Machine independent
– Portable (but must be compiled for different platforms)
– Examples: Fortran, Pascal, C, C++, Java, etc.
Machine Language
• The representation of a computer program which is actually read
and understood by the computer.
– A program in machine code consists of a sequence of machine instructions.
• Instructions:
– Machine instructions are in binary code
– Instructions specify operations and memory cells involved in the operation
Example:
Operation Address
0010 0000 0000 0100
0100 0000 0000 0101
0011 0000 0000 0110
Assembly Language
• A mnemonic representation of the machine language of a
specific
processor.
• Example:
Load
Add
Store
Price
Tax
Cost
• Is converted to machine code by an assembler.
• Usually, each line of assembly code produces one machine
instruction
(One-to-one correspondence).
• Programming in assembly language is slow and error-prone but is more
efficient in terms of hardware performance.
• It forced the programmer to think in terms of the machine
rather
than in terms of his/her problem.
High-level language
• Developed in the late 1950s & ‘60s
• A programming language which uses statements consisting of English-
like keywords such as "FOR", "PRINT" or “IF“, ... etc.
• Each statement corresponds to several machine language instructions (one-
to-many correspondence).
• The idea was to allow the programmer to think about a problem in terms
familiar to him/her and relevant to the problem rather than have to
worry about the machine.
High-level language
• Data referenced using descriptive names
• Operations can be described using familiar symbols
• Example:
Cost := Price + Tax
• A program called a compiler is used to translate a program written in a high-
level language to machine language.
The History of C
• Unix was originally written in Assembly language.
• Ken Thompson wrote B as a higher level language to enhance Unix.
• However, B was ineffective.
• In 1971 Dennis Ritchie at Bell Laboratories extended B calling it ‘NB’ (newB)
• In 1972-3, ‘NB’ was redesigned and renamed ‘C’
• Originally used to rewrite the UNIX operating system.
• First versions known as “Traditional C” or “Classic C”
• Standardised version approved in 1989 and now called “ANSI C”
(actual standardisation work started in 1983)
The History of C cont’d
• Many new languages are based off of C:
– C++
– Java
– C#
– Perl
• Today, virtually all major operating systems are written in C and/or C++
• Apart from system s/w, C is also used to write application s/w such as word
processing programs, spreadsheet programs, database management
programs, accounting programs, games, educational software, etc.
Characteristics of C
• Lies just above Assembly Language and just below High Level Languages such as
BASIC, PASCAL and FORTRAN in the Programming Language type hierarchy
• C is a compiled language
• 32 keywords in “ANSI C” and a rich collection of existing functions (operations/procedures)
called the “C Standard Library”
• C is case sensitive. That is, the same letter in lowercase or uppercase is treated as
being
different
• Simple, flexible, loose procedural language, but requires attention to detail. Easy to
make mistakes
• Executable produced are fast (when compared with programs written in languages such
as
Visual Basic, Fox Pro, Java etc.)
• Used to implement solutions for a wide variety of programming problems
• C is hardware-independent and highly portable. That is, the same carefully designed
The C Standard Library
• A rich collection of pre-written functions
• There are two primary aspects to learning C
– Learning the C language itself
– Learning how to use the functions in the C Standard Library (encourages
software
reusability)
• The C Standard Library is the foundation of “building blocks” - the collections
of functions - that make up C programs
• C programs usually consist of the following functions:
– Those from The C Standard Library
– Functions you create yourself
– Functions other people have created and made available to you
The Software Development Life Cycle
1. Define/Understand problem
2. Analyse problem to obtain requirements
3. Design solution(s): Components, Storage Mechanism, Interface and
Algorithms
4. Programming: use suitable programming language to transform design into
executable computer program
5. Test: run executable to determine if program solves problem and satisfies
requirements
6. Deploy application: hand over program to users
7. Maintenance: corrective, preventative and perfective
The Programming Life Cycle
1. Understand problem
2. Decompose problem into manageable units (top-down stepwise refinement
is recommended)
3. Design algorithm, flowchart and pseudo code, and storage mechanism for
solution
4. Encode algorithm using an appropriate programming language
5. Compilation: use appropriate compiler to compile computer program into
executable
program (involves linking etc)
6. Testing: Test module/function to determine if it satisfies requirments. Also know
as unit testing
7. Repeat 3 – 6 as required.
My First C Program
Jane Doe*/
January 29, 2020 */
1. /* Programmer:
2. /* Date:
3.
4. #include <stdio.h>
5.
6. int main(int argc, char
*argv[]) 7. {
8. printf(“Hello, World!n”);
9. return 0;
10. }
The Anatomy
of a
C program
• Lines 1 & 2: /* Programmer:
/* Date:
Jane Doe */
January 29, 2020 */
Comments are enclosed in /* … */ constructs. The first two lines provide
useful information about the person who wrote the program, in addition to the date on
which it was written.
• Line 4: #include <stdio.h>
As part of compilation, the C compiler runs a program called the C preprocessor.
The preprocessor adds and removes 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 and symbolic constants that the program needs to
use. A
declaration for the printf function is in this file.
• Line 6: int main(int argc, char *argv[])
This statement declares the main function. A C program can containmany functions
but must always have one main function, which is the entry point into the program. A
function is a self-contained module of code that can accomplish some task. The “int"
specifies the return type the function. In this case, an Integer value is returned to the
operating system.
• Line 7: {
This opening bracket denotes the start of the program. It is used to denote the
beginning of a block of program statements.
• Line 8: 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
code tells the printf function to
advance to the next line after printing the message.
• Line 9: return 0;
This statement that tells the calling program - the loader (a program run by the
Operating System) that the program/function was ended successfully.
• Line 10: }
Closing bracket denotes the end of the main function block (and end of the program).
What happens when we run a C program?
The Life Cycle of a C Program
Transforming a C program into an
executable.
1. Editor / IDE: A program is written in a text editor, e.g. Notepad then saved with a ‘.c’
extension. The file produced is called the source code.
2. Preprocess : The source code is passed to the preprocessor according to the
preprocessor directives. Preprocessor directives begin with a hash sign (#), such as
#include and #define. They indicate that certain manipulations are to be performed
BEFORE compilation. A typical manipulation would be to include in the source code, the
contents of the file defined by #include <filename> (Typically #include references header
files which contain the declaration of functions and other objects). The preprocessor is
also responsible for removing comments from the source code.
Transforming a C program into an
executable.
3. Compile: The preprocessed file is then passed to a program called the C Compiler which
translates the source code into machine readable code. Compilation involves analyzing
the language structure of the source code to determine if it is valid. Once no errors are
detected, the compiler generates a binary file called an object code file (aka ‘.o’ or ‘.obj’
file) and stores it on disk. If any compiler errors are received, no object code file will be
generated. However, if only warnings were received, an object code file will be generated.
Object code is not directly executable, though. In order to make an executable, the
implementation code for all of the library functions that were #included into the file need to
be added in. This is the job of the linker.
Transforming a C program into an
executable.
3. Compile cont’d: During compilation, the Compiler checks for objects or functions that
were not locally defined in the source code, for example, the printf() function. It then
produces an entry in the object code file's symbol table saying that printf() has an
“unresolved reference” (or simply that no implementation of the function was found).
4. Linker: The object file is then passed to the Linker which sees the unresolved reference
to undefined objects or functions such as printf() and searches the available libraries for
their implementation. When found, it links those unresolved references to their
corresponding library implementation and produces an executable file (.out or .exe file)
and stores it on disk. If any linker errors are received, no executable file will be
generated.
Transforming a C program into an
executable.
5. Loader: The loader puts the executable file in memory.
6. CPU: The CPU takes the executable and runs each instruction until the program is
fully
executed.
A gentle conclusion
That's it!!! 
To get the most out of this class, you should get access to both a text editor
and a C compiler.
A C compiler, Borland Dev C++, is available in the Computer Science
Laboratory. Dev C++ comes with a text editor and compiler. Otherwise, use
one of the text editors, installed on your computer or try an online complier.
Instructions for practicing your first program will be covered in the first
laboratory session.

More Related Content

Similar to CSE_1201_Lecture_1_Introduction_to_Programming_0fd134f8149173dfa0821f1575f733a1.pdf.pptx (20)

PPT
C PROGRAMMING
Stalongiles Philip
 
PPTX
Diploma ii cfpc u-1 introduction to c language
Rai University
 
PDF
Programming in c
ankitjain851
 
PDF
Introduction to C programming
Kathmandu University
 
PPTX
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
Malikireddy Bramhananda Reddy
 
PPTX
C language unit-1
Malikireddy Bramhananda Reddy
 
PPTX
C languaGE UNIT-1
Malikireddy Bramhananda Reddy
 
DOCX
Programming In C- (1)jhgjhgjhgjhghj.docx
Dpak Chavan
 
PPTX
Introduction to C Programming
Selvaraj Seerangan
 
DOCX
C Unit 1 notes PREPARED BY MVB REDDY
Rajeshkumar Reddy
 
PDF
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
Subramanyambharathis
 
PPTX
Introduction to c language
BAKRANIYA KALPESH
 
PPTX
C_Programming_Notes_ICE
Gilbert NZABONITEGEKA
 
PPT
Introduction
Kamran
 
PPTX
C Programming UNIT 1.pptx
Mugilvannan11
 
PDF
ICT1002-W8-LEC-Introduction-to-C.pdf
ssuser33f16f
 
PPT
Book ppt
FALLEE31188
 
PPT
Synapseindia dot net development computer programming
Synapseindiappsdevelopment
 
PPTX
Unit ii
sathisaran
 
PPTX
C programming presentation(final)
aaravSingh41
 
C PROGRAMMING
Stalongiles Philip
 
Diploma ii cfpc u-1 introduction to c language
Rai University
 
Programming in c
ankitjain851
 
Introduction to C programming
Kathmandu University
 
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
Malikireddy Bramhananda Reddy
 
Programming In C- (1)jhgjhgjhgjhghj.docx
Dpak Chavan
 
Introduction to C Programming
Selvaraj Seerangan
 
C Unit 1 notes PREPARED BY MVB REDDY
Rajeshkumar Reddy
 
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
Subramanyambharathis
 
Introduction to c language
BAKRANIYA KALPESH
 
C_Programming_Notes_ICE
Gilbert NZABONITEGEKA
 
Introduction
Kamran
 
C Programming UNIT 1.pptx
Mugilvannan11
 
ICT1002-W8-LEC-Introduction-to-C.pdf
ssuser33f16f
 
Book ppt
FALLEE31188
 
Synapseindia dot net development computer programming
Synapseindiappsdevelopment
 
Unit ii
sathisaran
 
C programming presentation(final)
aaravSingh41
 

More from DrmagedAlazony (7)

PPTX
Computer_Programming_Lecture_6Control Structures2.pptx
DrmagedAlazony
 
PPTX
compare between odoo and ilpAsscompare between odoo and ilpAss
DrmagedAlazony
 
PPTX
عرض-ال10-ادوات Business Analysis Business Analysis
DrmagedAlazony
 
PDF
1 Agile.pdf bv 1 Agile.pdf pmp agile
DrmagedAlazony
 
PDF
PMP-Exam-Prep-3.0-Course-Outline-with-ECO-2023_merged.pdf
DrmagedAlazony
 
PDF
WORK GROUP 1- Creating a High - Performing Team.pdf
DrmagedAlazony
 
PDF
project Management PMP PMBOK 6th MP PMBOK 6th
DrmagedAlazony
 
Computer_Programming_Lecture_6Control Structures2.pptx
DrmagedAlazony
 
compare between odoo and ilpAsscompare between odoo and ilpAss
DrmagedAlazony
 
عرض-ال10-ادوات Business Analysis Business Analysis
DrmagedAlazony
 
1 Agile.pdf bv 1 Agile.pdf pmp agile
DrmagedAlazony
 
PMP-Exam-Prep-3.0-Course-Outline-with-ECO-2023_merged.pdf
DrmagedAlazony
 
WORK GROUP 1- Creating a High - Performing Team.pdf
DrmagedAlazony
 
project Management PMP PMBOK 6th MP PMBOK 6th
DrmagedAlazony
 
Ad

Recently uploaded (20)

PPTX
Photo chemistry Power Point Presentation
mprpgcwa2024
 
PPTX
A Case of Identity A Sociological Approach Fix.pptx
Ismail868386
 
PPTX
SYMPATHOMIMETICS[ADRENERGIC AGONISTS] pptx
saip95568
 
DOCX
DLL english grade five goof for one week
FlordelynGonzales1
 
PPTX
How to use _name_search() method in Odoo 18
Celine George
 
PPTX
JSON, XML and Data Science introduction.pptx
Ramakrishna Reddy Bijjam
 
PPTX
How Physics Enhances Our Quality of Life.pptx
AngeliqueTolentinoDe
 
PPTX
How to Create & Manage Stages in Odoo 18 Helpdesk
Celine George
 
PDF
Wikinomics How Mass Collaboration Changes Everything Don Tapscott
wcsqyzf5909
 
PPTX
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
PPTX
How to use grouped() method in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
 
PDF
CAD25 Gbadago and Fafa Presentation Revised-Aston Business School, UK.pdf
Kweku Zurek
 
PDF
Our Guide to the July 2025 USPS® Rate Change
Postal Advocate Inc.
 
PPTX
Urban Hierarchy and Service Provisions.pptx
Islamic University of Bangladesh
 
PDF
Free eBook ~100 Common English Proverbs (ebook) pdf.pdf
OH TEIK BIN
 
PPTX
How to Configure Refusal of Applicants in Odoo 18 Recruitment
Celine George
 
PPTX
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
PDF
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
 
PPT
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
ErlizaRosete
 
Photo chemistry Power Point Presentation
mprpgcwa2024
 
A Case of Identity A Sociological Approach Fix.pptx
Ismail868386
 
SYMPATHOMIMETICS[ADRENERGIC AGONISTS] pptx
saip95568
 
DLL english grade five goof for one week
FlordelynGonzales1
 
How to use _name_search() method in Odoo 18
Celine George
 
JSON, XML and Data Science introduction.pptx
Ramakrishna Reddy Bijjam
 
How Physics Enhances Our Quality of Life.pptx
AngeliqueTolentinoDe
 
How to Create & Manage Stages in Odoo 18 Helpdesk
Celine George
 
Wikinomics How Mass Collaboration Changes Everything Don Tapscott
wcsqyzf5909
 
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
How to use grouped() method in Odoo 18 - Odoo Slides
Celine George
 
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
 
CAD25 Gbadago and Fafa Presentation Revised-Aston Business School, UK.pdf
Kweku Zurek
 
Our Guide to the July 2025 USPS® Rate Change
Postal Advocate Inc.
 
Urban Hierarchy and Service Provisions.pptx
Islamic University of Bangladesh
 
Free eBook ~100 Common English Proverbs (ebook) pdf.pdf
OH TEIK BIN
 
How to Configure Refusal of Applicants in Odoo 18 Recruitment
Celine George
 
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
 
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
ErlizaRosete
 
Ad

CSE_1201_Lecture_1_Introduction_to_Programming_0fd134f8149173dfa0821f1575f733a1.pdf.pptx

  • 1. CSE 1201 Introduction to Programming - in C Lecture 1 Programming is to Computer Science as Mathematics is to Physics
  • 2. Introduction • Lecturers – Instructors: Ms. Aurel Liddell (Room E27) Mr. Lenandlar Singh Mr. Rayad Lakhan Mr. Renard Jacobis, Mr. Kim Shing Chong* 3 hrs/week 2 hrs/week – Tutors (labs): • Lectures • Laboratory session • Recommended Texts: – The C Programming Language by Kernighan and Ritchie – C Programming: A Modern Approach by K.N. King • Assessments*: – Individual Assignments/ Labs quizzes – 1 Group Project – 2 In-class tests – Final Exam 10% 10% 20% 60% * subject to change
  • 3. Learning Outcomes At the end of this course, you will be able to: 1. Identify the basic terminology used in computer programming 2. Explain the process and tools used in transforming source code into executable programs 3. Differentiate between programming language paradigms 4. Write, compile and debug programs in C language. 5. Use different data types in a computer program. 6. Design programs involving decision structures, loops and functions. 7. Explain the difference between call by value and call by reference 8. Discuss the dynamics of memory by the use of pointers. 9. Make appropriate decisions about when to use macros vs functions 10. Use different data structures and create/update basic data files. 11. Explain the difference between computer programming and software engineering
  • 4. Outline of Today’s Topics • Software Categories • The Evolution of Programming Languages • History of the C Programming Language • What happens to your program? – Compilation, Linking, Execution
  • 5. A Layered View of the Computer Application Programs Word-Processors, Spreadsheets, Database Software, IDEs, etc… System Software Compilers, Interpreters,Preprocessors, etc. Operating System, Device Drivers Machine with all its hardware
  • 6. Software Categories • Application S/w – Programs written for computer users • Word-processors, spreadsheets, & other application packages • System S/w – Programs written for computer systems • Compilers, operating systems, utility programs, programming languages …
  • 7. Software Categories cont’d System S/w: The Operating System (OS) Provides several essential services: – Loading & running application programs – Allocating memory & processor time – Providing input & output facilities – Managing files of information – Manages low-level interaction with hardware
  • 8. What is Computer Programming? • Involves writing instructions for the computer hardware to execute • The aim is to achieve the outcome of some task quickly and accurately while producing the same results every time, given the same input. • Performed using a suitable programming language
  • 9. What is a Programming Language? • A vocabulary and set of grammatical rules for instructing a computer to perform specific tasks • Each language has a unique set of keywords (words that it understands) and a special syntax for organizing program instructions. • Programs are converted into machine language so that the computer can understand it. There are two ways to do this: – compile the program – interpret the program
  • 10. The Evolution of Programming Languages • Machine Language (1940s & ‘50s) – Uses binary code – Machine-dependent – Not portable • Assembly Language (1950s & ‘60s) – Uses mnemonics – Machine-dependent – Not usually portable • High-Level Language – Uses English-like language – Machine independent – Portable (but must be compiled for different platforms) – Examples: Fortran, Pascal, C, C++, Java, etc.
  • 11. Machine Language • The representation of a computer program which is actually read and understood by the computer. – A program in machine code consists of a sequence of machine instructions. • Instructions: – Machine instructions are in binary code – Instructions specify operations and memory cells involved in the operation Example: Operation Address 0010 0000 0000 0100 0100 0000 0000 0101 0011 0000 0000 0110
  • 12. Assembly Language • A mnemonic representation of the machine language of a specific processor. • Example: Load Add Store Price Tax Cost • Is converted to machine code by an assembler. • Usually, each line of assembly code produces one machine instruction (One-to-one correspondence). • Programming in assembly language is slow and error-prone but is more efficient in terms of hardware performance. • It forced the programmer to think in terms of the machine rather than in terms of his/her problem.
  • 13. High-level language • Developed in the late 1950s & ‘60s • A programming language which uses statements consisting of English- like keywords such as "FOR", "PRINT" or “IF“, ... etc. • Each statement corresponds to several machine language instructions (one- to-many correspondence). • The idea was to allow the programmer to think about a problem in terms familiar to him/her and relevant to the problem rather than have to worry about the machine.
  • 14. High-level language • Data referenced using descriptive names • Operations can be described using familiar symbols • Example: Cost := Price + Tax • A program called a compiler is used to translate a program written in a high- level language to machine language.
  • 15. The History of C • Unix was originally written in Assembly language. • Ken Thompson wrote B as a higher level language to enhance Unix. • However, B was ineffective. • In 1971 Dennis Ritchie at Bell Laboratories extended B calling it ‘NB’ (newB) • In 1972-3, ‘NB’ was redesigned and renamed ‘C’ • Originally used to rewrite the UNIX operating system. • First versions known as “Traditional C” or “Classic C” • Standardised version approved in 1989 and now called “ANSI C” (actual standardisation work started in 1983)
  • 16. The History of C cont’d • Many new languages are based off of C: – C++ – Java – C# – Perl • Today, virtually all major operating systems are written in C and/or C++ • Apart from system s/w, C is also used to write application s/w such as word processing programs, spreadsheet programs, database management programs, accounting programs, games, educational software, etc.
  • 17. Characteristics of C • Lies just above Assembly Language and just below High Level Languages such as BASIC, PASCAL and FORTRAN in the Programming Language type hierarchy • C is a compiled language • 32 keywords in “ANSI C” and a rich collection of existing functions (operations/procedures) called the “C Standard Library” • C is case sensitive. That is, the same letter in lowercase or uppercase is treated as being different • Simple, flexible, loose procedural language, but requires attention to detail. Easy to make mistakes • Executable produced are fast (when compared with programs written in languages such as Visual Basic, Fox Pro, Java etc.) • Used to implement solutions for a wide variety of programming problems • C is hardware-independent and highly portable. That is, the same carefully designed
  • 18. The C Standard Library • A rich collection of pre-written functions • There are two primary aspects to learning C – Learning the C language itself – Learning how to use the functions in the C Standard Library (encourages software reusability) • The C Standard Library is the foundation of “building blocks” - the collections of functions - that make up C programs • C programs usually consist of the following functions: – Those from The C Standard Library – Functions you create yourself – Functions other people have created and made available to you
  • 19. The Software Development Life Cycle 1. Define/Understand problem 2. Analyse problem to obtain requirements 3. Design solution(s): Components, Storage Mechanism, Interface and Algorithms 4. Programming: use suitable programming language to transform design into executable computer program 5. Test: run executable to determine if program solves problem and satisfies requirements 6. Deploy application: hand over program to users 7. Maintenance: corrective, preventative and perfective
  • 20. The Programming Life Cycle 1. Understand problem 2. Decompose problem into manageable units (top-down stepwise refinement is recommended) 3. Design algorithm, flowchart and pseudo code, and storage mechanism for solution 4. Encode algorithm using an appropriate programming language 5. Compilation: use appropriate compiler to compile computer program into executable program (involves linking etc) 6. Testing: Test module/function to determine if it satisfies requirments. Also know as unit testing 7. Repeat 3 – 6 as required.
  • 21. My First C Program Jane Doe*/ January 29, 2020 */ 1. /* Programmer: 2. /* Date: 3. 4. #include <stdio.h> 5. 6. int main(int argc, char *argv[]) 7. { 8. printf(“Hello, World!n”); 9. return 0; 10. }
  • 23. • Lines 1 & 2: /* Programmer: /* Date: Jane Doe */ January 29, 2020 */ Comments are enclosed in /* … */ constructs. The first two lines provide useful information about the person who wrote the program, in addition to the date on which it was written. • Line 4: #include <stdio.h> As part of compilation, the C compiler runs a program called the C preprocessor. The preprocessor adds and removes 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 and symbolic constants that the program needs to use. A declaration for the printf function is in this file. • Line 6: int main(int argc, char *argv[]) This statement declares the main function. A C program can containmany functions but must always have one main function, which is the entry point into the program. A function is a self-contained module of code that can accomplish some task. The “int" specifies the return type the function. In this case, an Integer value is returned to the operating system.
  • 24. • Line 7: { This opening bracket denotes the start of the program. It is used to denote the beginning of a block of program statements. • Line 8: 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 code tells the printf function to advance to the next line after printing the message. • Line 9: return 0; This statement that tells the calling program - the loader (a program run by the Operating System) that the program/function was ended successfully. • Line 10: } Closing bracket denotes the end of the main function block (and end of the program).
  • 25. What happens when we run a C program? The Life Cycle of a C Program
  • 26. Transforming a C program into an executable. 1. Editor / IDE: A program is written in a text editor, e.g. Notepad then saved with a ‘.c’ extension. The file produced is called the source code. 2. Preprocess : The source code is passed to the preprocessor according to the preprocessor directives. Preprocessor directives begin with a hash sign (#), such as #include and #define. They indicate that certain manipulations are to be performed BEFORE compilation. A typical manipulation would be to include in the source code, the contents of the file defined by #include <filename> (Typically #include references header files which contain the declaration of functions and other objects). The preprocessor is also responsible for removing comments from the source code.
  • 27. Transforming a C program into an executable. 3. Compile: The preprocessed file is then passed to a program called the C Compiler which translates the source code into machine readable code. Compilation involves analyzing the language structure of the source code to determine if it is valid. Once no errors are detected, the compiler generates a binary file called an object code file (aka ‘.o’ or ‘.obj’ file) and stores it on disk. If any compiler errors are received, no object code file will be generated. However, if only warnings were received, an object code file will be generated. Object code is not directly executable, though. In order to make an executable, the implementation code for all of the library functions that were #included into the file need to be added in. This is the job of the linker.
  • 28. Transforming a C program into an executable. 3. Compile cont’d: During compilation, the Compiler checks for objects or functions that were not locally defined in the source code, for example, the printf() function. It then produces an entry in the object code file's symbol table saying that printf() has an “unresolved reference” (or simply that no implementation of the function was found). 4. Linker: The object file is then passed to the Linker which sees the unresolved reference to undefined objects or functions such as printf() and searches the available libraries for their implementation. When found, it links those unresolved references to their corresponding library implementation and produces an executable file (.out or .exe file) and stores it on disk. If any linker errors are received, no executable file will be generated.
  • 29. Transforming a C program into an executable. 5. Loader: The loader puts the executable file in memory. 6. CPU: The CPU takes the executable and runs each instruction until the program is fully executed.
  • 30. A gentle conclusion That's it!!!  To get the most out of this class, you should get access to both a text editor and a C compiler. A C compiler, Borland Dev C++, is available in the Computer Science Laboratory. Dev C++ comes with a text editor and compiler. Otherwise, use one of the text editors, installed on your computer or try an online complier. Instructions for practicing your first program will be covered in the first laboratory session.