SlideShare a Scribd company logo
1 of 48
Overview
 Introduction to Computer
 Program and Programming Languages
 Types of Programming Languages
 Low-Level Languages
 Assembly languages
 High-Level Languages
 History of Programming Languages
 Translators
 Compiler
 Interpreter
 Typical C Program Development Environment
 The C Programming Language
 Characteristics of C language
 Basic Program Structure in C Language
1
Introduction
 Computer
A computer is an electronic device which is capable to
• receive the data,
• process the data, and
• provide results
according to a set of instructions
 Program
A program is a set of instructions of a computer language, where each
instruction tells the computer to do something:
For example,
• get two numbers as input,
• add these numbers,
• print the sum as output
2
Programming Languages
 Programming Language
 A programming language defines the rules for writing instructions
 Programmers write instructions in a programming language
 Types of Programming Languages
A number of programming languages are in use today and are
generally categorized as follows:
 Low-Level Languages
 Assembly languages
 High-Level Languages
3
Types of Languages
 Low-Level language or Machine/Binary Language
 This language consists of binary numbers to perform a task
 Machine language is directly understandable to the computer
 Machine languages are machine dependent (i.e., a particular machine
language can be used on only one type of computer)
 Programming in machine-language is very slow, tiresome and error prone
for the programmers
4
Types of Languages
 Assembly language
 It was developed to overcome the problems with machine language
 Assembly language uses English-like abbreviations to programming, such as
ADD for adding numbers
 As the assembly language is not the machine own’s language, so translators
were developed called assemblers
 Assemblers translate the assembly-language programs into the machine
language programs
5
Types of Languages
 High level language
 In early programming languages, the programmers had to write many
instructions to perform a single task
 The high-level languages use a single instruction to perform many tasks
 Compilers or interpreters are used as translators to convert high-level
language programs into machine language
 C, C++, Visual Basic, Visual C++, Visual C#, Python and Java are the most
commonly used high-level programming languages today
6
Types of translators
 Compiler
 Interpreter
7
Translators and Types
 Translator
 A translator is used convert a high level language program
(source code) into machine language (object code)
Source code object code
 Types of translators
 Compiler
 Interpreter
8
Compiler vs. Interpreter
 Compiler
 A compiler first reads the whole source code, and converts
it into a its equivalent machine language, if there are no
errors(bugs)
 Reports a list of errors, if errors in the source code
 Faster translation
 C, C++, C# etc. are the examples of compiled languages
9
Compiler vs. Interpreter
 Interpreter
 An interpreter performs line by line translation
 It first reads the first line of the source code, and converts it into a its
equivalent machine code (if no error), then the second line, and so on
 If there is error, it reports it and the user has to correct it, and after this,
the source code to object code translation occurs
 Slower translation than compiler
 Java, Python etc. are called interpreted languages
10
Why study programming Languages?
 In 1967, Sammet, an American computer scientist and one of the
developers of the COBOL programming language, reported 120
programming languages commonly used
 Today , these languages are many more
 Most programmers never use more than a few, some limit their
career to just on or two
 The goal in learning about a language is its fundamental design
concepts and how this affects its implementation
11
12
https://www.tiobe.com/tiobe-index/
Programming Languages Popularity
Programming Domains
 Scientific applications(Fortran)
 Business Applications(COBOL)
 Artificial Intelligence(LISP, Prolog)
 System Programming(C )
 Web software (HTML, PHP, Java)
 General Purpose (Python)
13
14
The Ideal Way to Do Computing
 The ideal way to ask computer to do something is to order it in a
natural language e.g.
 I want to view this webpage
 Calculate my annual tax
 etc.
 However, today’s computer’s are not intelligent enough to
understand our orders in natural language
15
Where We Are in Computers?
 At the very basic level, computers use the concept of an electrical pulse
 Low voltage is represented as 0
 High voltage is represented as 1
 To instruct a computer, we need ask the computer in the language of 0s and
1s commonly known as machine language
 For example, 5 is a number in natural language, so in the language of
0s and 1s, it becomes 101
 In Today’s computing, we use a high-level language to instruct the
computer
 The compiler translates these instructions into the machine language
16
Where are we going?
 The next step in computing is to use natural language over a high-level
language
 But we are many more years away from it
 A lot of research needs to be carried out before we actually see this
 Until then our task is to use high-level languages in its best possible
