Presentation is loading. Please wait.

Presentation is loading. Please wait.

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:

Similar presentations


Presentation on theme: "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:"— Presentation transcript:

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: Nothing works and they don't know why. --unknown

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

3 Nabil Ur Rehman BICSE 3 nabil.rehman@niit.edu.pk Zeeshan Ahmad BICSE 3 zeeshan.ahmad@niit.edu.pk Jahanzeb Maqbool BIT9-A jahanzeb.maqbool@niit.edu.pk Bibrak Qamar BIT9-A bibrak.qamar@niit.edu.pk Aqsa Khalid BICSE5A aqsa_khalid@yahoo.com

4 Introduction to C Programming Lecture 2

5 Today’s Lecture Software Categories Software Categories System Software System Software Application Software Application Software Introduction to ‘C’ Language Introduction to ‘C’ Language History History Evolution Evolution Justification Justification Development Environment of ‘C’ Development Environment of ‘C’

6 There are two main categories of software System software System software Application Software Application Software

7 Evolution of programming languages The lack of portability between different computers led to the development of high- level languages—so called because they permitted a programmer to ignore many low-level details of the computer's hardware The lack of portability between different computers led to the development of high- level languages—so called because they permitted a programmer to ignore many low-level details of the computer's hardware Details of procedural, non-procedural will follow in the lectures Details of procedural, non-procedural will follow in the lectures

8 How people used to program Machine Language….. Damn! It was difficult Machine Language….. Damn! It was difficult Assembly Language…. Remember ADD? Assembly Language…. Remember ADD? –Required too much user involvement –To much to remember –Less semantic C Language C Language –B Language.. Bell Labs –Improved to C Language –Is a compiled language

9 ANSI C ANSI C

10 Tools of the trade Editor Editor Interpreter and Compilers Interpreter and Compilers Debuggers Debuggers

11 Integrated Development Environment (IDE) It contains Editor Editor Compilers Compilers Debugger Debugger Linkers Linkers Loaders Loaders

12 Preprocessor program processes the code. Loader puts program in memory. CPU takes each instruction and executes it, possibly storing new data values as the program executes. Compiler creates object code and stores it on disk. Linker links the object code with the libraries Loader Primary Memory Compiler Editor Preprocessor Linker Primary Memory........................ Disk CPU Disk Program is created in the editor and stored on disk.

13 #include #include main ( ) { cout << “ Welcome to SEECS “; }

14 Variable Variable X

15 Variable Pic of the memory Pic of the memory 25 25 10323 10323 name of the variable

16 Variable Variable starts with 1.Character 2.Underscore _ (Not Recommended)

17 Variable Small post box Small post box X

18 Variable Variable is the name of a location in the memory e.g. x= 2; e.g. x= 2;

19 Variable In a program a variable has: 1. Name 2. Type 3. Size 4. Value

20 Assignment Operator = x = 2 X 2

21 Assignment Operator L.H.S = R.H.S. X+ 3 = y + 4 Wrong Z = x +4 x +4 = Z Wrong

22 X = 10 ; X = 30 ; X 10 X 30

23 X = X + 1; X 10 + 1 = X 11

24 Data type int i ; //Declaration line int i ; //Declaration line i

25 Writing C program

26 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 C Turbo (obsolete and not recommended)

27 3 Stages of Compilation Stage 1: Preprocessing – Performed by a program called the preprocessor – Modifies the source code (in RAM) according to preprocessor directives (preprocessor commands) embedded in the source code –Strips comments and white space from the code –The source code as stored on disk is not modified.

28 3 Stages of Compilation (con’t) Stage 2: Compilation oPerformed by a program called the compiler oTranslates the preprocessor-modified source code into object code (machine code) oChecks for syntax errors and warnings oSaves the object code to a disk file, if instructed to do so (we will not do this). o If any compiler errors are received, no object code file will be generated. o An object code file will be generated if only warnings, not errors, are received.

29 Object code: It is machine language code containing various calls specific to operating system… e.g the object code written by compiler is not only hardware dependent but also operating system dependent. It is machine language code containing various calls specific to operating system… e.g the object code written by compiler is not only hardware dependent but also operating system dependent. So if you have linux and windows both operating systems then object file of compiled by one Operating System (OS) will not get executed on the other OS So if you have linux and windows both operating systems then object file of compiled by one Operating System (OS) will not get executed on the other OS

30 3 Stages of Compilation (con’t) Stage 3: Linking oCombines the program object code with other object code to produce the executable file. oThe other object code can come from the Run- Time Library, other libraries, or object files that you have created. oSaves the executable code to a disk file. On the Linux system, that file is called a.out. o If any linker errors are received, no executable file will be generated.

31 Program Development Using 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

32 #include //This is pre-processor directive void main ( ) //this tells the starting point of your program { int x ; int y ; int z ; x = 10 ; y = 20 ; z = x + y ; cout << " x = " ; //print the text on monitor cout << x ; cout << " y = " ; cout << y ; cout << " z =x + y = " ; cout << z ; }

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


Download ppt "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:"

Similar presentations


Ads by Google