33
Theory is when you know Theory is when you know something, but it doesn't something, but it doesn't work. Practice is when work. Practice is when something works, but you don't something works, but you don't know why. know why. Programmers combine theory and Programmers combine theory and practice: Nothing works and practice: Nothing works and they don't know why. they don't know why. --unknown --unknown

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

Embed Size (px)

Citation preview

Page 1: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

Theory is when you know Theory is when you know something, but it doesn't work. something, but it doesn't work. Practice is when something works, Practice is when something works, but you don't know why.but you don't know why.

Programmers combine theory and Programmers combine theory and practice: Nothing works and they practice: Nothing works and they don't know why.don't know why.

--unknown--unknown

Page 2: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

Once a new technology starts Once a new technology starts rolling, if you're not part of the rolling, if you're not part of the steamroller, you're part of the steamroller, you're part of the road. road.

--Stewart Brand--Stewart Brand

Page 3: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

Nabil Ur RehmanBICSE [email protected]

Zeeshan AhmadBICSE [email protected]

Jahanzeb [email protected]

Bibrak [email protected]

Aqsa [email protected]

Page 4: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

Introduction to C Introduction to C ProgrammingProgramming

Lecture 2Lecture 2

Page 5: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

Today’s LectureToday’s Lecture Software CategoriesSoftware Categories

System SoftwareSystem Software Application SoftwareApplication Software

Introduction to ‘C’ LanguageIntroduction to ‘C’ Language HistoryHistory EvolutionEvolution JustificationJustification

Development Environment of ‘C’Development Environment of ‘C’

Page 6: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

There are two main categories of softwareThere are two main categories of software

System softwareSystem software

Application Software Application Software

Page 7: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

Evolution of Evolution of programming languagesprogramming languages

The lack of portability between The lack of portability between different computers led to the different computers led to the development of development of high-level languageshigh-level languages——so called because they permitted a so called because they permitted a programmer to ignore many low-level programmer to ignore many low-level details of the computer's hardware details of the computer's hardware

Details of procedural, non-procedural Details of procedural, non-procedural will follow in the lectureswill follow in the lectures

Page 8: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

How people used to How people used to programprogram Machine Language….. Damn! It was Machine Language….. Damn! It was

difficultdifficult Assembly Language…. Remember ADD? Assembly Language…. Remember ADD?

– Required too much user involvementRequired too much user involvement– To much to remember To much to remember – Less semanticLess semantic

C Language C Language – B Language.. Bell LabsB Language.. Bell Labs– Improved to C LanguageImproved to C Language– Is a compiled languageIs a compiled language

Page 9: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

ANSI CANSI C

Page 10: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

Tools of the Tools of the tradetrade

EditorEditor Interpreter and Compilers Interpreter and Compilers DebuggersDebuggers

Page 11: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

Integrated Development EnvironmentIntegrated Development Environment(IDE)(IDE)

It containsIt contains EditorEditor Compilers Compilers DebuggerDebugger Linkers Linkers LoadersLoaders

Page 12: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

Preprocessor programprocesses the code.

Loader puts program in memory.

CPU takes eachinstruction and executes it, possibly storing new data values as the program executes.

Compiler creates object code and storesit on disk.Linker links the objectcode with the libraries

Loader

Primary Memory

Compiler

Editor

Preprocessor

Linker

 

Primary Memory

.

.

.

.

.

.

.

.

.

.

.

.

Disk

Disk

Disk

CPU

Disk

DiskProgram is created in the editor and stored on disk.

Page 13: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

#include <iostream.h>#include <iostream.h>main ( )main ( ){{

cout << “ Welcome to SEECS “;cout << “ Welcome to SEECS “;}}

Page 14: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

VariableVariable

VariableVariable X

Page 15: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

VariableVariable Pic of the memoryPic of the memory

2525

1032310323

namename

of the of the variablvariablee

Page 16: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

VariableVariableVariable starts withVariable starts with

1.1. CharacterCharacter

2.2. Underscore _ Underscore _ (Not (Not Recommended)Recommended)

Page 17: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

VariableVariable Small post boxSmall post box

X

Page 18: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

VariableVariable

Variable is the name of a Variable is the name of a location inlocation in

the memorythe memory

e.g. x= 2;e.g. x= 2;

Page 19: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

VariableVariableIn a program a variable In a program a variable

has:has:

1.1. NameName

2.2. TypeType

3.3. SizeSize

4.4. ValueValue