ways
Program & Its Various Aspects
17
18
What is Programming?
 When we say “programming” we are actually referring
to the science of transforming our intentions in a
high-level programming language
19
Many Aspects of Programming
 Programming is controlling
 computer does exactly what you tell it to do
 Programming is teaching
 computer can only “learn” to do new things if you tell it how
 Programming is problem solving
 always trying to make computer do something useful — i.e., finding
an optimal travel route
 Programming is creative
 must find a good solution out of many possibilities
20
Many Aspects of Programming
 Programming is modelling
 describe salient (relevant) properties and behaviours of a system
of components (objects)
 Programming is abstraction
 identify important features without getting lost in detail
 Programming is concrete
 must provide detailed instructions to complete task
C-Language
 History & characteristics of C language
21
History of C language
 C language was developed by Dennis Ritchie and Ken Thompson in
1972 at Bell Labs where they were working on Unix Operating System
 Dennis Ritchie is known as the founder of the C language
 C was developed to add additional features to its earlier
languages such as B, BCPL, etc.
 It inherits many features of B and BCPL languages
22
Characteristics of C language
1. C is a General Purpose Programming Language
- This means that C language can be used to write a variety of
applications
2. C is a structured programming language
- This means that when you program in C language, a problem is
divided into several small units called functions
3. C is a simple language
- This means that C language is easy to use and has a vast
collection of keywords, operators, built-in functions and data
types
23
Characteristics of C language
4. C is case sensitive language
- This means that in C language the lower case letters are
different from upper case letters
5. C is portable language
-This means that a program written in C language can be run on
different hardware platforms
24
Characteristics of C language
6.C is a flexible language
-This means that C language can be used like a high level
language and like a low level language
7. C is easily available language
-The C software is easy to access and can be easily installed
on a user computer within a few minutes
25
Characteristics of C language
8. C is easily debugged language
 The C is easy to debug
 The C compiler detects syntax errors quickly and easily and
displays the errors along with the line numbers of the code and
the error message
9. C has a number of in-built memory management functions that save
memory and improve the efficiency of the program
10. C has a rich set of library functions for various arithmetic and
trigonometric calculations
26
C-Program Development Environment
(IDE)
27
C IDE
 A C program development environment is called IDE(Integrated
Development Environment)
 Many IDEs available today and some are as follows
 DEVCpp
 Microsoft Visual Studio
 Eclipse
 NetBeans
 Code::Blocks
 etc.
 We use DEVCpp, for C program development in this course
28
C Program Execution Phases
 C program goes through six phases to be executed. These
are as follows:
 Edit
 Preprocess
 Compile
 Link
 Load
 Execute
29
C Program Execution Phases
30
C Program Execution Phases
31
Execution Phases
 Phase 1: Editing/Creating a Program
 Phase 1 consists of editing a file
 To edit a file, we use Dev C++ IDE
 A C program is typed or coded in the IDE
 After coding, the program is stored on a hard disk
 A C program file name should end with the .c extension
 Phases 2 : Preprocessing the Program
 In C language, a preprocessor program is executed automatically
