1 Chapter 5: Preparing C Programs
2 Program development Understanding the problem EDITWriting an algorithm Converting to code COMPILE RUN errors Result Verifying the algorithm Chapter 5 Program development
3 Program development pico prog.c cc prog.c a.out Source code EDITCOMPILE RUN errors Result Source code pico prog.c cc prog.c a.out Chapter 5 Program development
4 High-level languages Machine language: computer’s native language.Add two numbers: Assembly language: uses mnemonics. Add two numbers: ADD R1 R2 An assembly code needs to be translated to machine code. Chapter 5 High-level languages
5 High-level languages High-level programming languages: bridging the gap between machine language and natural languages. Examples: COBOL, Fortran, Algol, C Add two numbers (in C): Z = A + B; Compilation: translation to machine code. Chapter 5 High-level languages
6 A C program A sample C program/* A simple C program to read a number & compute and display its square by using the multiplication (*) operator. */ #include
7 Compilation in C Use the cc or gcc compiler: cc prog.cProduces executable file a.out if no errors To specify name of executable file, use -o option: cc -o prog prog.c Name of executable file becomes ‘prog’. Chapter 5 Compilation in C
8 Errors Compilation errors: occur during compilation.Reason: syntax errors. Easy to rectify. Run-time errors: occur during execution. Reasons: logic errors, data errors, computation errors. Harder to rectify. Chapter 5 Errors
9 Homework Try exercises in chapter 5. Chapter 5 Homework