Introduction To Computer
Introduction To Computer
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
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
4
Types of Languages
Assembly language
It was developed to overcome the problems with machine language
5
Types of Languages
High level language
In early programming languages, the programmers had to write many
instructions to perform a single task
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)
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
Most programmers never use more than a few, some limit their
career to just on or two
11
Programming Languages Popularity
https://www.tiobe.com/tiobe-index/ 12
Programming Domains
Scientific applications(Fortran)
Business Applications(COBOL)
System Programming(C )
13
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.
14
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
15
Where are we going?
The next step in computing is to use natural language over a high-level
language
Until then our task is to use high-level languages in its best possible
ways
16
Program & Its Various Aspects
17
What is Programming?
When we say “programming” we are actually referring
to the science of transforming our intentions in a
high-level programming language
18
Many Aspects of Programming
Programming is controlling
Programming is teaching
computer can only “learn” to do new things if you tell it how
Programming is creative
must find a good solution out of many possibilities
19
Many Aspects of Programming
Programming is modelling
Programming is abstraction
identify important features without getting lost in detail
Programming is concrete
must provide detailed instructions to complete task
20
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
22
Characteristics of C language
1. C is a General Purpose Programming Language
3. C is a simple language
23
Characteristics of C language
4. C is case sensitive language
24
Characteristics of C language
6.C is a flexible language
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
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
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
32
Execution Phases
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
#include<stdio.h>
int main()
{
// program statement_1;
// program statement_2
…
return 0;
}
36
Writing Program in C using DEVCpp IDE
Steps to follow:
•Click on File
•Select New, and
•Click on Source File
•Start coding in the source file(in the figure, sample example)
•Save it with a name(e.g., first.c)
•Compile, and
•Run
37
Writing Program in C using DEVCpp IDE
Sample
Program
38
C Program Example
#include<stdio.h>
int main()
printf("Welcome to C language");
return 0;
}
Program output:
Welcome to C language
39
Example: A simple C Program
#include<stdio.h>
int main()
{
printf("Welcome Students\n");
return 0;
}
Program output:
Welcome Students
This is C language statement
40
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
42
Escape sequence
43
Escape Sequence Example
#include<stdio.h>
int main()
{
printf(“This is\n C language statement \n”);
printf(“This\t is\t C\t language\t statement \n”);
printf(“ This\a is\a C\a language\a statement \n”);
printf(“ a\\b \n”);
printf(“ This is \”C language\” statement \n”);
printf(“ \’A\’ for Apple \n”);
printf(“ Hi\b \n”);
return 0;
}
44
Escape Sequence Example…
Program output:
This is
C language statement
a\b
45
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;
}
Program output:
This is C language statement
48