before compilation begins
 Here the C preprocessor calls the preprocessor directives(e.g.
#include<…>)
32
Execution Phases
 Phases 3 : Compiling the Program
 The compiler translates the c program code called source code into
machine language-code called object code
 The compiler translates the C program into machine-language code
 To compile the program, we use the compile command in the IDE
 Phase 4: Linking
 A linker links the object code for the missing functions to produce an
executable image
33
Execution Phases
 Phase 5: Loading
 Before a program can be executed, the program must first be placed in
memory
 This is done by the loader, which takes the executable image from disk
and transfers it to memory
 Additional components from shared libraries that support the program
are also loaded
 Phase 6: Execution
 Finally, the computer, under the control of its CPU, executes the
program one instruction at a time
 To load and execute the program, we run the program in the IDE
34
Basic Program Structure in C
35
Basic Program Structure in C Language
36
#include<stdio.h>
int main()
{
// program statement_1;
// program statement_2
…
return 0;
}
Writing Program in C using DEVCpp IDE
37
Steps to follow:
1. Click on File
2. Select New, and
3. Click on Source File
4. Start coding in the source file(in the figure, sample example)
5. Save it with a name(e.g., first.c)
6. Compile, and
7. Run
Writing Program in C using DEVCpp IDE
38
Sample
Program
C Program Example
#include<stdio.h>
int main()
{
printf("Welcome to C language");
return 0;
}
39
Program output:
Welcome to C language
Example: A simple C Program
#include<stdio.h>
int main()
{
printf("Welcome Studentsn");
Printf(“This is C language statement”);
return 0;
}
40
Program output:
Welcome Students
This is C language statement
Escape Sequence in C
41
Escape sequence
 Escape sequence is a set of characters followed by backslash (),
which has a particular meaning for the compiler to do something
with the output statement
 For example, the escape sequence n means newline, which causes
the cursor to position to the beginning of the next line on the
screen
 C language supports the following escape sequences
42
Escape sequence
43
b for backspace, remove one character at the back
’ single quote, insert a single-quote character in a string
Escape Sequence Example
#include<stdio.h>
int main()
{
printf(“This isn C language statement n”);
printf(“Thist ist Ct languaget statement n”);
printf(“ Thisa isa Ca languagea statement n”);
printf(“ ab n”);
printf(“ This is ”C language” statement n”);
printf(“ ’A’ for Apple n”);
printf(“ Hib n”);
return 0;
}
44
Escape Sequence Example…
45
Program output:
This is
C language statement
This is C language statement
This (alert) is (alert) C (alert) language (alert) statement
ab
This is ”C language” statement
‘A’ for Apple
H
Program Comments in C
46
Comments
 Comments are used to document a program:
 Improve program readability and help other people read and understand
your program
 Dot cause the computer to perform any action when the program is run
 Ignored by the C compiler and do not cause any machine-language object
code to be generated
 Types of Comments:
 Single-line comments e.g. //This is first C program
 Multi-line comments e.g. /* This is first C program
Author: Ali
Dated: October 20, 2020 */
47
Example: Comments
// A first program in C
/* Author: Ali
Dated: October 05, 2020
*/
#include<stdio.h>
int main()
{
printf(“This is C language statement”);
return 0;
}
48
Program output:
This is C language statement

More Related Content

What's hot

Assembly language programming
Assembly language programmingAssembly language programming
Assembly language programming
himhk
 
Basic programming concepts
Basic programming conceptsBasic programming concepts
Basic programming concepts
salmankhan570
 
1. over view and history of c
1. over view and history of c1. over view and history of c
1. over view and history of c
Harish Kumawat
 

What's hot (20)

C notes for exam preparation
C notes for exam preparationC notes for exam preparation
C notes for exam preparation
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Chapter 01
Chapter 01Chapter 01
Chapter 01
 
Assembly language programming
Assembly language programmingAssembly language programming
Assembly language programming
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Basic programming concepts
Basic programming conceptsBasic programming concepts
Basic programming concepts
 
Programming Fundamentals lecture 1
Programming Fundamentals lecture 1Programming Fundamentals lecture 1
Programming Fundamentals lecture 1
 
Computer Languages.
Computer Languages.Computer Languages.
Computer Languages.
 
Generations of programming_language.kum_ari11-1-1-1
Generations of programming_language.kum_ari11-1-1-1Generations of programming_language.kum_ari11-1-1-1
Generations of programming_language.kum_ari11-1-1-1
 
Introduction to C Language
Introduction to C LanguageIntroduction to C Language
Introduction to C Language
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Program & language generation
Program & language generationProgram & language generation
Program & language generation
 
1. over view and history of c
1. over view and history of c1. over view and history of c
1. over view and history of c
 
Computer programming languages
Computer programming languagesComputer programming languages
Computer programming languages
 
Programming languages
Programming languagesProgramming languages
Programming languages
 
Types of Programming Languages
Types of Programming LanguagesTypes of Programming Languages
Types of Programming Languages
 
structured programming Introduction to c fundamentals
structured programming Introduction to c fundamentalsstructured programming Introduction to c fundamentals
structured programming Introduction to c fundamentals
 
C programming presentation for university
C programming presentation for universityC programming presentation for university
C programming presentation for university
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
 
fundamentals of c
fundamentals of cfundamentals of c
fundamentals of c
 

Similar to Introduction to Computer

C Unit 1 notes PREPARED BY MVB REDDY
C Unit 1 notes PREPARED BY MVB REDDYC Unit 1 notes PREPARED BY MVB REDDY
C Unit 1 notes PREPARED BY MVB REDDY
Rajeshkumar Reddy
 
Learn c programming language in 24 hours allfreebooks.tk
Learn c programming language in 24 hours   allfreebooks.tkLearn c programming language in 24 hours   allfreebooks.tk
Learn c programming language in 24 hours allfreebooks.tk
ragulasai
 
Introduction to Programming Concepts By Aamir Saleem Ansari
Introduction to Programming Concepts By Aamir Saleem AnsariIntroduction to Programming Concepts By Aamir Saleem Ansari
Introduction to Programming Concepts By Aamir Saleem Ansari
Tech
 

Similar to Introduction to Computer (20)

CS3251-_PIC
CS3251-_PICCS3251-_PIC
CS3251-_PIC
 
C.pdf
C.pdfC.pdf
C.pdf
 
Lecture 1-3.ppt
Lecture 1-3.pptLecture 1-3.ppt
Lecture 1-3.ppt
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Introduction to Computer Programming (general background)
Introduction to Computer Programming (general background)Introduction to Computer Programming (general background)
Introduction to Computer Programming (general background)
 
Ppt 1
Ppt 1Ppt 1
Ppt 1
 
Software programming and development
Software programming and developmentSoftware programming and development
Software programming and development
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Unit 1
Unit 1Unit 1
Unit 1
 
Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7
 
Introduction to c language
Introduction to c language Introduction to c language
Introduction to c language
 
C lecture notes new
C lecture notes newC lecture notes new
C lecture notes new
 
C Unit 1 notes PREPARED BY MVB REDDY
C Unit 1 notes PREPARED BY MVB REDDYC Unit 1 notes PREPARED BY MVB REDDY
C Unit 1 notes PREPARED BY MVB REDDY
 
Learn c programming language in 24 hours allfreebooks.tk
Learn c programming language in 24 hours   allfreebooks.tkLearn c programming language in 24 hours   allfreebooks.tk
Learn c programming language in 24 hours allfreebooks.tk
 
C programme presentation
C programme presentationC programme presentation
C programme presentation
 
Fundamentals of Programming Chapter 2
Fundamentals of Programming Chapter 2Fundamentals of Programming Chapter 2
Fundamentals of Programming Chapter 2
 
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdfINTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
 
Introduction to Programming Concepts By Aamir Saleem Ansari
Introduction to Programming Concepts By Aamir Saleem AnsariIntroduction to Programming Concepts By Aamir Saleem Ansari
Introduction to Programming Concepts By Aamir Saleem Ansari
 
Introduction to programming language (basic)
Introduction to programming language (basic)Introduction to programming language (basic)
Introduction to programming language (basic)
 

Recently uploaded

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 

Recently uploaded (20)

Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food Additives
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 

Introduction to Computer

  • 1. Overview  Introduction to Computer  Program and Programming Languages  Types of Programming Languages  Low-Level Languages  Assembly languages  High-Level Languages  History of Programming Languages  Translators  Compiler  Interpreter  Typical C Program Development Environment  The C Programming Language  Characteristics of C language  Basic Program Structure in C Language 1
  • 2. Introduction  Computer A computer is an electronic device which is capable to • receive the data, • process the data, and • provide results according to a set of instructions  Program A program is a set of instructions of a computer language, where each instruction tells the computer to do something: For example, • get two numbers as input, • add these numbers, • print the sum as output 2
  • 3. Programming Languages  Programming Language  A programming language defines the rules for writing instructions  Programmers write instructions in a programming language  Types of Programming Languages A number of programming languages are in use today and are generally categorized as follows:  Low-Level Languages  Assembly languages  High-Level Languages 3
  • 4. Types of Languages  Low-Level language or Machine/Binary Language  This language consists of binary numbers to perform a task  Machine language is directly understandable to the computer  Machine languages are machine dependent (i.e., a particular machine language can be used on only one type of computer)  Programming in machine-language is very slow, tiresome and error prone for the programmers 4
  • 5. Types of Languages  Assembly language  It was developed to overcome the problems with machine language  Assembly language uses English-like abbreviations to programming, such as ADD for adding numbers  As the assembly language is not the machine own’s language, so translators were developed called assemblers  Assemblers translate the assembly-language programs into the machine language programs 5
  • 6. Types of Languages  High level language  In early programming languages, the programmers had to write many instructions to perform a single task  The high-level languages use a single instruction to perform many tasks  Compilers or interpreters are used as translators to convert high-level language programs into machine language  C, C++, Visual Basic, Visual C++, Visual C#, Python and Java are the most commonly used high-level programming languages today 6
  • 7. Types of translators  Compiler  Interpreter 7
  • 8. Translators and Types  Translator  A translator is used convert a high level language program (source code) into machine language (object code) Source code object code  Types of translators  Compiler  Interpreter 8
  • 9. Compiler vs. Interpreter  Compiler  A compiler first reads the whole source code, and converts it into a its equivalent machine language, if there are no errors(bugs)  Reports a list of errors, if errors in the source code  Faster translation  C, C++, C# etc. are the examples of compiled languages 9
  • 10. Compiler vs. Interpreter  Interpreter  An interpreter performs line by line translation  It first reads the first line of the source code, and converts it into a its equivalent machine code (if no error), then the second line, and so on  If there is error, it reports it and the user has to correct it, and after this, the source code to object code translation occurs  Slower translation than compiler  Java, Python etc. are called interpreted languages 10
  • 11. Why study programming Languages?  In 1967, Sammet, an American computer scientist and one of the developers of the COBOL programming language, reported 120 programming languages commonly used  Today , these languages are many more  Most programmers never use more than a few, some limit their career to just on or two  The goal in learning about a language is its fundamental design concepts and how this affects its implementation 11
  • 13. Programming Domains  Scientific applications(Fortran)  Business Applications(COBOL)  Artificial Intelligence(LISP, Prolog)  System Programming(C )  Web software (HTML, PHP, Java)  General Purpose (Python) 13
  • 14. 14 The Ideal Way to Do Computing  The ideal way to ask computer to do something is to order it in a natural language e.g.  I want to view this webpage  Calculate my annual tax  etc.  However, today’s computer’s are not intelligent enough to understand our orders in natural language
  • 15. 15 Where We Are in Computers?  At the very basic level, computers use the concept of an electrical pulse  Low voltage is represented as 0  High voltage is represented as 1  To instruct a computer, we need ask the computer in the language of 0s and 1s commonly known as machine language  For example, 5 is a number in natural language, so in the language of 0s and 1s, it becomes 101  In Today’s computing, we use a high-level language to instruct the computer  The compiler translates these instructions into the machine language
  • 16. 16 Where are we going?  The next step in computing is to use natural language over a high-level language  But we are many more years away from it  A lot of research needs to be carried out before we actually see this  Until then our task is to use high-level languages in its best possible ways
  • 17. Program & Its Various Aspects 17
  • 18. 18 What is Programming?  When we say “programming” we are actually referring to the science of transforming our intentions in a high-level programming language
  • 19. 19 Many Aspects of Programming  Programming is controlling  computer does exactly what you tell it to do  Programming is teaching  computer can only “learn” to do new things if you tell it how  Programming is problem solving  always trying to make computer do something useful — i.e., finding an optimal travel route  Programming is creative  must find a good solution out of many possibilities
  • 20. 20 Many Aspects of Programming  Programming is modelling  describe salient (relevant) properties and behaviours of a system of components (objects)  Programming is abstraction  identify important features without getting lost in detail  Programming is concrete  must provide detailed instructions to complete task
  • 21. C-Language  History & characteristics of C language 21
  • 22. History of C language  C language was developed by Dennis Ritchie and Ken Thompson in 1972 at Bell Labs where they were working on Unix Operating System  Dennis Ritchie is known as the founder of the C language  C was developed to add additional features to its earlier languages such as B, BCPL, etc.  It inherits many features of B and BCPL languages 22
  • 23. Characteristics of C language 1. C is a General Purpose Programming Language - This means that C language can be used to write a variety of applications 2. C is a structured programming language - This means that when you program in C language, a problem is divided into several small units called functions 3. C is a simple language - This means that C language is easy to use and has a vast collection of keywords, operators, built-in functions and data types 23
  • 24. Characteristics of C language 4. C is case sensitive language - This means that in C language the lower case letters are different from upper case letters 5. C is portable language -This means that a program written in C language can be run on different hardware platforms 24
  • 25. Characteristics of C language 6.C is a flexible language -This means that C language can be used like a high level language and like a low level language 7. C is easily available language -The C software is easy to access and can be easily installed on a user computer within a few minutes 25
  • 26. Characteristics of C language 8. C is easily debugged language  The C is easy to debug  The C compiler detects syntax errors quickly and easily and displays the errors along with the line numbers of the code and the error message 9. C has a number of in-built memory management functions that save memory and improve the efficiency of the program 10. C has a rich set of library functions for various arithmetic and trigonometric calculations 26
  • 28. C IDE  A C program development environment is called IDE(Integrated Development Environment)  Many IDEs available today and some are as follows  DEVCpp  Microsoft Visual Studio  Eclipse  NetBeans  Code::Blocks  etc.  We use DEVCpp, for C program development in this course 28
  • 29. C Program Execution Phases  C program goes through six phases to be executed. These are as follows:  Edit  Preprocess  Compile  Link  Load  Execute 29
  • 30. C Program Execution Phases 30
  • 31. C Program Execution Phases 31
  • 32. Execution Phases  Phase 1: Editing/Creating a Program  Phase 1 consists of editing a file  To edit a file, we use Dev C++ IDE  A C program is typed or coded in the IDE  After coding, the program is stored on a hard disk  A C program file name should end with the .c extension  Phases 2 : Preprocessing the Program  In C language, a preprocessor program is executed automatically before compilation begins  Here the C preprocessor calls the preprocessor directives(e.g. #include<…>) 32
  • 33. Execution Phases  Phases 3 : Compiling the Program  The compiler translates the c program code called source code into machine language-code called object code  The compiler translates the C program into machine-language code  To compile the program, we use the compile command in the IDE  Phase 4: Linking  A linker links the object code for the missing functions to produce an executable image 33
  • 34. Execution Phases  Phase 5: Loading  Before a program can be executed, the program must first be placed in memory  This is done by the loader, which takes the executable image from disk and transfers it to memory  Additional components from shared libraries that support the program are also loaded  Phase 6: Execution  Finally, the computer, under the control of its CPU, executes the program one instruction at a time  To load and execute the program, we run the program in the IDE 34
  • 36. Basic Program Structure in C Language 36 #include<stdio.h> int main() { // program statement_1; // program statement_2 … return 0; }
  • 37. Writing Program in C using DEVCpp IDE 37 Steps to follow: 1. Click on File 2. Select New, and 3. Click on Source File 4. Start coding in the source file(in the figure, sample example) 5. Save it with a name(e.g., first.c) 6. Compile, and 7. Run
  • 38. Writing Program in C using DEVCpp IDE 38 Sample Program
  • 39. C Program Example #include<stdio.h> int main() { printf("Welcome to C language"); return 0; } 39 Program output: Welcome to C language
  • 40. Example: A simple C Program #include<stdio.h> int main() { printf("Welcome Studentsn"); Printf(“This is C language statement”); return 0; } 40 Program output: Welcome Students This is C language statement
  • 42. Escape sequence  Escape sequence is a set of characters followed by backslash (), which has a particular meaning for the compiler to do something with the output statement  For example, the escape sequence n means newline, which causes the cursor to position to the beginning of the next line on the screen  C language supports the following escape sequences 42
  • 43. Escape sequence 43 b for backspace, remove one character at the back ’ single quote, insert a single-quote character in a string
  • 44. Escape Sequence Example #include<stdio.h> int main() { printf(“This isn C language statement n”); printf(“Thist ist Ct languaget statement n”); printf(“ Thisa isa Ca languagea statement n”); printf(“ ab n”); printf(“ This is ”C language” statement n”); printf(“ ’A’ for Apple n”); printf(“ Hib n”); return 0; } 44
  • 45. Escape Sequence Example… 45 Program output: This is C language statement This is C language statement This (alert) is (alert) C (alert) language (alert) statement ab This is ”C language” statement ‘A’ for Apple H
  • 47. Comments  Comments are used to document a program:  Improve program readability and help other people read and understand your program  Dot cause the computer to perform any action when the program is run  Ignored by the C compiler and do not cause any machine-language object code to be generated  Types of Comments:  Single-line comments e.g. //This is first C program  Multi-line comments e.g. /* This is first C program Author: Ali Dated: October 20, 2020 */ 47
  • 48. Example: Comments // A first program in C /* Author: Ali Dated: October 05, 2020 */ #include<stdio.h> int main() { printf(“This is C language statement”); return 0; } 48 Program output: This is C language statement