Page 20: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

Assignment Assignment OperatorOperator

==x = 2x = 2

X 2

Page 21: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

Assignment Assignment Operator Operator

L.H.S = R.H.S.L.H.S = R.H.S.

X+ 3 = y + 4 X+ 3 = y + 4 WrongWrongZ = x +4Z = x +4

x +4 = Z x +4 = Z WrongWrong

Page 22: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

X = 10 ; X = 10 ;

X = 30 ;X = 30 ;

X 10

X 30

Page 23: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

X = X + 1;X = X + 1;

X 10 + 1

= X11

Page 24: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

Data typeData type

int i ; int i ; //Declaration line//Declaration line

ii

Page 25: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

Writing C programWriting C program

Page 26: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

Compiler converts human

readable language to a

language which is

understandable by the operating system/hardware

Examples of C/C++

compilers of today:

Visual C++GCC/G++

DJGPP (open source for

windows like GCC)

Borland CTurbo (obsolete

and not recommended)

Page 27: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

3 Stages of 3 Stages of CompilationCompilation

Stage 1: Stage 1: PreprocessingPreprocessing

– Performed by a program called the Performed by a program called the preprocessorpreprocessor

– Modifies the source code (in RAM) according to Modifies the source code (in RAM) according to preprocessor directives (preprocessor preprocessor directives (preprocessor commandscommands) embedded in the source code) embedded in the source code

– Strips comments and white space from the Strips comments and white space from the codecode

– The source code as stored on disk is The source code as stored on disk is notnot modified.modified.

Page 28: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

3 Stages of Compilation (con’t)3 Stages of Compilation (con’t)

Stage 2: Stage 2: CompilationCompilation

o Performed by a program called the Performed by a program called the compilercompilero Translates the preprocessor-modified source Translates the preprocessor-modified source

code into code into object code (machine code)object code (machine code)o Checks for Checks for syntax errorssyntax errors and and warningswarningso Saves the Saves the object codeobject code to a disk file, if to a disk file, if

instructed to do so (we will not do this).instructed to do so (we will not do this).o If any compiler errors are received, no object code If any compiler errors are received, no object code

file will be generated.file will be generated.o An object code file An object code file willwill be generated if only be generated if only

warnings, not errors, are received.warnings, not errors, are received.

Page 29: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

Object code:Object code:

It is machine language code containing It is machine language code containing various calls specific to operating various calls specific to operating system… e.g the object code written by system… e.g the object code written by compiler is not only hardware compiler is not only hardware dependent but also operating system dependent but also operating system dependent. dependent.

So if you have linux and windows both So if you have linux and windows both operating systems then object file of operating systems then object file of compiled by one Operating System (OS) compiled by one Operating System (OS) will not get executed on the other OSwill not get executed on the other OS

Page 30: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

3 Stages of Compilation 3 Stages of Compilation (con’t)(con’t)Stage 3: Stage 3: LinkingLinking

o Combines the program object code with other Combines the program object code with other object code to produce the executable file.object code to produce the executable file.

o The other object code can come from the The other object code can come from the Run-Run-Time LibraryTime Library, other libraries, or object files , other libraries, or object files that you have created.that you have created.

o Saves the executable code to a disk file. On the Saves the executable code to a disk file. On the Linux system, that file is called Linux system, that file is called a.outa.out..

o If any linker errors are received, no executable file If any linker errors are received, no executable file will be generated.will be generated.

Page 31: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

Program Development Program Development Using gccUsing gcc

Source File pgm.c

Program Object Code File pgm.o

Executable File a.out

Preprocessor

Modified Source Code in RAM

Compiler

Linker

Other Object Code Files (if any)

Editor

Page 32: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

#include <iostream.h> #include <iostream.h> //This is pre-processor directive//This is pre-processor directivevoid main ( ) void main ( ) //this tells the starting point of your program//this tells the starting point of your program{{

int x ;int x ;int y ;int y ;int z ;int z ;x = 10 ;x = 10 ;y = 20 ;y = 20 ;z = x + y ;z = x + y ;

cout << " x = " ; cout << " x = " ; //print the text on monitor//print the text on monitorcout << x ;cout << x ;

cout << " y = " ;cout << " y = " ;cout << y ;cout << y ;

cout << " z =x + y = " ;cout << " z =x + y = " ;cout << z ;cout << z ;

}}

Page 33: Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:

int x, y, z ;int x, y, z ;

int x; int y; int z int x; int y; int z ;;