Sei sulla pagina 1di 14

Introduction to Programming languages

Introduction to computer programming and


Problem Solving- CSE 101

L Jeganathan

Lecture 01

September 14, 2010

Introduction to computer programming and Problem solving - CSE


Introduction to Programming languages

W HAT IS A PROGRAMMING LANGUAGE ?


1 A program is a set of instructions that tell the computer to

do various things.
2 As human languages are too difficult for a computer to
understand in an unambiguous way, commands are usually
written in a language specially designed for the purpose.

Introduction to computer programming and Problem solving - CSE


Introduction to Programming languages

P ROGRAMMING L ANGUAGES

A programming language is an artificial language designed


to express computations that can be performed by a
machine, particularly a computer.
Programming languages can be used to create programs (
or codes) that control the behavior of a machine, to
express algorithms precisely.
Many programming languages have some form of written
specification of their syntax (form) and semantics
(meaning).
Some programming languages : BASIC, PASCAL, C, C++

Introduction to computer programming and Problem solving - CSE


Introduction to Programming languages

C AN THE COMPUTER UNDERSTAND THE PROGRAMMING


LANGUAGES ?

Computers cannot perform any task on its own.


Computers should be informed of the step by step
procedure to do a particular task(Algorithm).
It is not enough just to tell the computer : Add two integers
2&3 and give the answer; we have to write a procedure to
achieve that task.
Natural languages are not capable to communicate a
procedure in an unambiguous way; So we go for a
Programming languages (or a Higher level language)
Computers can not also understand the programs (usually
written in english).

W HAT ELSE A COMPUTER COULD UNDERSTAND ?

Introduction to computer programming and Problem solving - CSE


Introduction to Programming languages

C
omputers could only understand the sequence of 0s and 1s (0
refers no power and 1 refers power in the circuit ) So the
Programs should be converted into a sequence of binary
numbers understandable to the computers Central Processing
Unit.

T HEN , H OW ARE WE GOING TO COMMUNICATE WITH THE


COMPUTERS ?

Introduction to computer programming and Problem solving - CSE


Introduction to Programming languages

T
here are two ways to communicate with a computer. We take
the help of devices called Interpreter or Compilers. We can
use either of these.

Introduction to computer programming and Problem solving - CSE


Introduction to Programming languages

I NTERPRETER
An interpreter normally means a computer program that
executes, i.e. performs, instructions written in a
programming language.
With an interpreter, the language comes as an
environment, where you type in commands at a prompt
and the environment executes them for you.
If anything goes wrong, many interpreters will drop you into
a debugger to help you track down the problem.
The advantage of an interpreter is that you can see the
results of your commands immediately, and mistakes can
be corrected readily.

Introduction to computer programming and Problem solving - CSE


Introduction to Programming languages

C OMPILER
A compiler is a computer program (or set of programs) that
transforms source code written in a programming language
(the source language) into another computer language (the
target language, often having a binary form known as
object code).
The necessity to transform source code is to create an
executable program
The name "compiler" is primarily used for programs that
translate source code from a high-level programming
language to a lower level language (e.g., assembly
language or machine code).
A program that translates from a low level language to a
higher level one is a decompiler.
A program that translates between high-level languages is
usually called a language translator, source to source
translator, or language converter
Introduction to computer programming and Problem solving - CSE
Introduction to Programming languages

RUNNING A C PROGRAM

E DIT-C OMPILE -L INK -E XECUTE P ROCESS :

E DITING
write a computer program with words and symbols that are
understandable to human beings. This is the edit part of
the development cycle. You type the program directly into a
window on the screen and save the resulting text as a
separate file.
This is often referred to as the source file.
The custom is that the text of a C program is stored in a file
with the extension .c for C programming language

Introduction to computer programming and Problem solving - CSE


Introduction to Programming languages

M ODEL C P ROGRAM

# include <stdio.h>
int
main (void)
{
printf ("Hello, world!");
return 0;
}

Introduction to computer programming and Problem solving - CSE


Introduction to Programming languages

source code is stored in a file called hello.c

Introduction to computer programming and Problem solving - CSE


Introduction to Programming languages

C OMPILING
You cannot directly execute the source file. To run on any
computer system, the source file must be translated into
binary numbers understandable to the computers Central
Processing Unit.
This process produces an intermediate object file - with the
extension .obj, the .obj stands for Object.

gcc hello.c -o hello

Introduction to computer programming and Problem solving - CSE


Introduction to Programming languages

L INKING
The first question that comes to most peoples minds is
Why is linking necessary? The main reason is that many
compiled languages come with library routines which can
be added to your program.
Theses routines are written by the manufacturer of the
compiler to perform a variety of tasks, from input/output to
complicated mathematical functions.
In the case of C the standard input and output functions
are contained in a library (stdio.h)
so even the most basic program will require a library
function. After linking the file extension is .exe which are
executable files.

Introduction to computer programming and Problem solving - CSE


Introduction to Programming languages

E XECUTING A P ROGRAM
hello
hello world !

This loads the executable file into memory and causes the
CPU to begin executing the instructions contained within it.
./hello loads and runs the executable file hello located in
the current directory
item Thus the text editor produces .c source files, which go
to the compiler, which produces .obj object files, which go
to the linker, which produces .exe executable file. You can
then run exe files as you can other applications.

Introduction to computer programming and Problem solving - CSE

Potrebbero piacerti anche