SlideShare a Scribd company logo
1 of 20
1
Some influential ones:
FORTRAN
science / engineering
COBOL
business data
LISP
logic and AI
BASIC
a simple language
2
Languages
Programming basics
code or source code: The
sequence of instructions
in a program.
syntax: The set of legal
structures and commands
that can be used in a
particular programming
language.
output: The messages
printed to the user by a
program.
console: The text box
onto which output is
printed.
3
Compiling and interpreting
Many languages require you to
compile (translate) your
program into a form that the
machine understands.
Python is instead directly
interpreted into machine
instructions.
4
compile execute
output
source code
Hello.java
byte code
Hello.class
interpret
output
source code
Hello.py
Dimensions of aPL
• Functional
• Treatscomputation as the evaluation ofmathematical functions
(e.g. Lisp, Scheme, Haskell, etc.)
• Imperative
• describes computation in terms of statements that changea program
state (e.g. FORTRAN, BASIC, Pascal, C, etc. )
• Logical (declarative)
• expresses the logic of a computation withoutdescribingits control flow
(e.g. Prolog)
• Object oriented
• uses "objects"– data structures consistingof data fields and methods
together with their interactions– to design applications and computer
programs (e.g. C++, Java, C#, Python, etc.)
Slide credit: Thomas J. Cortina
C (1973)
• Developed by Ken Thompson and Dennis Ritchie at
AT&T Bell Labs for use on the UNIXoperating system.
– now used on practicallyevery operatingsystem
– popular languagefor writing system software
• Features:
– An extremely simple core language, with non-essential
functionality provided by a standardizedsetof library routines.
– Low-level access to computer memory via the use of pointers.
• C ancestors: C++, C#, Java
9
Slide credit: Thomas J. Cortina
Python
• Created by Guido van Rossum in the late 1980s
• Allows programming in multiple paradigms: object-
oriented, structured,functional
• Uses dynamic typing and garbage collection
8
Building a simple program in
Python (as compared to C)
• Compilers versusinterpreters
• Variable declarations
• Whitespace
• The printf() function
• Functions
9
Compilers versus interpreters
• One major difference between C and Python is how the
programs written in these two languages are executed.
• With C programs, you usually use a compiler when you
are ready to see a C program execute.
• By contrast, with Python, you typically use an interpreter.
10
Compilers versus interpreters
• An interpreter reads the user-written programand
performs it directly.
• A compiler generates a file containing the translation
of the program into the machine's native code.
– The compiler does not actually execute the program!
– Instead, you first execute the compiler to create a native
executable, and then you execute the generatedexecutable.
11
Variable declarations
• C requires variable declarations, informing the compiler
about the variable before the variable is actuallyused.
• In C, the variable declaration defines the variable'stype.
• No such thing in Python!
20
Declaring a Variable
• Declaring a variable is simpleenough.
• You enter the variable's type, somewhitespace,
the variable's name, and a semicolon:
double x;
• Value assignment is similar toPython:
x=3;
• x will actually hold the floating-pointvalue 3.0 rather than the
integer3.
• However, once you declare a variable to be of a particular
type, you cannot change itstype!
13
Declaring a Variable
• In C, variable declarations belong at the top of the
function in which they areused.
• If you forget to declare a variable, the compiler will
refuse to compile theprogram:
– A variable is used but is notdeclared.
• To a Python programmer, it seems a pain to have to
include these variable declarations in a program, though
this gets easier with morepractice.
14
Whitespace
• In Python, whitespace characters like tabs andnewlines
are important:
– You separate your statements by placingthem on separate
lines, and you indicate the extent of a block using
indentation.
– like the body of a while or if statement
• C does not use whitespace except for separatingwords.
• Most statements are terminated with a semicolon ';', and
blocks of statementsare indicated using a set of braces, '{'
and '}'.
Whitespace
15
C fragment
disc = b * b - 4 * a * c;
if (disc < 0)
{
num_sol = 0;
}
else
{
t0 = -b / a;
if (disc == 0)
{
num_sol = 1;
sol0 = t0 / 2;
}
else
{
num_sol = 2;
t1 = sqrt(disc) / a;
sol0 = (t0 + t1) / 2;
sol1 = (t0 - t1) / 2;
}
}
Python equivalent
disc = b * b - 4 * a * c
if disc < 0:
num_sol = 0
else:
t0 = -b
if disc
/ a
== 0:
num_sol = 1
sol0 = t0 / 2
else:
num_sol = 2
**
t1 = disc
sol0
sol1
= (t0 +
= (t0 -
0.5 / a
t1) / 2
t1) / 2
16
Whitespace
• As said, whitespace is insignificant in C.
• The computer would be just as happy if the previous code
fragment is written as follows:
disc=b*b-4*a*c;if(disc<0){
num_sol=0;}else{t0=-b/a;if(
disc==0){num_sol=1;sol0=t0/2
;}else{num_sol=2;t1=sqrt(disc/a;
sol0=(t0+t1)/2;sol1=(t0-t1)/2;}}
• However, do not write your programs like this!
30
Functions
• Unlike Python, all C code must be nested within functions,
and functions cannot be nested withineach other.
• A C program's overall structure is typicallyvery
straightforward.
• It is a list of function definitions, one after another, each
containing a list of statements to be executed when the
function iscalled.
18
Functions
• A C function is defined bynamingthe return type, followed bythe function
name, followed bya set of parentheses listing the parameters.
• Each parameter is described by includingthe type of the parameter and the
parametername.
• Here's a simple example of a function definition:
float expon(float b, int e)
{
if (e == 0)
{
return 1.0;
}
else
{
return b * expon(b, e - 1);
}
}
This is a function named
expon, which takes two
arguments, first a floating point
number and next an integer,
and returns a floating point
number.
19
Functions
• If you have a function that does not have any useful
return value, then you'd use void as the return type.
• Programs have one special function named main, whose
return type is aninteger.
• This function is the “starting point” for the program:
– The computer essentially calls the program's mainfunction
when it wants to execute theprogram.
– The integer return value is largely meaningless; we'll
always return 0 rather than worrying about howthe return
value might beused.
Functions
20
C program
int gcd(int a, int b)
{
if (b == 0)
{
return a;
}
else
{
return gcd(b, a % b);
}
}
int main()
{
printf("GCD: %dn“, gcd(24,40));
return 0;
}
Python program
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
print("GCD: " + str(gcd(24, 40)))

More Related Content

Similar to Lecture 1.pptx

Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)
mujeeb memon
 

Similar to Lecture 1.pptx (20)

Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
C programming
C programmingC programming
C programming
 
Cp week _2.
Cp week _2.Cp week _2.
Cp week _2.
 
Basic c
Basic cBasic c
Basic c
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 
Embedded C.pptx
Embedded C.pptxEmbedded C.pptx
Embedded C.pptx
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
C language unit-1
C language unit-1C language unit-1
C language unit-1
 
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDYC LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
 
C languaGE UNIT-1
C languaGE UNIT-1C languaGE UNIT-1
C languaGE UNIT-1
 
Rr
RrRr
Rr
 
Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)
 
C pdf
C pdfC pdf
C pdf
 
Prog1-L1.pdf
Prog1-L1.pdfProg1-L1.pdf
Prog1-L1.pdf
 
Overview of c
Overview of cOverview of c
Overview of c
 
The smartpath information systems c pro
The smartpath information systems c proThe smartpath information systems c pro
The smartpath information systems c pro
 
Unit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptxUnit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptx
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++
 
C.pdf
C.pdfC.pdf
C.pdf
 
C Language Presentation.pptx
C Language Presentation.pptxC Language Presentation.pptx
C Language Presentation.pptx
 

Recently uploaded

VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
dharasingh5698
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Intro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfIntro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdf
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 

Lecture 1.pptx

  • 1. 1
  • 2. Some influential ones: FORTRAN science / engineering COBOL business data LISP logic and AI BASIC a simple language 2 Languages
  • 3. Programming basics code or source code: The sequence of instructions in a program. syntax: The set of legal structures and commands that can be used in a particular programming language. output: The messages printed to the user by a program. console: The text box onto which output is printed. 3
  • 4. Compiling and interpreting Many languages require you to compile (translate) your program into a form that the machine understands. Python is instead directly interpreted into machine instructions. 4 compile execute output source code Hello.java byte code Hello.class interpret output source code Hello.py
  • 5. Dimensions of aPL • Functional • Treatscomputation as the evaluation ofmathematical functions (e.g. Lisp, Scheme, Haskell, etc.) • Imperative • describes computation in terms of statements that changea program state (e.g. FORTRAN, BASIC, Pascal, C, etc. ) • Logical (declarative) • expresses the logic of a computation withoutdescribingits control flow (e.g. Prolog) • Object oriented • uses "objects"– data structures consistingof data fields and methods together with their interactions– to design applications and computer programs (e.g. C++, Java, C#, Python, etc.)
  • 6. Slide credit: Thomas J. Cortina C (1973) • Developed by Ken Thompson and Dennis Ritchie at AT&T Bell Labs for use on the UNIXoperating system. – now used on practicallyevery operatingsystem – popular languagefor writing system software • Features: – An extremely simple core language, with non-essential functionality provided by a standardizedsetof library routines. – Low-level access to computer memory via the use of pointers. • C ancestors: C++, C#, Java 9
  • 7. Slide credit: Thomas J. Cortina Python • Created by Guido van Rossum in the late 1980s • Allows programming in multiple paradigms: object- oriented, structured,functional • Uses dynamic typing and garbage collection
  • 8. 8 Building a simple program in Python (as compared to C) • Compilers versusinterpreters • Variable declarations • Whitespace • The printf() function • Functions
  • 9. 9 Compilers versus interpreters • One major difference between C and Python is how the programs written in these two languages are executed. • With C programs, you usually use a compiler when you are ready to see a C program execute. • By contrast, with Python, you typically use an interpreter.
  • 10. 10 Compilers versus interpreters • An interpreter reads the user-written programand performs it directly. • A compiler generates a file containing the translation of the program into the machine's native code. – The compiler does not actually execute the program! – Instead, you first execute the compiler to create a native executable, and then you execute the generatedexecutable.
  • 11. 11 Variable declarations • C requires variable declarations, informing the compiler about the variable before the variable is actuallyused. • In C, the variable declaration defines the variable'stype. • No such thing in Python!
  • 12. 20 Declaring a Variable • Declaring a variable is simpleenough. • You enter the variable's type, somewhitespace, the variable's name, and a semicolon: double x; • Value assignment is similar toPython: x=3; • x will actually hold the floating-pointvalue 3.0 rather than the integer3. • However, once you declare a variable to be of a particular type, you cannot change itstype!
  • 13. 13 Declaring a Variable • In C, variable declarations belong at the top of the function in which they areused. • If you forget to declare a variable, the compiler will refuse to compile theprogram: – A variable is used but is notdeclared. • To a Python programmer, it seems a pain to have to include these variable declarations in a program, though this gets easier with morepractice.
  • 14. 14 Whitespace • In Python, whitespace characters like tabs andnewlines are important: – You separate your statements by placingthem on separate lines, and you indicate the extent of a block using indentation. – like the body of a while or if statement • C does not use whitespace except for separatingwords. • Most statements are terminated with a semicolon ';', and blocks of statementsare indicated using a set of braces, '{' and '}'.
  • 15. Whitespace 15 C fragment disc = b * b - 4 * a * c; if (disc < 0) { num_sol = 0; } else { t0 = -b / a; if (disc == 0) { num_sol = 1; sol0 = t0 / 2; } else { num_sol = 2; t1 = sqrt(disc) / a; sol0 = (t0 + t1) / 2; sol1 = (t0 - t1) / 2; } } Python equivalent disc = b * b - 4 * a * c if disc < 0: num_sol = 0 else: t0 = -b if disc / a == 0: num_sol = 1 sol0 = t0 / 2 else: num_sol = 2 ** t1 = disc sol0 sol1 = (t0 + = (t0 - 0.5 / a t1) / 2 t1) / 2
  • 16. 16 Whitespace • As said, whitespace is insignificant in C. • The computer would be just as happy if the previous code fragment is written as follows: disc=b*b-4*a*c;if(disc<0){ num_sol=0;}else{t0=-b/a;if( disc==0){num_sol=1;sol0=t0/2 ;}else{num_sol=2;t1=sqrt(disc/a; sol0=(t0+t1)/2;sol1=(t0-t1)/2;}} • However, do not write your programs like this!
  • 17. 30 Functions • Unlike Python, all C code must be nested within functions, and functions cannot be nested withineach other. • A C program's overall structure is typicallyvery straightforward. • It is a list of function definitions, one after another, each containing a list of statements to be executed when the function iscalled.
  • 18. 18 Functions • A C function is defined bynamingthe return type, followed bythe function name, followed bya set of parentheses listing the parameters. • Each parameter is described by includingthe type of the parameter and the parametername. • Here's a simple example of a function definition: float expon(float b, int e) { if (e == 0) { return 1.0; } else { return b * expon(b, e - 1); } } This is a function named expon, which takes two arguments, first a floating point number and next an integer, and returns a floating point number.
  • 19. 19 Functions • If you have a function that does not have any useful return value, then you'd use void as the return type. • Programs have one special function named main, whose return type is aninteger. • This function is the “starting point” for the program: – The computer essentially calls the program's mainfunction when it wants to execute theprogram. – The integer return value is largely meaningless; we'll always return 0 rather than worrying about howthe return value might beused.
  • 20. Functions 20 C program int gcd(int a, int b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } int main() { printf("GCD: %dn“, gcd(24,40)); return 0; } Python program def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) print("GCD: " + str(gcd(24, 40)))